google-ads-php icon indicating copy to clipboard operation
google-ads-php copied to clipboard

MutateAdGroupCriterionResult does not return CpcBidMicros

Open chiragvels opened this issue 1 year ago • 12 comments

[DO NOT INCLUDE ANY PERSONAL OR SENSITIVE DATA - MAKE SURE TO REDACT CONTENT WHEN NECESSARY]

Your client library and Google Ads API versions:

  • Client library version: v23.1.0
  • Google Ads API version: V17

Your environment: PHP 8.1.2-1ubuntu2.18 Linux

Description of the bug: I am not able to get AdGroupCriterion object with option getAdGroupCriterion(); And so that I cannot see CpcBidMicros

Steps to reproduce: I was trying to update response for keywords through mutateAdGroupCriteria.

Expected behavior: Should have return macCPC and AdGroupCriterion Object. Request/Response Logs: object(Google\Ads\GoogleAds\V17\Services\MutateAdGroupCriterionResult)#146 (0) { } Operation 0 succeeded: ad group with resource name 'customers/XXXXX/adGroupCriteria/1148XXX3111~39774910'.

Anything else we should know about your project / environment:

chiragvels avatar Aug 26 '24 07:08 chiragvels

@chiragvels

Could you share your code too please?

fiboknacky avatar Aug 26 '24 07:08 fiboknacky

Hi @fiboknacky ,

The code :

$response = $adGroupCriterionServiceClient->mutateAdGroupCriteria(
                    MutateAdGroupCriteriaRequest::build($this->client_id, $adGroupCriterionOperations),
                        ['partialFailure' => true, 'responseContentType' => ResponseContentType::MUTABLE_RESOURCE]
                );
           if($response->getResults()->count()){
                  $operationIndex = 0;
                  foreach ($response->getResults() as $addedAdGroupCriterion) {
                   printf(
                            "Operation %d succeeded: ad group with resource name '%s'.%s",
                            $operationIndex,
                            $addedAdGroupCriterion->getResourceName(),
                            PHP_EOL
                    );
                   $kwAmount = ($addedAdGroupCriterion->getAdGroupCriterion() != NULL) ? $addedAdGroupCriterion->getAdGroupCriterion()->getCpcBidMicros() : '--';
                 }
           }


chiragvels avatar Aug 26 '24 07:08 chiragvels

Could you share the whole code like how you created the ad group criterion operation? And if you have a request ID, could you also share it here too? Thanks.

fiboknacky avatar Aug 26 '24 16:08 fiboknacky

Hi @fiboknacky ,

Part of the code:


             $adGroupCriterion = new AdGroupCriterion([
                        'resource_name' => ResourceNames::forAdGroupCriterion(
                            $this->client_id, 
                            $adGroupId,
                            $criterionId
                        ),
                        'cpc_bid_micros' => $max_cpc_in_micros
                    ]);

                    $adGroupCriterionOperation = new AdGroupCriterionOperation();
                    $adGroupCriterionOperation->setUpdate($adGroupCriterion);
                    $adGroupCriterionOperation->setUpdateMask(FieldMasks::allSetFieldsOf($adGroupCriterion));
                    $adGroupCriterionOperations[] = $adGroupCriterionOperation;

                   $adGroupCriterionServiceClient = $googleAdsClient->getAdGroupCriterionServiceClient();
                   $response = $adGroupCriterionServiceClient->mutateAdGroupCriteria(
                    MutateAdGroupCriteriaRequest::build($this->client_id, $adGroupCriterionOperations),
                        ['partialFailure' => true, 'responseContentType' => ResponseContentType::MUTABLE_RESOURCE]
                );
           if($response->getResults()->count()){
                  $operationIndex = 0;
                  foreach ($response->getResults() as $addedAdGroupCriterion) {
                   printf(
                            "Operation %d succeeded: ad group with resource name '%s'.%s",
                            $operationIndex,
                            $addedAdGroupCriterion->getResourceName(),
                            PHP_EOL
                    );
                   $kwAmount = ($addedAdGroupCriterion->getAdGroupCriterion() != NULL) ? $addedAdGroupCriterion->getAdGroupCriterion()->getCpcBidMicros() : '--';
                 }
}

RequestId: "4Kz5u1DT2MXMEZtOR3Q9BQ"

chiragvels avatar Aug 26 '24 17:08 chiragvels

Hi @fiboknacky ,

This is strange.

worked with this code

$response = $adGroupCriterionServiceClient->mutateAdGroupCriteria(
                    MutateAdGroupCriteriaRequest::build($this->client_id, $adGroupCriterionOperations)
                        ->setPartialFailure(true)
                        ->setResponseContentType(ResponseContentType::MUTABLE_RESOURCE)
                );

But not with this code

$response = $adGroupCriterionServiceClient->mutateAdGroupCriteria(
                    MutateAdGroupCriteriaRequest::build($this->client_id, $adGroupCriterionOperations),
                        ['partialFailure' => true, 'responseContentType' => ResponseContentType::MUTABLE_RESOURCE]
                );

"request-id": "DFTKWP1FJufECXQBo-xiHA", Thanks,

chiragvels avatar Aug 27 '24 07:08 chiragvels

Thanks. That's interesting information and should be helpful to my investigation. Allow me some time to check this.

fiboknacky avatar Aug 27 '24 16:08 fiboknacky

Hi @fiboknacky ,

did you get a chance to check this?

Thanks,

chiragvels avatar Sep 02 '24 05:09 chiragvels

Sorry, I'm pretty swamped right now and would be able to take a look at this next week.

fiboknacky avatar Sep 05 '24 02:09 fiboknacky

I might also think https://github.com/googleads/google-ads-php/blob/357866960b34125a21ef1c3c7b193ee7d68dfa20/examples/ErrorHandling/HandlePartialFailure.php#L185

it should be ['partial_failure'=>true] ?

So that in my code ['partial_failure' => true, 'response_content_type' => ResponseContentType::MUTABLE_RESOURCE]

Thanks,

chiragvels avatar Sep 09 '24 11:09 chiragvels

First, for your mentioned code: https://github.com/googleads/google-ads-php/blob/357866960b34125a21ef1c3c7b193ee7d68dfa20/examples/ErrorHandling/HandlePartialFailure.php#L185

It should be

MutateAdGroupsRequest::build($customerId, $operations)->setPartialFailure(true)

as explained in this section.

I'll update this example soon.

Therefore, for your code, it should be:

MutateAdGroupCriteriaRequest::build($this->client_id, $adGroupCriterionOperations)
    ->setPartialFailure(true)
    ->setResponseContentType(ResponseContentType::MUTABLE_RESOURCE)

Could you please try it?

fiboknacky avatar Sep 11 '24 06:09 fiboknacky

Hi @fiboknacky ,

Yes, it is working as I mentioned in my earlier comment here

However, the issue arises with options passed as an array like this or https://github.com/googleads/google-ads-php/blob/357866960b34125a21ef1c3c7b193ee7d68dfa20/examples/ErrorHandling/HandleRateExceededError.php#L257

['partialFailure' => true, 'responseContentType' => ResponseContentType::MUTABLE_RESOURCE]

This would fail.

As I checked examples, partial failures are used as 'partialFailure' in examples everywhere, but I believe it should be 'partial_failure'.

Therefore, using:

['partial_failure' => true]

should work?

Thanks

chiragvels avatar Sep 11 '24 07:09 chiragvels

No. That wouldn't work after we migrated to GAPIC v2 as I mentioned above.

HandleRateExceededError.php would need an update too. Sorry that we didn't see this earlier.

fiboknacky avatar Sep 11 '24 09:09 fiboknacky

Closing as the instructions have been provided.

fiboknacky avatar Mar 18 '25 08:03 fiboknacky

Hi @fiboknacky ,

As you instructed here

Is example updated?

Thanks,

chiragvels avatar Mar 18 '25 08:03 chiragvels

It's already changed to this style.

fiboknacky avatar Mar 18 '25 13:03 fiboknacky