Skip to content

Submit Orders via API

You can use the Automation API to start or schedule recipe orders.

Submit an order

To submit an order through the API, specify the kitchen, recipe, and variation.

Tip

You also can specify overrides for variables.

Use Bash

#!/bin/bash

TARGET_URL="https://cloud.datakitchen.io/v2/order/create/$KITCHEN/$RECIPE/$VARIATION"
JSON_HEADER="Content-type: application/json"
AUTH_HEADER="Authorization: Bearer $TOKEN"
OVERRIDES = '{"parameters": {"some key": "some value"}}'

RESULT = curl -f -s -X PUT -H "$JSON_HEADER" -H "$AUTH_HEADER" $TARGET_URL

Use Python

import requests
import json

overrides = {'some key': 'some value'}
parameters = json.dumps({'parameters': overrides})
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token}
url = 'https://cloud.datakitchen.io/v2/order/create/%s/%s/%s' % (kitchen, recipe, variation)
response = requests.put(url, headers=headers, data=parameters)
result = response.json()


# PYTHON AUTH FOLLOWS

payload = {username: os.environ[username], password: os.environ[password]}
   r = requests.post(https://cloud.datakitchen.io/v2/login', data=payload)
   token = r.text

headers = {content-type: application/json, authorization: bearer  + token}
   url = https://cloud.datakitchen.io/v2/order/create/%s/%s/%s' % (kitchen, recipe, variation)

Response characteristics

Successful order

On a successful order submission, the API will return a response code of 200. The JSON result will indicate the status of the request, the order ID, and applied variable overrides.

{
    "status": "success",
    "serving_hid": "f891ab00-ffcb-11e8-ad07-0242ac110002",
    "variable_overrides": {
        "some key": "some value"
    }
}

Unsuccessful order

If the order request has problems, the response will have a status code of 417 and there will be details in the JSON result.

For example, if you make an API call for a non-existent variation, the JSON will return as follows:

{
    "message": {
        "status": "failed",
        "error": {
            "message": "kitchen (test-kitchen),recipe (test-recipe),variation (missing-variation)",
            "detail": "unable to find the variation named missing-variation in the recipe test-recipe variations.json"
        }
    }
}