Set defferent bidModifier for different time slot

95 views
Skip to first unread message

Sachin Kumar

unread,
Jul 24, 2016, 1:07:32 AM7/24/16
to AdWords API Forum
Hello Team,


I want to set different bidModifier for different time slot e.g Time: 11-12 bidModifier=1.5, Time: 14-15 bidModifier=1.3.

To achieve this I used this code:

public function update_hour_bid(AdWordsUser $user,$clientId = null,$data=null){
        $newBid = explode("&", $data['newBid']);
        $user = new AdwordsUser();
        $user->SetClientCustomerId($clientId); // ClientId
        
        $campaignCriterionService = $user->GetService('CampaignCriterionService', ADWORDS_VERSION);
        
        $operations = array();
        $campaignID = $data['campaignid'];
        
        //$days = array('MONDAY','TUESDAY','WEDNESDAY','THURSDAY','FRIDAY','SATURDAY','SUNDAY');
                
        foreach($newBid as $bid){
            if(!empty($bid)){
            //foreach($days as $day) {
                $Biddata = explode("=", $bid);
                //$Biddata[0] // day
                //$Biddata[1] // hour
                //$Biddata[2] // bid
                $hour = explode('-',$Biddata[1]);
                // $hour[0] // start hour
                // $hour[1] // end hour
                               
                //Set Variables
                $adSchedule = new AdSchedule();
                $adSchedule->dayOfWeek = trim($Biddata[0]);
                $adSchedule->startHour = trim($hour[0]);
                $adSchedule->startMinute = 'ZERO';
                $adSchedule->endHour = trim($hour[1]);
                $adSchedule->endMinute = 'ZERO';
                                                              
                
                //$adSchedule->bidModifier = trim($Biddata[2]);
                                
                $adScheduleCriterion = new CampaignCriterion();//AdScheduleCriterion();
                $adScheduleCriterion->campaignId = $campaignID;
                $adScheduleCriterion->bidModifier = trim($Biddata[2]);
                $adScheduleCriterion->criterion = $adSchedule;
                              
                //Create the Operation
                $operation = new CampaignCriterionOperation();
                $operation->operand = $adScheduleCriterion;
                $operation->operator = 'ADD';
                $operations[] = $operation;
                                
                //echo '<pre>';print_r($operations);die();
            }
        }
        //Mutate!
        $result = $campaignCriterionService->mutate($operations);
        echo '<pre>';print_r($result);die();
        if (count($results->value)){
            return 1;
        }else{
            return 0;
        }

    }

 When I use $operation->operator = 'ADD' this code generate

<b>Fatal error</b>:  Uncaught SoapFault exception: [soap:Server] [CriterionError.AD_SCHEDULE_TIME_INTERVALS_OVERLAP
 @ operations[0].operand.criterion; trigger:'Existing schedule: AdSchedule{id=CriterionId{id=320824}
, dayOfWeek=WEDNESDAY, startHour=2, startMinute=ZERO, endHour=6, endMinute=ZERO}', RangeError.TOO_LOW
 @ operations[0].operand.bidModifier,

 When I use $operation->operator = 'SET' this generate error that criteria Id is required.


Kindly suggest me any change in this code so that I can set different  bidModifier for different time slot.


Thanks & Regards

Sachin Kumar



Peter Oliquino

unread,
Jul 25, 2016, 2:23:36 AM7/25/16
to AdWords API Forum
Hi Sachin,

My apologies for the delayed response. The CriterionError.AD_SCHEDULE_TIME_INTERVALS_OVERLAP error typically happens when you are adding the time interval of an AdSchedule which overlaps with another AdSchedule. You could use the CampaignCriterionService.get to get a list of campaign criteria along with their AdSchedule through the Selector to check and adjust the values you will put on the interval on the results as to avoid overlapping.

The RangeError.TOO_LOW error is caused by not specifying an ID in the call so you will need to make sure that the criterion IDs are being passed. Additionally, the startHour and endHour fields are ignored when using the SET operator, so in order to change the AdSchedule, you will first need to use the REMOVE operator using the ID field then the ADD operator with the updated values. Furthermore, you may refer to the discussion here for a more detailed guide as to how to change/modify the time your ads are showing and also for more information regarding Ad Scheduling. 

Best regards,
Peter
AdWords API Team

Sachin Kumar

unread,
Jul 25, 2016, 4:15:48 AM7/25/16
to AdWords API Forum
Thank you Peter for your reply. Your points helped me to find a way.


I got the way to add/update/remove the Ad schedule bid modifiers for different time slots. One thing I want to know, How I can get the list of fields which can be selected from any service e.g.('CampaignCriterionService')?


Thanks in advance.

Peter Oliquino

unread,
Jul 25, 2016, 4:57:02 AM7/25/16
to AdWords API Forum
Hi Sachin,

You can find the available fields through this link for CampaignCriterionService.get. For other services, you may refer to the rest of the information in the mentioned link.

Best regards,
Peter Laurence N. Oliquino
AdWords API Team

Sachin Kumar

unread,
Jul 25, 2016, 5:27:57 AM7/25/16
to AdWords API Forum
Hello Peter,

Thank you very much for the link.

I want dayOfWeek using CampaignCriterionService. the code is as:
// Create selector.
        $selector = new Selector();
        $selector->fields = array('Id','CriteriaType','CampaignId');
       
        $selector->predicates[] = new Predicate('CampaignStatus', 'NOT_IN', array('PAUSED', 'REMOVED'));
        $selector->predicates[] = new Predicate('CampaignId', 'IN', array('2545xxxx'));
        $selector->predicates[] = new Predicate('CriteriaType', 'EQUALS','AD_SCHEDULE');
        //$selector->predicates[] = new Predicate('Criterion.DayOfWeek','EQUALS','MONDAY');
        $selector->predicates[] = new Predicate('DayOfWeek','IN',array($day));

 but getting this fatal error:


<pre><br />
<b>Fatal error</b>:  Uncaught SoapFault exception: [soap:Server] [SelectorError.INVALID_PREDICATE_FIELD_NAME @ ; trigger:'DayOfWeek'] in /home/bergstromdev/public_html/Google/Api/Ads/Common/Lib/AdsSoapClient.php:216
Stack trace:
#0 /home/bergstromdev/public_html/Google/Api/Ads/Common/Lib/AdsSoapClient.php(216): SoapClient-&gt;__soapCall('get', Array, NULL, Array, Array)
#1 /home/bergstromdev/public_html/Google/Api/Ads/AdWords/v201603/CampaignCriterionService.php(7949): AdsSoapClient-&gt;__soapCall('get', Array)
#2 /home/bergstromdev/public_html/lib/Adwords.class.php(1816): CampaignCriterionService-&gt;get(Object(Selector))


Kindly suggest me a way.




On Sunday, July 24, 2016 at 10:37:32 AM UTC+5:30, Sachin Kumar wrote:

Peter Oliquino

unread,
Jul 25, 2016, 6:45:12 AM7/25/16
to AdWords API Forum
Hi Sachin,

Unfortunately the 'DayOfWeek' field is not filterable. You may refer once again in this link and check the 'Filterable' column for the fields you could use as a predicate. Additionally you would need to remove  "$selector->predicates[] = new Predicate('CampaignStatus', 'NOT_IN', array('PAUSED', 'REMOVED'));" since 'CampaignStatus' is not supported in the CampaignCriterionService.

Thanks and regards,
Peter
AdWords API Team
Reply all
Reply to author
Forward
0 new messages