Polling

If a task takes longer than the request timeout limit, the request is acknowledged by a 202 Accepted and treated as a background job.

You don't get the requested data directly, instead you get the URL of the background job in the Location header, which shows you the background job status.

{info} A far more efficient way to get the desired data are Webhooks.


Query job status

You need to check this URL periodically to check when the background job is finished.

When the background job is completed, a 200 OK is returned and the response body filled the resource_url to complete the next step. If not, a 202 Accepted will still be returned and the resource_url will remain empty.

Examples

Create a long running task

{primary.fa-paper-plane} Request

POST /variant/1/design HTTP/1.1

{success} Response

HTTP/1.1 202 Accepted
Location: https://api.smake.io/v2/jobs/1

The job is not finished.

{primary.fa-paper-plane} Request

GET /jobs/1 HTTP/1.1

{success} Response

HTTP/1.1 202 Accepted
Location: https://api.smake.io/v2/jobs/1

{
    "id": 1,
    "is_test": true,
    "resource_url": null,
    "state": "queued"
}

The job is finished.

{primary.fa-paper-plane} Request

GET /jobs/1 HTTP/1.1

{success} Response

HTTP/1.1 200 OK

{
    "id": 1,
    "is_test": true,
    "resource_url": "https://api.smake.io/v2/variant/2",
    "state": "finished"
}