Run Orders via API¶
Use the following information to run an order using the Automation API.
Required parameters¶
| Required parameter | Description |
|---|---|
Token |
A valid session token generated by username/password authentication. |
Kitchen |
The kitchen where you want to run the order. |
Recipe |
The recipe for the order. |
Variation |
The variation for the order. |
Runtime overrides¶
Overrides for recipe and kitchen variables passed at the time of order execution.
| Required parameter | Description |
|---|---|
Order Schedule |
The start, recurrence, frequency, and expiration of an order. Determines the number of order runs. See schedule-setting in variations.json. |
Infrastructure |
The specific infrastructure used during running of an order run. For example, an s3 bucket, database schema, or container image tag. |
Date of Source Data |
Used for backfilling use cases when the newest code should be run against old data. Distinct from the start date of an order run. |
Alert Destination |
Where order run alerts should be sent. |
Examples of running orders via API¶
This example, shown in Bash and Python, runs an order and passes an optional runtime override.
Bash¶
#!/bin/bash
BASE_URL="https://cloud.datakitchen.io"
FORM_HEADER="Content-type: application/x-www-form-urlencoded"
JSON_HEADER"Content-type: application/json"
USERNAME="<USERNAME>"
PASSWORD="<PASSWORD>"
# Collect Token with curl command
TOKEN=`curl -f -s -X POST -d "username=$USERNAME&password=$PASSWORD" -H "$FORM_HEADER" "$BASE_URL/v2/login"`
# Status message
if [ "$?" != "0" ]
then
echo "Unable to login"
else
echo "Token received: ${TOKEN}"
fi
# Define Header with Token and Required Parameters
AUTH_HEADER="Authorization: Bearer $TOKEN"
KITCHEN="<KITCHEN_NAME>"
RECIPE="<RECIPE_NAME>"
VARIATION="<VARIATION_NAME>"
# Define optional Runtime Overrides
PARAMS='{"parameters":{"testvar":"override_value"}}'
# Curl command to Cook the Order
curl -f -s -X PUT -H "$JSON_HEADER" -H "$AUTH_HEADER" -d $PARAMS "$BASE_URL/v2/order/create/$KITCHEN/$RECIPE/$VARIATION"
# Status message
if [ "$?" != "0" ]
then
echo "Unable to create order run"
else
echo "Order run created successfully"
fi
Python¶
import requests
import os
import codecs
import json
# Gather Token
payload = {'username': os.environ['username'], 'password': os.environ['password']}
r = requests.post('https://cloud.datakitchen.io/v2/login', data = payload)
token=r.text
# Define required parameters
kitchen="your_kitchen"
recipe="your_recipe"
variation="your_variation"
# Define optional Runtime Overrides
overrides = {"variable1": override1, "value2": override2}
parameters = json.dumps({'parameters': overrides})
# Define put request pieces
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token }
url = 'https://cloud.datakitchen.io/v2/order/create/%s/%s/%s' % (kitchen, recipe, variation)
# Cook Order
r2 = requests.put(url, headers = headers, data=parameters)
print 'r2'
print r2.json()