Getting the status of the job via callback

Once a job is created, you need to know if the job failed, was completed successfully or if it is still processing.

By sending a callback url together with the job, you will be notified instantly when the job finished either with the status failed or completed.

If you want to receive a callback with every job status change (e.g. ready, processing in addition to failed or completed), set the flag notify_status to true.

The information received in your callback script has the same structure as the response in Send a job with a remote file.

POST /jobs HTTP/1.1
Host: https://api2.online-convert.com
X-Oc-Api-Key: <your API key here>
Content-Type: application/json
{
    "input": [{
        "type": "remote",
        "source": "https://static.online-convert.com/example-file/raster%20image/jpg/example_small.jpg"
    }],
    "conversion": [{
        "target": "png"
    }],
    "callback": "<put your callback url here>",
    "notify_status": false
}
curl -X POST \
  https://api2.online-convert.com/jobs \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'x-oc-api-key: <your API key here>' \
  -d '{
    "input": [{
        "type": "remote",
        "source": "https://cdn.online-convert.com/example-file/raster%20image/png/example_small.png"
    }],
    "conversion": [{
        "category": "image",
        "target": "png"
    }],
    "callback": "<put your callback url here>",
    "notify_status": false
}'

Example of a simple callback endpoint

Following, you can find a very simple callback example code in PHP.

It writes the content of the callback as a human readable array in a plain text file (setting the job's Id and Status as the filename) inside the script's directory.

This way, it will be easy for you to debug all of the possible status contents by simply setting "notify_status": true in your JSON API call.

<?php
$job        = file_get_contents('php://input');
$jobAsArray = json_decode($job, true);

if (empty($jobAsArray['id'])) {
    file_put_contents(
        'callback_errors.log',
        'Invalid callback received. Content: ' . var_export($job, true) . PHP_EOL,
        FILE_APPEND
    );

    exit;
}

$filename = sprintf('%s_%s.txt', $jobAsArray['id'], $jobAsArray['status']['code']);
file_put_contents($filename,  print_r($jobAsArray, true));

results matching ""

    No results matching ""