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",
}
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.
What i'm doing wrong?
Thanks,
Frank