Skip to content

Add BatchJobService support to beta client library. #145

Closed
@shakaran

Description

@shakaran

As far I read here:

https://developers.google.com/adwords/api/docs/reference/v201605/BatchJobService.BatchJob#status

"For versions newer than V201509, make a POST request to the uploadUrl and retrieve the "Location" header from the response as the url to upload operations."

Other SDKs seem have a class BatchJobUploadHelper for poll or POST the upload url.

$batch_job_service = $adWordsServices->get($session, 'BatchJobService', 'v201605', 'cm');

try
{
    /** @var BatchJobReturnValue $result */
    $result = $batch_job_service->mutate($operations);
}
catch(ApiException $e)
{
    echo $e->getMessage() . PHP_EOL;
}

if(!empty($result) && $result instanceof Google\AdsApi\AdWords\v201605\cm\BatchJobReturnValue)
{
    $batch_job = reset($result->getValue());

    // HERE IS NEEDED A POST request to $batch_job->getUploadUrl()
}
else 
{
    echo 'Result is empty or no valid';
}

$selector = new Selector();
$selector->setFields(['Status']);

$batch_jobs_page = $batch_job_service->get($selector);

var_dump($batch_jobs_page); // ALL ARE AWAITING_FILE status (BatchJobStatus::AWAITING_FILE)

if I make a direct curl POST request, I am getting a 411 error from google servers since content-length is required. For example:

curl -X POST -H 'Content-length:0' 'https://batch-job-upload-prod-1234.storage.googleapis.com/1234/1234.operations.xml?moreparams'

Even cheating the Content-length I don't get a valid response. So how should I get that the job pass to active? It would be nice a class and method like BatchJobUploadHelper::upload($batch_job)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions