Creating Bath Job Doesn't Work

12 views
Skip to first unread message

Kanan Farzali

unread,
Jun 20, 2017, 11:08:34 AM6/20/17
to AdWords API Forum
Hi Google,

I have recently updated my code to the new API - v 201705 now being used and the code has been updated respectively.

The new code looks like this (php):

function createBatchJob($clientId, $operations) {
 $oAuth2Credential
= (new OAuth2TokenBuilder())
 
->fromFile()
 
->build();

 
// Construct an API session configured from a properties file and the OAuth2
 
// credentials above.
 $session
= (new AdWordsSessionBuilder())
 
->fromFile()
 
->withOAuth2Credential($oAuth2Credential)
 
->withClientCustomerId($clientId)
 
->build();

 $adWordsServices
= new AdWordsServices();
 $batchJobService
= $adWordsServices->get($session, BatchJobService::class);

 
// Create a BatchJob.
 $addOp
= new BatchJobOperation();
 $addOp
->setOperator(Operator::ADD);
 $addOp
->setOperand(new BatchJob());

 $result
= $batchJobService->mutate([$addOp]);
 $batchJob
= $result->getValue()[0];

 $uploadUrl
= $batchJob->getUploadUrl()->getUrl();

 $batchJobs
= new BatchJobs($session);

 $batchJobs
->uploadBatchJobOperations($operations, $uploadUrl);

 
if (!empty($batchJob->getUploadUrl()->getUrl())) {
 $jobDetails
= new stdClass();
 $jobDetails
->job_id = $batchJob->getId();
 $jobDetails
->client_id = $clientId;

 
return $jobDetails;
 
}
}



The code creates a btach job and gives response but unfortunately campaigns are not getting paused in the account. Basically it gives back 'AWAITING FILE' response which is not what exactly I want.

I feel like something is missing in my code. Please help.

Shwetha Vastrad (AdWords API Team)

unread,
Jun 20, 2017, 3:44:54 PM6/20/17
to AdWords API Forum
Hi Kanan,

Could you provide a few sample BatchJobIds which are in AWAITING_FILE status? Please note that you need to poll the batch job's status periodically until it is CANCELED or DONE. This example shows how to poll for completion of the batch job using an exponential back off.

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