Inconsistent results using mutateLabel (PHP API)

30 views
Skip to first unread message

autoeuro...@gmail.com

unread,
Dec 7, 2016, 9:43:56 AM12/7/16
to AdWords API Forum
Hi all,

I'm using the following function in a Test Account to change Keyword labels. The problem is it randomly changes the labels, sometimes it will process just a few of my requests, sometimes half, sometimes none, there's really no coherent pattern to it. No errors are thrown.

In the example I'm using, the mysql query will return a total of 96 keywords that need label changes. Each keyword has 3 labels, so that's 96 * 3, plus each keyword already has 3 labels that need to be removed first, so that's a total of (96*3) * 2 (one REMOVE operation and one ADD operation). A total of 576 operations. It doesn't seem to make a difference if I send them all, or just 50, or just 10 at a time, the results are always inconsistent and the labels are NEVER all changes, only a few get processed. (and which ones seems to be quite random).

In this example I'm limiting my request to just below 2000 operations (as suggested by the batch request documentation), although the total sent is never that much.



function bulkCommitKeywordLabels($user, $accountName, $lType){
    $conn
= conn();
    $q
= mysqli_query($conn,"select `id`,`keywordId`,`adgroupId`,`oldLabelId`,`newLabelId` from `cronJobLabelUpdate` where `accountName` = '$accountName'  and `labelType` = '$lType' and `outcome` = 'WAITING'");
    $criterionService
= $user->GetService('AdGroupCriterionService', ADWORDS_VERSION);
    $operations
= array();
    $requestLimit
= 0;
    $cnt
= 0;
   
while($r = mysqli_fetch_assoc($q)){
        $requestLimit
++;
       
if(trim($r['keywordId']) != '' && trim($r['adgroupId']) != ''){
            $id
= $r['id'];
           
// Label to be removed
            $op1data
= new AdGroupCriterionLabel($r['adgroupId'],$r['keywordId'],$r['oldLabelId']);
            $op1
= new AdGroupCriterionLabelOperation();
            $op1
->operand = $op1data;
            $op1
->operator = 'REMOVE';
            $operations
[] = $op1;
           
// Label to be added
            $op2data
= new AdGroupCriterionLabel($r['adgroupId'],$r['keywordId'],$r['newLabelId']);
            $op2
= new AdGroupCriterionLabelOperation();
            $op2
->operand = $op2data;
            $op2
->operator = 'ADD';
            $operations
[] = $op2;
            mysqli_query
($conn,"update `cronJobLabelUpdate` set `outcome` = 'SENT' where `id` = '$id' limit 1");
       
}else{
            echo
'<br>Invalid KeywordId... Maybe?<br>';
       
}
       
if($requestLimit >= 999){ // this is actually double since there's always a REMOVE and an ADD operation for each keywordID
            $cnt
++;
           
// commit changes, clear variables
           
try{
                $result
= $criterionService->mutateLabel($operations);
               
if($result->partialFailureErrors != NULL){
                    var_dump
($result->partialFailureErrors);
                    echo
'<br>Count: '.$cnt.'<br>';
               
}
           
}catch(Exception $e){
                echo
'<br>Error on Function (bulkCommitKeywordLabels)' . $e->getMessage() .' count: '.$cnt;
                echo
'<br>TERMINATING';
               
exit();
           
}
            $operations
= array();
            $requestLimit
= 0;
            sleep
(2);
       
}
   
}        
}



Thanks for your help,

Shwetha Vastrad (AdWords API Team)

unread,
Dec 7, 2016, 1:26:52 PM12/7/16
to AdWords API Forum
Hi, 

Could you enable logging by following the instructions provided here and retry the request? Please send me the SOAP XML request and response logs generated so I can see what's going wrong. Please use Reply privately to author when responding.

Thanks,
Shwetha, AdWords API Team.
Reply all
Reply to author
Forward
0 new messages