Polling a batch job via PHP library needs unnecessary upload URL?

33 views
Skip to first unread message

JC Lee

unread,
Dec 1, 2016, 5:16:26 AM12/1/16
to AdWords API Forum
I noticed in the PHP library, BatchJobUtils' constructor has a required $uploadUrl param. Isn't upload URL unnecessary when polling a batch job?

In my case, I am using a queue system to poll the batch job.

Since I can't get the upload URL using BatchJobService->get (Doc says "This field is only returned when calling BatchJobService.mutate with an ADD operation."),

it means that I have to store the redundant upload URL in my database. Please let me know if this is true.

Sample code for downloading batch job results:
    $batchJobUtils = new \BatchJobUtils($batchJob->uploadUrl->url);
if ($batchJob->downloadUrl !== null && $batchJob->downloadUrl->url !== null) {
$xmlResponse = $batchJobUtils->DownloadBatchJobResults($batchJob->downloadUrl->url);
    }

Reading the Java sample code, instead of BatchJobUtils it's BatchJobHelper. BatchJobHelper does not have the required upload URL param.
AdWordsSession session = new AdWordsSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
BatchJobHelper batchJobHelper = new BatchJobHelper(session);
batchJobHelper.downloadBatchJobMutateResponse(batchJob.getDownloadUrl().getUrl());

Shwetha Vastrad (AdWords API Team)

unread,
Dec 1, 2016, 11:42:20 AM12/1/16
to AdWords API Forum
Hi,

Yes, UploadUrl is not needed when polling the status of a BatchJob using BatchJobService GET request. BatchJobUtils in the PHP client library is a collection of utility methods to upload batch operations and download the results, whereas BatchJobHelper is a utility in Java client library for similar use. The way these utilities are programmed in different client libraries will depend on the structure of the language. I would suggest that you post your question in the PHP client library repository so that this issue can be addressed there. 

Regards,
Shwetha, AdWords API Team.

JC Lee

unread,
Dec 2, 2016, 2:03:21 AM12/2/16
to AdWords API Forum
I have filed an issue on github.

In the mean time though, correct me if I am wrong, it looks like to download the batch job results in PHP I will have to have the upload URL.

Shwetha Vastrad (AdWords API Team)

unread,
Dec 2, 2016, 12:29:01 PM12/2/16
to AdWords API Forum
Hi,

You can download the BatchJob results without using the uploadUrl by using the code below:

  // Get the service, which loads the required classes.
  $batchJobService = $user->GetService('BatchJobService', ADWORDS_VERSION);

  // Create selector.
  $selector = new Selector();
  $selector->fields = array('Id', 'DownloadUrl', 'ProcessingErrors', 'ProgressStats', 'Status');

  // Create predicates.
  $selector->predicates[] = new Predicate('Id', 'EQUALS', array($batchJobId));
  
  // Create paging controls.
  $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);

  // Make the get request.
  $page = $batchJobService->get($selector);

  // Process results

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