CampaignCriterionOperation IpBlockInfo criterion_id from response

144 views
Skip to first unread message

Andras Kende

unread,
Jan 19, 2022, 1:35:33 PM1/19/22
to Google Ads API and AdWords API Forum
Hello,

Trying to get the criterion_id (987654321) from the the api CampaignCriterionOperation results..

"customers/123456789/campaignCriteria/1122334455~987654321"



$campaignCriterion = new CampaignCriterion([
'negative' => true,
'campaign' => ResourceNames::forCampaign($google_ads_customerid, $google_ads_campaignid),
'type' => CriterionType::IP_BLOCK,
'ip_block' => new IpBlockInfo(['ip_address' => '1.2.3.4'])
]);

$operation = new CampaignCriterionOperation(['create' => $campaignCriterion]);
$operations = [];
$operations[] = $operation;
$campaignCriterionServiceClient = $googleAdsClient->getCampaignCriterionServiceClient();
$response = $campaignCriterionServiceClient->mutateCampaignCriteria($google_ads_customerid, $operations);

$google_ads_resource = $response->getResults()[0]->getResourceName();
$google_ads_resource_explode = explode('~', $google_ads_resource)
$criterion_id = $google_ads_resource_explode[1];

$criterion_id = $response->getResults() ????


Thanks,
Andras




Google Ads API Forum Advisor

unread,
Jan 19, 2022, 10:33:19 PM1/19/22
to and...@gmail.com, adwor...@googlegroups.com

Hi Andras,

Thanks for reaching out to the Google Ads API Support.

Could you provide us with the complete request and response logs with the request-id, so our team can better check?

For the PHP client library, logging can be enabled by navigating to the Client libraries > Your client library (Select PHP) > Logging documentation, which you can access from this link. You may then send the requested information via the Reply privately to author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead.

Regards,

Google Logo
Yasar
Google Ads API Team
 


ref:_00D1U1174p._5004Q2VNWVr:ref

Andras Kende

unread,
Jan 21, 2022, 2:57:31 PM1/21/22
to Google Ads API and AdWords API Forum
Hi Yasar,

the new API code is working fine, my question is:

$response = $campaignCriterionServiceClient->mutateCampaignCriteria($google_ads_customerid, $operations);
$results = $response->getResults()[0]->getResourceName();

returns the following string:
"customers/123456789/campaignCriteria/1122334455~987654321"

but wondering if it's possible to get the criterion_id from the API .

Currently exploding the getResourceName string to get the criterion_id which is the last part after the ~
$google_ads_resource = $response->getResults()[0]->getResourceName();
       - "customers/123456789/campaignCriteria/1122334455~987654321"
$google_ads_resource_explode = explode('~', $google_ads_resource);
$criterion_id = $google_ads_resource_explode[1];
- "987654321"


on the old adwords API I used as:
$criterion_id = $campaignCriterion->getCriterion()->getId();
old API also returned the IP address as :
$campaignCriterion->getCriterion()->getipAddress();

Thanks,
Andras

Google Ads API Forum Advisor

unread,
Jan 24, 2022, 3:54:56 AM1/24/22
to and...@gmail.com, adwor...@googlegroups.com
Hi Andras,

Thank you for your reply.

You can use the campaign_criterion report to retrieve the details such as campaign_criterion.criterion_id and campaign_criterion.ip_block.ip_address. Let me know if this helps.

Best regards,

Google Logo
Peter Laurence Napa Oliquino
Google Ads API Team
 


ref:_00D1U1174p._5004Q2VNWVr:ref

Andras Kende

unread,
Jan 24, 2022, 5:15:15 AM1/24/22
to Google Ads API and AdWords API Forum
Hi Peter

So I would have to query each mutateCampaignCriteria with a new API request like:

SELECT campaign_criterion.criterion_id, campaign_criterion.ip_block.ip_address FROM campaign_criterion WHERE campaign_criterion.resource_name = 'customers/123456789/campaignCriteria/1122334455~987654321'

Thanks,
Andras

Google Ads API Forum Advisor

unread,
Jan 25, 2022, 1:01:50 AM1/25/22
to and...@gmail.com, adwor...@googlegroups.com

Hello Andras,

Thanks for getting back to us.

Can you try this guide (Retrieve mutable attributes from the response)? The response will contain the values of all mutable fields for every object created or updated by the request. If you're unable to retrieve those details, then you can utilize the campaign_criterion report as previously mentioned by my colleague(Peter).

Regards,

Google Logo
Mark Kevin Albios
Google Ads API Team
 


ref:_00D1U1174p._5004Q2VNWVr:ref
Reply all
Reply to author
Forward
0 new messages