I can't get a report saved in GAM - api php

160 views
Skip to first unread message

Jóse L. Méndez Cordova

unread,
Apr 15, 2024, 12:54:41 PM4/15/24
to google-doubleclick...@googlegroups.com, admana...@forumsupport.google
What version of the admanager API allows you to obtain reports saved or created in GAM?

My intention is to obtain any type of report but in this case I require a type of report, especially those from Reach

Since I am using v202311\ReportService; and it is returning this Fatal error: Uncaught UnexpectedValueException: The saved query is not compatible with this API version. in C:\xampp\htdocs\apitest\

image.png

This is my code <?php
/**
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Google\AdsApi\Examples\AdManager\v202311\ReportService;

require __DIR__ . '/../vendor/autoload.php';

use Google\AdsApi\AdManager\AdManagerSession;
use Google\AdsApi\AdManager\AdManagerSessionBuilder;
use Google\AdsApi\AdManager\Util\v202311\ReportDownloader;
use Google\AdsApi\AdManager\Util\v202311\StatementBuilder;
use Google\AdsApi\AdManager\v202311\ExportFormat;
use Google\AdsApi\AdManager\v202311\ReportJob;
use Google\AdsApi\AdManager\v202311\ReportQueryAdUnitView;
use Google\AdsApi\AdManager\v202311\ServiceFactory;
use Google\AdsApi\Common\OAuth2TokenBuilder;
use UnexpectedValueException;

/**
 * This example retrieves and runs a saved report query.
 */
class RunSavedQuery
{

    const SAVED_QUERY_ID = '14540267500';

    public static function runExample(
        ServiceFactory $serviceFactory,
        AdManagerSession $session,
        int $savedQueryId
    ) {
        $reportService = $serviceFactory->createReportService($session);

        // Create statement to retrieve the saved query.
        $statementBuilder = (new StatementBuilder())->where('id = :id')
            ->orderBy('id ASC')
            ->limit(1)
            ->withBindVariableValue('id', $savedQueryId);

        $savedQueryPage = $reportService->getSavedQueriesByStatement(
            $statementBuilder->toStatement()
        );
        $savedQuery = $savedQueryPage->getResults()[0];

        if ($savedQuery->getIsCompatibleWithApiVersion() === false) {
            throw new UnexpectedValueException(
                'The saved query is not compatible with this API version.'
            );
        }

        // Optionally modify the query.
        $reportQuery = $savedQuery->getReportQuery();
        $reportQuery->setAdUnitView(ReportQueryAdUnitView::HIERARCHICAL);

        // Create report job using the saved query.
        $reportJob = new ReportJob();
        $reportJob->setReportQuery($reportQuery);

        $reportJob = $reportService->runReportJob($reportJob);

        // Create report downloader to poll report's status and download when
        // ready.
        $reportDownloader = new ReportDownloader(
            $reportService,
            $reportJob->getId()
        );
        if ($reportDownloader->waitForReportToFinish()) {
            // Write to system temp directory by default.
            $filePath = sprintf(
                '%s.csv.gz',
                tempnam(sys_get_temp_dir(), 'saved-report-')
            );
            printf("Downloading report to %s ...%s", $filePath, PHP_EOL);
            // Download the report.
            $reportDownloader->downloadReport(
                ExportFormat::CSV_DUMP,
                $filePath
            );
            print "done.\n";
        } else {
            print "Report failed.\n";
        }
    }

    public static function main()
    {
        $oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()
            ->build();
        $session = (new AdManagerSessionBuilder())->fromFile()
            ->withOAuth2Credential($oAuth2Credential)
            ->build();
        self::runExample(
            new ServiceFactory(),
            $session,
            intval(self::SAVED_QUERY_ID)
        );
    }
}

RunSavedQuery::main();








Note.-I have been able to download reports with the examples from https://github.com/googleads/googleads-php-lib/tree/main/examples/AdManager/v202311

But I have not been able to download the reports that were created directly in GAM.

Ad Manager API Forum Advisor

unread,
Apr 15, 2024, 3:23:09 PM4/15/24
to lic1...@gmail.com, google-doubleclick...@googlegroups.com
Hi,

Thank you for contacting Ad Manager API support team.

I think you might have missed to see our earlier response, for clarification I am posting it again here.

By reviewing your concern, I understand that you want to know the version of the Ad Manager API to obtain reports saved or created in GAM using Reach type. There are different versions available for obtaining or creating reports (such as v202308v202311,v202402 which is the latest version). Additionally, I understand that you are encountering the issue of  iscompatiblewithApiVersion : false. This error indicates that the saved query is not compatible with the current API version. You may refer to all the available dimensions and columns in the Ad Manager API. To assist you further on this issue provide us with the following details:
  •  Network code 
  • Complete SOAP request and response logs of all those errors (SOAP logging must be enabled).
  • The screenshot of the report builder from the UI (to check all dimensions, metrics, filters, date range used).
  • The downloaded report file from the UI and the API.
  • UserService.getCurrentUser (if unable, you may just provide the email address used to make API requests) 
You can share the requested details via Reply privately to the author option or a direct private reply to this email.​ ​ ​ ​ ​ ​ ​
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02tP5Lq:ref" (ADR-00231024)

Thanks,
 
Google Logo Ad Manager API Team

 

Jóse L. Méndez Cordova

unread,
Apr 22, 2024, 7:50:45 PM4/22/24
to Google Ad Manager API Forum
Hello

I sent you the requested data privately and there was no response.

Can you help me to what email I can send you the requested information?

Ad Manager API Forum Advisor

unread,
Apr 23, 2024, 3:29:25 AM4/23/24
to lic1...@gmail.com, google-doubleclick...@googlegroups.com
Hi,

We have received information that was provided and we have responded already but for clarity we are posting the same response .

After investigating the screenshots, and implementing the same from our end, we found that you are using the beta metric ‘Estimated total unique visitors,’ which is not available in the API yet. So, I recommended removing Estimated total unique visitors metrics and trying to generate a report. 

I can confirm that the ’Estimated total unique visitors’ metric is not possible yet in the API. I would like to inform you that the ’Estimated total unique visitors’ metric  is only available in the Ad Manager UI. I will raise a request to add this feature in the Ad Manager API. With that being said, I am unable to comment about the availability of the " inventory format targeting"  in the API. I'd advise you to follow our Blog Post and Release Notes for announcements about new API releases and features. 

Jóse L. Méndez Cordova

unread,
Apr 29, 2024, 5:55:31 PM4/29/24
to Google Ad Manager API Forum
Hello.

Thanks for the reply.

three more questions:

1.- When do you think it is likely that this option 'Estimated total unique visitors' will be added, will there be a time estimate in order to use it?

2.- Could it be that instead of taking it directly from the ID saved in GAM, take the values using RunReachReport.php to add the 'Estimated total unique visitors'?
Can you share an example with me please?

3.-I have other historical reports saved in GAM that I want to download, but it says again 'The saved query is not compatible with this API version'. Should I share the same data with you so you can review it?

I attach an image of the other historical report


WhatsApp Image 2024-04-29 at 3.51.07 PM.jpeg

thank for the help.

Ad Manager API Forum Advisor

unread,
Apr 30, 2024, 4:40:54 AM4/30/24
to lic1...@gmail.com, google-doubleclick...@googlegroups.com

Hi,

I have raised a request to add ’Estimated total unique visitors’ metric feature in the Ad Manager API. With that being said,  we cannot provide a scheduled timeline for adding this feature in the Ad Manager API. I would recommend you to please follow our Blog post and Release notes to get any updates about the Ad Manager API.

I recommend using UNIQUE_REACH and UNIQUE_REACH_FREQUENCY in the RunReachReport.php instead of using Estimated total unique visitors in the UI.

I reviewed the provided report builder screenshots and understand that you are facing an issue while running a saved report from the API, which has a dynamic date range of the last 1 year. I would like to inform you that these are available data ranges in the ReportService. I can confirm that the dynamic date range of the last 1 year feature is not available in the API. I will raise a request to add this feature to the API. I cannot provide a scheduled timeline for availability of this feature to the API. You may follow our release notes and blog post for future updates.

  Hope this helps!

 

Reply all
Reply to author
Forward
Message has been deleted
0 new messages