Creating ad_schedule using rest API with the campaignCriteria service

229 views
Skip to first unread message

Eylon Raymond Harari

unread,
Feb 3, 2021, 12:03:03 AM2/3/21
to AdWords API and Google Ads API Forum
I am trying to create new a ad_schedule for a given campaign. 

Steps I have taken to achieve that: 
1) Get all the existing ad_schedule criteria - working  
2) Remove all ad_schedule criteria to "clear the ground" before creating new ones  - working 
3) Creation of new ad_schedule criteria - not working  

Sample of curl request made for the creation of new ad_schedule criteria: 

--header 'Authorization: Bearer {access_token}' \
--header 'developer-token: {developer token}' \
--header 'login-customer-id: 123456789' \
--header 'Content-Type: application/json' \
--data-raw '{
   "operations":[
      {
         "create":{
            "resourceName":"customers/{customer_id}/campaignCriteria/{campaign_id}~{random_generated_id}",
            "adSchedule":{
               "startMinute":"{scheduleDay.startMinute}",
               "endMinute":"{scheduleDay.endMinute}",
               "dayOfWeek":"{scheduleDay.dayOfWeek}",
               "startHour":"{scheduleDay.startHour}",
               "endHour":"{scheduleDay.endHour}"
            },
            "status":"ENABLED",
            "campaign":"{campaign_id}",
            "bidModifier":1.0
         }
      }
   ]
}'

I suspect it is not working because of the incorrect "resourceName". I was following this guide, which instructs to set the "resourceName" as such: customers/{customer_id}/campaignCriteria/{campaign_id}~{criterion_id}..

Currently, because it's a create operation I am randomly creating the "criterion_id" as you can see in the CURL request

I also tried to set the  "resourceName" as only "customers/{customer_id}/campaignCriteria" but it didn't work as well... 

What can I be missing here? 

Thanks 👍


Eylon Raymond Harari

unread,
Feb 3, 2021, 1:25:39 AM2/3/21
to AdWords API and Google Ads API Forum
Edit: I have found this key point: 
"Key Point: Create operations don't specify a resourceName or ID. When the API call succeeds, the response includes the resourceName generated for the newly created object." in this guide https://developers.google.com/google-ads/api/docs/rest/common/mutate#create

So the new request looks like this after changing resourceName to campaignCriterion

--header 'Authorization: Bearer {access_token}' \
--header 'developer-token: {developer token}' \
--header 'login-customer-id: 123456789' \
--header 'Content-Type: application/json' \
--data-raw '{
   "operations":[
      {
         "create":{
            "campaignCriterion":"customers/{customer_id}/campaignCriteria/{campaign_id}~{random_generated_id}",
            "adSchedule":{
               "startMinute":"{scheduleDay.startMinute}",
               "endMinute":"{scheduleDay.endMinute}",
               "dayOfWeek":"{scheduleDay.dayOfWeek}",
               "startHour":"{scheduleDay.startHour}",
               "endHour":"{scheduleDay.endHour}"
            },
            "status":"ENABLED",
            "campaign":"{campaign_id}",
            "bidModifier":1.0
         }
      }
   ]
}'

I also made the request with a few variations to fish out if I had a typo: 
1- "campaignCriterion":"customers/{customer_id}/campaignCriteria/{campaign_id}~{random_generated_id}"
2- "campaignCriterion":"customers/{customer_id}/campaignCriteria"
3- "campaignCriteria":"customers/{customer_id}/campaignCriteria/{campaign_id}~{random_generated_id}"
4- "campaignCriteria":"customers/{customer_id}/campaignCriteria"

The operation still does not work after these edits 



Google Ads API Forum Advisor Prod

unread,
Feb 3, 2021, 4:01:03 PM2/3/21
to eyl...@gmail.com, adwor...@googlegroups.com

Hi Eylon,

Thank you for reaching out. When you create a new CampaignCriterion, you are not supposed to add resourceName in the operations. Please remove the "campaignCriterion":"customers/{customer_id}/campaignCriteria/{campaign_id}~{random_generated_id}" and try it again.

Thanks and regards,
Xiaoming, Google Ads API Team
 

Google Logo
Xiaoming
Google Ads API Team
 


ref:_00D1U1174p._5004Q2BdL8k:ref

Eylon Raymond Harari

unread,
Feb 3, 2021, 7:41:18 PM2/3/21
to AdWords API and Google Ads API Forum
Hi, thanks for the tip 

I tried again like this:


--header 'Authorization: Bearer {access_token}' \
--header 'developer-token: {developer token}' \
--header 'login-customer-id: 123456789' \
--header 'Content-Type: application/json' \
--data-raw '{
   "operations":[
      {
         "create":{
            "adSchedule":{
               "startMinute":"{scheduleDay.startMinute}",
               "endMinute":"{scheduleDay.endMinute}",
               "dayOfWeek":"{scheduleDay.dayOfWeek}",
               "startHour":"{scheduleDay.startHour}",
               "endHour":"{scheduleDay.endHour}"
            },
            "status":"ENABLED",
            "campaign":"{campaign_id}",
            "bidModifier":1.0
         }
      }
   ]
}


And it still doesn't work.. 

Would appreciate other ideas of how to solve that  👍

Eylon Raymond Harari

unread,
Feb 3, 2021, 10:08:24 PM2/3/21
to AdWords API and Google Ads API Forum
Its working now - 

This is the correct payload: 

{
   "operations":[
      {
         "create":{
            "adSchedule":{
               "startMinute":"{scheduleDay.startMinute}",
               "endMinute":"{scheduleDay.endMinute}",
               "dayOfWeek":"{scheduleDay.dayOfWeek}",
               "startHour":"{scheduleDay.startHour}",
               "endHour":"{scheduleDay.endHour}"
            },
            "status":"ENABLED",
            "campaign":"customers/{customer_id}/campaigns/{campaign_id}",
            "bidModifier":1.0
         }
      }
   ]
}

campaign needs to be in in "customers/{customer_id}/campaigns/{campaign_id}" format, and not only the campaign ID

Google Ads API Forum Advisor Prod

unread,
Feb 4, 2021, 2:47:11 PM2/4/21
to eyl...@gmail.com, adwor...@googlegroups.com

Hi Eylon,

Thank you for reaching out. Yes, whenever you specify an entity in the Google Ads API, you would need to look up their resource_name and use it in the request payload. In your case, the campaign has to follow this pattern.



Thanks and regards,
Xiaoming, Google Ads API Team
 

Reply all
Reply to author
Forward
0 new messages