Example: Deleting an Image From the API

I recently helped a customer in a private conversation. They wanted to delete an image from the API using Python.

I would like to post the example code I sent them here in case any other users need it.

The code below will delete a single image via the REST API in Python (2.7).

For the code to work you must:

  • Replace the image_id variable with a real image ID
  • Replace the value of my_token with a real token value.
    import requests
    import json
    
    payload = {}
    image_id = 123
    my_token = '_ CHANGE THIS VALUE _'
    headers = {
        'content-type': 'application/json',
        'Authorization': my_token
    }
    
    url = "https://my.farm.bot/api/images/" + str(image_id)
    
    response = requests.delete(url, data=json.dumps(payload), headers=headers)
    
    print(response)