error when creating new ad schedule (campaign criterion)

109 views
Skip to first unread message

fru...@adzlocal.de

unread,
Oct 2, 2020, 8:10:27 AM10/2/20
to AdWords API and Google Ads API Forum
Hi there,

i'm trying to create a set of adgroup criteria for a campaign (ad schedules) with the new php v5 library.
But all i get is an error message saying that the field 'campaign' is missing.
This is the debug log output:


[2020-10-02 13:41:06] google-ads.WARNING: Request made: Host: "googleads.googleapis.com", Method: "/google.ads.googleads.v5.services.CampaignCriterionService/MutateCampaignCriteria", CustomerId: 9060438356, RequestId: "IM6lns_YYYaajRQPX6ocGA", IsFault: 1, FaultMessage: "["Field 'campaign' is required for 'CREATE' operation.","Field 'campaign' is required for 'CREATE' operation.","Field 'campaign' is required for 'CREATE' operation.","Field 'campaign' is required for 'CREATE' operation.","Field 'campaign' is required for 'CREATE' operation."]"  
[2020-10-02 13:41:06] google-ads.NOTICE: Request
-------
Method Name: /google.ads.googleads.v5.services.CampaignCriterionService/MutateCampaignCriteria
Headers: {
    "x-goog-api-client": "gl-php\/7.3.18 gapic\/ gax\/1.4.0 grpc\/1.29.1",
    "x-goog-request-params": "customer_id=9060438356",
    "developer-token": "REDACTED",
    "login-customer-id": "3478781078"
}
Request: {"customerId":"9060438356","operations":[{"create":{"adSchedule":{"startMinute":"ZERO","endMinute":"ZERO","dayOfWeek":"MONDAY"}}},{"create":{"adSchedule":{"startMinute":"ZERO","endMinute":"ZERO","dayOfWeek":"TUESDAY"}}},{"create":{"adSchedule":{"startMinute":"ZERO","endMinute":"ZERO","dayOfWeek":"WEDNESDAY"}}},{"create":{"adSchedule":{"startMinute":"ZERO","endMinute":"ZERO","dayOfWeek":"THURSDAY"}}},{"create":{"adSchedule":{"startMinute":"ZERO","endMinute":"ZERO","dayOfWeek":"FRIDAY"}}}]}

Response
-------
Headers: {
    "request-id": "IM6lns_YYYaajRQPX6ocGA",
    "date": "Fri, 02 Oct 2020 11:41:05 GMT",
    "alt-svc": "h3-Q050=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-27=\":443\"; ma=2592000,h3-T051=\":443\"; ma=2592000,h3-T050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\""
}

Fault
-------
Status code: 3
Details: Request contains an invalid argument.
Failure: {"errors":[{"errorCode":{"requestError":"REQUIRED_FIELD_MISSING"},"message":"Field 'campaign' is required for 'CREATE' operation.","location":{"fieldPathElements":[{"fieldName":"operations","index":"0"},{"fieldName":"create"},{"fieldName":"campaign"}]}},{"errorCode":{"requestError":"REQUIRED_FIELD_MISSING"},"message":"Field 'campaign' is required for 'CREATE' operation.","location":{"fieldPathElements":[{"fieldName":"operations","index":"1"},{"fieldName":"create"},{"fieldName":"campaign"}]}},{"errorCode":{"requestError":"REQUIRED_FIELD_MISSING"},"message":"Field 'campaign' is required for 'CREATE' operation.","location":{"fieldPathElements":[{"fieldName":"operations","index":"2"},{"fieldName":"create"},{"fieldName":"campaign"}]}},{"errorCode":{"requestError":"REQUIRED_FIELD_MISSING"},"message":"Field 'campaign' is required for 'CREATE' operation.","location":{"fieldPathElements":[{"fieldName":"operations","index":"3"},{"fieldName":"create"},{"fieldName":"campaign"}]}},{"errorCode":{"requestError":"REQUIRED_FIELD_MISSING"},"message":"Field 'campaign' is required for 'CREATE' operation.","location":{"fieldPathElements":[{"fieldName":"operations","index":"4"},{"fieldName":"create"},{"fieldName":"campaign"}]}}]}  




I can see that the request seems to be missing the campaign field, but i think the campaign has been set for each new campaign criterion.
This is my code:

....
$campaignResourceName = ResourceNames::forCampaign($accountId, $campaignId);
$operations = [];
foreach ($adScheduleInfos as $adScheduleInfo) {
$campaignCriterion = new CampaignCriterion(
[
'ad_schedule' => $adScheduleInfo,
'campaign' => $campaignResourceName
]
);
$operations[] = new CampaignCriterionOperation(['create' => $campaignCriterion]);
}

foreach ($operations as $op) {
var_dump($op->getCreate()->getCampaign());
}

$response = $googleAdsClient->getCampaignCriterionServiceClient()->mutateCampaignCriteria($accountId, $operations);
....

The var_dump() prints: 
.... CampaignCriterionAdScheduleHelper.php:90:string 'customers/9060438356/campaigns/9882431196' (length=41)

But when i look at the request/log, campaign is not set for the operations.
I tried to follow this example: https://developers.google.com/google-ads/api/docs/samples/add-campaign-targeting-criteria#php for creating new campaign criteria.
What i'm doing wrong?

Thanks,
Frank

Google Ads API Forum Advisor Prod

unread,
Oct 2, 2020, 12:29:33 PM10/2/20
to fru...@adzlocal.de, adwor...@googlegroups.com
Hi Frank,

You will need to set the campaign just like how the example you provided did.

In the campaignCriterion object, you will need to add
'campaign' => $campaignResourceName

You'll also need to provide pass the variable in the function that creates the ad schedule.

Regards,
Anthony
Google Ads API Team

Google Logo
Anthony
Google Ads API Team
 


ref:_00D1U1174p._5004Q25Yela:ref

fru...@adzlocal.de

unread,
Oct 5, 2020, 6:10:00 AM10/5/20
to AdWords API and Google Ads API Forum
Hi Anthony, 

thank you for the response. 
But unfortunately i don't get it - you said i should add 'campaign' => $campaignResourceName to the campaignCriterion, but that's exactly what i do in my code..?
Even the var_dump() prints the campaign resource name which has been set before. 

And what do you mean by passing the the variable int the function that creates the ad schedule?
I can't find any possibility to set a campaign for an ad schedule.

That's how my code looks like to create the ad schedules ($adScheduleData is a simple array with predefined start and end hours/minutes):

foreach ($adScheduleData as $weekDayName => $scheduleDataset) {
$adScheduleInfos[] = new AdScheduleInfo([
'day_of_week' => DayOfWeek::value($weekDayName),
'start_hour' => $scheduleDataset['startHour'],
'start_minute' => $scheduleDataset['startMinute'] ?? MinuteOfHour::ZERO,
'end_hour' => $scheduleDataset['endHour'],
'end_minute' => $scheduleDataset['endMinute'] ?? MinuteOfHour::ZERO,
]);
}

I appreciate any help!

Regards
Frank

Google Ads API Forum Advisor Prod

unread,
Oct 5, 2020, 2:01:04 PM10/5/20
to fru...@adzlocal.de, adwor...@googlegroups.com
Hi Frank,

Can you please reply privately to author your code so I can see if you set the campaign properly?

Thanks,

goo...@spammerz.de

unread,
Oct 8, 2020, 10:50:58 AM10/8/20
to AdWords API and Google Ads API Forum
Hey there, I seem to have a similar error when trying to create an ExpandedTextAd. Getting the message that 'Field 'ad_group' is required for 'CREATE' operation'.

Similar to the example above I do provide resource name and everything required. Google Ads V4 does not complain about this. Using batch jobs to create the ads.

Google Ads API Forum Advisor Prod

unread,
Oct 8, 2020, 3:47:24 PM10/8/20
to goo...@spammerz.de, adwor...@googlegroups.com
Hello,

Can you please reply privately to author your request and response for this API call so that we can take a closer look?

fru...@adzlocal.de

unread,
Dec 10, 2020, 9:11:19 AM12/10/20
to AdWords API and Google Ads API Forum
hey, just made another attempt to update to api v5 but with an updated protobuf library (v3.14.0) which in the meantime has been updated due to a known issue - now it works as expected
so if someone stumbles upon a similar problem please check/update your library versions..

Reply all
Reply to author
Forward
0 new messages