Cancel an Asynchronous Job
/r-scripts/v2/jobs/{jobId}/cancel
Request
-
jobId(required): string
The id of the asynchronous job
There's no request body for this operation.
Back to TopResponse
- application/json
200 Response
400 Response
401 Response
404 Response
500 Response
Examples
An asynchronous job runs in the background after it is submitted. If you need to stop
a job before it finishes, send a cancellation request using the job ID returned in
the Location header. You can then check the job status and retrieve
the result to confirm that the job was cancelled. The following steps show this
process.
Cancel a running asynchronous job by following these steps:
- Submit the job with
asyncFlagset totrue. - Use the job ID returned in the Location header to send a cancellation request.
- Check the job status.
- Fetch the job result.
Step 1: Submit an asynchronous job
This example submits the sleep_33mins function as an asynchronous
job.
curl -i -k -X POST \
--header "Authorization: Bearer ${token}" \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
-d '{
"comments": "long running job that sleeps 33mins",
"asyncFlag": true
}' \
"<oml-cloud-service-location-url>/oml/api/r-scripts/v2/do-eval/sleep_33mins"
The response includes HTTP status 201 Created and a Location header containing the job ID.
HTTP/2 201 Created
server: nginx/1.14.1
date: Thu, 23 Jul 2026 15:46:25 GMT
content-length: 0
strict-transport-security: max-age=31536000;includeSubDomains
x-content-type-options: nosniff
set-cookie: JSESSIONID=node0a2ukgrg0zetn34usmt4qdu7p16.node0; Path=/oml; Secure; HttpOnly
expires: Thu, 01 Jan 1970 00:00:00 GMT
location: https://<oml-cloud-service-location-url>/oml/api/r-scripts/v2/jobs/<job_id>
Step 2: Cancel the job
Wait for 10 seconds, then send a POST request to cancel the endpoint. The request has no body.
sleep 10
curl -i -k -X POST \
--header "Authorization: Bearer ${token}" \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
"<oml-cloud-service-location-url>/oml/api/r-scripts/v2/jobs/<job_id>/cancel"
The response indicates that the job was cancelled successfully.
{"result":"job cancelled successfully"}
Step 3: Check the job status
Call the job status endpoint with the job ID.
curl -i -k -X GET \
--header "Authorization: Bearer ${token}" \
--header 'Accept: application/json' \
"<oml-cloud-service-location-url>/oml/api/r-scripts/v2/jobs/<job_id>"
The response redirects to the job result URL with HTTP status 302 Found.
HTTP/2 302 Found
server: nginx/1.14.1
date: Thu, 23 Jul 2026 15:50:43 GMT
content-length: 0
strict-transport-security: max-age=31536000;includeSubDomains
x-content-type-options: nosniff
content-location: https://<oml-cloud-service-location-url>/oml/api/r-scripts/v2/jobs/<job_id>/result
Step 4: Fetch the job result
Send a request to the URL in the Content-Location header.
curl -i -k -X GET \
--header "Authorization: Bearer ${token}" \
--header 'Accept: application/json' \
"<oml-cloud-service-location-url>/oml/api/r-scripts/v2/jobs/<job_id>/result"
The result has HTTP status 200 OK and reports the job status as
CANCLLED.
{
"result": null,
"comments": "long running job that sleeps 33mins",
"status": "CANCELLED"
}