googleads / google-ads-php

Google Ads API Client Library for PHP
https://developers.google.com/google-ads/api/docs/client-libs/php
Apache License 2.0
295 stars 262 forks source link

Ad group criteria update error #959

Closed 0x1881 closed 1 year ago

0x1881 commented 1 year ago

When I try to change the unknown gender criteria in ad groups, I get an error regarding the criteria ID. While it works flawlessly in some ad groups, it does not work in others. Please help me understand what the problem is.

Code:

   `$adGroupResourceName = ResourceNames::forAdGroupCriterion($customerId, $adGroupId, GenderType::UNDETERMINED);

    // Updates bid modifier ad group criterion for gender.
    $adGroupCriterion = new AdGroupCriterion();
    $adGroupCriterion->setResourceName($adGroupResourceName);
    $adGroupCriterion->setBidModifier(self::BID_VALUE);

    // Update ad group criterion operations for both ad group criteria.
    $adGroupCriterionOperation = new AdGroupCriterionOperation();
    $adGroupCriterionOperation->setUpdate($adGroupCriterion);
    $adGroupCriterionOperation->setUpdateMask(FieldMasks::allSetFieldsOf($adGroupCriterion));

    // Issues a mutate request to update the ad group criteria and print out some information.
    $adGroupCriterionServiceClient = $googleAdsClient->getAdGroupCriterionServiceClient();
    $response = $adGroupCriterionServiceClient->mutateAdGroupCriteria(
        MutateAdGroupCriteriaRequest::build($customerId, [
            $adGroupCriterionOperation
        ])
    );`

Error result:

ApiException was thrown with message { "message": "Request contains an invalid argument.", "code": 3, "status": "INVALID_ARGUMENT", "details": [ { "@type": "type.googleapis.com\/google.ads.googleads.v14.errors.GoogleAdsFailure", "errors": [ { "errorCode": { "mutateError": "RESOURCE_NOT_FOUND" }, "message": "Resource was not found.", "trigger": { "int64Value": "20" }, "location": { "fieldPathElements": [ { "fieldName": "operations", "index": 0 }, { "fieldName": "update" }, { "fieldName": "resource_name" } ] } } ], "requestId": "K9KiFCMtsD50Yf5eQOYUNA" } ] }

fiboknacky commented 1 year ago

Are you sure that your resource name is correct?

    $adGroupCriterion->setResourceName($adGroupResourceName);

It looks like you set the resource name of ad group to ad group criterion.

0x1881 commented 1 year ago

Are you sure that your resource name is correct?


    $adGroupCriterion->setResourceName($adGroupResourceName);

It looks like you set the resource name of ad group to ad group criterion.

Thank you dude. You can close the problem.

I realized that unknown gender is not included in the target criteria. When I added the unknown gender manually, the update problem was solved.

So how can I delete and add unknown gender in ad groups with PHP?

fiboknacky commented 1 year ago

This is an example of how to remove objects in Google Ads API. Once you remove the old one, you can then add a new one by specifying a correct resource name you want to add like shown in this example.