How to Cancel a Job

The job cancel API allows you to cancel a job when the status is Pending or Running. In your job cancel request, use the returned job ID from your Media job.

Check the Job Status

Before you cancel a job, you can check the current job status to make sure it is Pending or Running.

Here is an example GET request using the Transcode API. You will need to replace the job_id with the value returned from your Media API request and update the URL with the Media API that you are using.

import os
import requests
 
# Add your API token as an environmental variable or hard coded value.
api_token = os.getenv("DOLBYIO_API_TOKEN", "your_token_here")

# Set DOLBYIO_JOB_ID as your environment variable.
job_id = os.environ['DOLBYIO_JOB_ID']
 
url = "https://api.dolby.com/media/transcode"
headers = {
    "Authorization": "Bearer {0}".format(api_token),
    "Content-Type": "application/json",
    "Accept": "application/json"
}
 
params = {
    "job_id": job_id
}
 
try:
    response = requests.get(url, params=params, headers=headers)
    response.raise_for_status()
except requests.exceptions.HTTPError as e:
    raise Exception(response.text)
print(response.json())
const axios = require("axios").default
 
// Add your API token as an environmental variable or hard coded value.  
const api_token = process.env.DOLBYIO_API_TOKEN || "your_token_here";  

// Set DOLBYIO_JOB_ID as your environment variable.
const job_id = process.env.DOLBYIO_JOB_ID;
 
const config = {
  method: "get",
  url: "https://api.dolby.com/media/transcode",
  headers: {
    "Authorization": `Bearer ${api_token}`,
    "Content-Type": "application/json",
    "Accept": "application/json"
  },
   
  params: {
    job_id: job_id,
  },
}
 
axios(config)
  .then(function(response) {
    console.log(JSON.stringify(response.data, null, 4))
  })
  .catch(function(error) {
    console.log(error)
  })
#!/bin/bash

# Add your API token as an environmental variable or hard coded value.
API_TOKEN=${DOLBYIO_API_TOKEN:-"your_token_here"}

curl -X GET "https://api.dolby.com/media/transcode?job_id=$DOLBYIO_JOB_ID" \
    --header "Authorization: Bearer $API_TOKEN" \
    
    # TODO: You must replace this value with the job ID returned from your Media API job.

Make a Job Cancel Request

To cancel your media job, you use the job ID that was returned when you started your media job.

import os
import requests
 
# Add your API token as an environmental variable or hard coded value.
api_token = os.getenv("DOLBYIO_API_TOKEN", "your_token_here")

# Set DOLBYIO_JOB_ID as your environment variable.
job_id = os.environ['DOLBYIO_JOB_ID']
   
query = {'job_id': job_id }
response = requests.post("https://api.dolby.com/media/jobs/cancel", params=query,
headers = {
    "Authorization": "Bearer {0}".format(api_token),
    "Content-Type": "application/json",
    "Accept": "application/json"
}, json={})
response.raise_for_status()
print(response.json())
const axios = require('axios').default;
 
// Add your API token as an environmental variable or hard coded value.  
const api_token = process.env.DOLBYIO_API_TOKEN || "your_token_here";  

// Set DOLBYIO_JOB_ID as your environment variable.
const job_id = process.env.DOLBYIO_JOB_ID;
  
const config = {
  method: 'post',
  url: 'https://api.dolby.com/media/jobs/cancel',
  params: {
    job_id: job_id
  },
  headers: {
    "Authorization": `Bearer ${api_token}`,
    "Content-Type": "application/json",
    "Accept": "application/json"
  },
  data: {}
};
  
axios(config)
  .then(function (response) {
    console.log(response.data);
  })
  .catch(function (error) {
    console.log(error);
  });
#!/bin/bash

# Add your API token as an environmental variable or hard coded value.
API_TOKEN=${DOLBYIO_API_TOKEN:-"your_token_here"}

curl -X POST "https://api.dolby.com/media/jobs/cancel?job_id=$DOLBYIO_JOB_ID" \
          --header "Authorization: Bearer $API_TOKEN" --header "Content-Type: application/json" -d '{}'
        # TODO: You must replace this value with the job ID returned from your Media API job.

Learn More