googleads / googleads-php-lib

Google Ad Manager SOAP API Client Library for PHP
Apache License 2.0
655 stars 770 forks source link

Get line items by targeting: Unmarshalling Error cvc-type.2 #561

Closed akira28 closed 5 years ago

akira28 commented 5 years ago

I'm trying to retrieve a list of line items based on their targeting:

        $adManagerServices = new AdManagerServices();
        $lineItemService   = $adManagerServices->get($this->session, LineItemService::class);

        // Create a statement to select line items.
        $pageSize  = StatementBuilder::SUGGESTED_PAGE_LIMIT;
        $targeting = new Targeting();

        $browserTargeting  = new BrowserTargeting();
        $browserTechnology = new Technology();
        $browserTechnology->setId(500072); // chrome
        $browserTargeting->setBrowsers([$browserTechnology]);
        $technologyTargeting = new TechnologyTargeting();
        $technologyTargeting->setBrowserTargeting($browserTargeting);
        $targeting->setTechnologyTargeting($technologyTargeting);
        $statementBuilder = (new StatementBuilder())
            ->where("Targeting = :targeting")
            ->orderBy('id ASC')
            ->withBindVariableValue('targeting', $targeting)
            ->limit($pageSize);

        // Retrieve a small amount of line items at a time, paging
        // through until all line items have been retrieved.
        $totalResultSetSize = 0;
        $results            = [];
        do {
            $page = $lineItemService->getLineItemsByStatement(
                $statementBuilder->toStatement()
            );

            // Print out some information for each line item.
            if ($page->getResults() !== null) {
                $totalResultSetSize = $page->getTotalResultSetSize();
                $i                  = $page->getStartIndex();
                foreach ($page->getResults() as $lineItem) {
                    $i++;
                    $output->writeln(
                        "<info>{$i}) Line item with ID {$lineItem->getId()} and name '{$lineItem->getName()}' was found.</info>"
                    );
                    $results[] = $lineItem;
                }
            }

            $statementBuilder->increaseOffsetBy($pageSize);
        } while ($statementBuilder->getOffset() < $totalResultSetSize);

But I'm getting this error: Unmarshalling Error: cvc-type.2: The type definition cannot be abstract for element ns1:value.

This is the generated request:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://www.google.com/apis/ads/publisher/v201811"><SOAP-ENV:Header><ns1:RequestHeader><ns1:networkCode>21727012966</ns1:networkCode><ns1:applicationName>XFP sandbox property (DfpApi-PHP, googleads-php-lib/38.0.0, PHP/7.3.0)</ns1:applicationName></ns1:RequestHeader></SOAP-ENV:Header><SOAP-ENV:Body><ns1:getLineItemsByStatement><ns1:filterStatement><ns1:query>WHERE Targeting = :targeting ORDER BY id ASC LIMIT 500</ns1:query><ns1:values><ns1:key>targeting</ns1:key><ns1:value/></ns1:values></ns1:filterStatement></ns1:getLineItemsByStatement></SOAP-ENV:Body></SOAP-ENV:Envelope>

As you can see the targeting is empty.

and the response:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Unmarshalling Error: cvc-type.2: The type definition cannot be abstract for element ns1:value. </faultstring></soap:Fault></soap:Body></soap:Envelope>

What am I doing wrong?

thangduo commented 5 years ago

Hi Andrea,

Sorry for the late response here. I was on PTO. Will take a look and get back to you this week.

Thanks, Thang Duong

thangduo commented 5 years ago

Hi Andrea,

Filtering line items by targeting is currently not supported in Google Ad Manager. Please go to the Google Ad Manager product forum (https://productforums.google.com/forum/#!forum/dfp) or a Google Technical Account Manager (if you have one assigned to your company) to make a feature request.

Thanks, Thang Duong

samrum commented 5 years ago

@thangduo the api reference says that Targeting is supported for filtering: https://developers.google.com/ad-manager/api/reference/v201902/LineItemService#getlineitemsbystatement

thangduo commented 5 years ago

Hi Ruben,

You are correct that the documentation is listing Targeting as filterable. It's a bug in our documentation that we'll be fixing soon.

Thanks, Thang Duong

mbanusic commented 5 years ago

@thangduo this still hasn't been fixed in the documentation and it has been three updates in the meantime

blueridgemountains1 commented 4 years ago

Hello, any update on this @thangduo ?

thangduo commented 4 years ago

Hi, we are working on updating the documentation.

Thanks, Thang Duong

thangduo commented 4 years ago

The documentation fix is done and live.

Thanks, Thang Duong