How to remove an ad schedule using id?

212 views
Skip to first unread message

Ken Dan Tinio

unread,
Feb 20, 2018, 5:00:56 AM2/20/18
to AdWords API Forum

so far I have this code


    $adsched = new AdSchedule();
    $adsched->setId($ad_schedule_id);

    // Create a criterion with modified bid.
    $criterion = new CampaignCriterion();
    $criterion->setCampaignId($campaign_id);
    $criterion->setCriterion($adsched);

    // Create a campaign criterion operation and add it to the operations list.
    $operation = new CampaignCriterionOperation();
    $operation->setOperator(Operator::REMOVE);
    $operation->setOperand($criterion);
    $operations = [$operation];


Then I get this error

[OperationAccessDenied.OPERATION_NOT_PERMITTED_FOR_REMOVED_ENTITY @ operations[0]]

Dhanya Sundararaju (AdWords API Team)

unread,
Feb 20, 2018, 11:28:07 AM2/20/18
to AdWords API Forum
Hi Ken,

The error OperationAccessDenied.OPERATION_NOT_PERMITTED_FOR_REMOVED_ENTITY, is usually thrown when you try to do a mutate operation on a entity that was already removed. Please refer guide for better clarity. You could also get a EntityNotFound.INVALID_ID error. Your code looks good to me and should remove the ad schedule using AdSchedule id, after the line $campaignCriterionService->mutate($removeOperations); is executed as in example here. If this does not address your issue, could you please reply with your complete SOAP logs? You may opt to reply privately to author.

Regards,
Dhanya, AdWords API Team

Ken Dan Tinio

unread,
Feb 21, 2018, 11:40:51 PM2/21/18
to AdWords API Forum
How do I know if its removed status?


so far I have this code:

          $data[] = array(
              "id"              => $campaignCriterion->getCriterion()->getId(),
              "type"            => $campaignCriterion->getCriterion()->getType(),
              "dayofweek"       => $campaignCriterion->getCriterion()->getDayOfWeek(),
              "starthour"       => $campaignCriterion->getCriterion()->getStartHour(),
              "startminute"     => $campaignCriterion->getCriterion()->getStartMinute(),
              "endhour"         => $campaignCriterion->getCriterion()->getEndHour(),
              "endminute"       => $campaignCriterion->getCriterion()->getEndMinute(),
              "campaign_id"     => $campaignCriterion->getCampaignId(),
              // "campaign_name"   => $campaignCriterion->getCampaign()->getName(),
          );

Dhanya Sundararaju (AdWords API Team)

unread,
Feb 22, 2018, 2:31:29 PM2/22/18
to AdWords API Forum
Hi Ken,

You can use the below code snippet to get the status of the criterion
$campaignCriterion->getCampaignCriterionStatus();

Ken Dan Tinio

unread,
Feb 22, 2018, 9:36:56 PM2/22/18
to AdWords API Forum
The status is null..



          $data[] = array(
              "id"              => $campaignCriterion->getCriterion()->getId(),
              "type"            => $campaignCriterion->getCriterion()->getType(),
              "dayofweek"       => $campaignCriterion->getCriterion()->getDayOfWeek(),
              "starthour"       => $string_start_hour,
              "startminute"     => $string_start_min,
              "endhour"         => $string_end_hour,
              "endminute"       => $string_end_min,
              "campaign_id"     => $campaignCriterion->getCampaignId(),
              "status"          => $campaignCriterion->getCampaignCriterionStatus(),
              "result"          => $dayofweek.", ".$string_start_hour.':'.$string_start_min.' to '.$string_end_hour.':'.$string_end_min
          ); 




        {
            "id": 320096,
            "type": "AD_SCHEDULE",
            "dayofweek": "WEDNESDAY",
            "starthour": "00",
            "startminute": "00",
            "endhour": 24,
            "endminute": "00",
            "campaign_id": 175483775,
            "status": null,
            "result": "Wednesday, 00:00 to 24:00"
        },

Dhanya Sundararaju (AdWords API Team)

unread,
Feb 23, 2018, 1:15:08 PM2/23/18
to AdWords API Forum
Hi Ken,

I was able to get the status for adschedule via the code snippet below. Please note that CampaignCriterionStatus field needs to be specified explicility in your selector fields:

$campaignCriterionService =
$adWordsServices->get($session, CampaignCriterionService::class);

// Create a selector to select all campaign criteria for the specified campaign.
$selector = new Selector();
$selector->setFields(['Id', 'CriteriaType', 'CampaignCriterionStatus']);
$selector->setPredicates([
new Predicate('CampaignId', PredicateOperator::IN, [$campaignId]),
new Predicate('CriteriaType', PredicateOperator::IN,['AD_SCHEDULE'])]);
$selector->setPaging(new Paging(0, self::PAGE_LIMIT));

$totalNumEntries = 0;
do {
// Retrieve campaign criteria one page at a time, continuing to request
// pages until all campaign criteria have been retrieved.
$page = $campaignCriterionService->get($selector);

// Print out some information for each campaign criterion.
if ($page->getEntries() !== null) {
$totalNumEntries = $page->getTotalNumEntries();
foreach ($page->getEntries() as $campaignCriterion) {
printf("Campaign targeting criterion with ID %d and type '%s' and status '%s' was found.\n",
$campaignCriterion->getCriterion()->getId(),
$campaignCriterion->getCriterion()->getType(),
$campaignCriterion->getCampaignCriterionStatus());
}
}

Response I received was as below:
[2018-02-23 11:30:21] AW_SOAP.INFO: clientCustomerId=***-***-**** operations=1 service=CampaignCriterionService method=get responseTime=164 requestId=000565e3ad2dae7a0ae9eb585b0316b1 server=adwords.google.com isFault=0 faultMessage= 
Campaign targeting criterion with ID 350096 and type 'AD_SCHEDULE' and status 'ACTIVE' was found.


If you still face issues, please reply back with your complete SOAP logs so that I will be able to troubleshoot further.

Ken Dan Tinio

unread,
Feb 26, 2018, 4:26:57 AM2/26/18
to AdWords API Forum
Thanks been look for that! Works amazingly!
Reply all
Reply to author
Forward
0 new messages