For a list of model ids associated with your organization see 👉 here
JSON
Define your payload data.
This can be done directly in python or as a file passed in. If we define our JSON directly in python we need to convert the data to json using json.dumps
If your payload is defined directly in python make sure to use python syntax (ie JSON uses "true" but python uses "True")
Post Request
Make a post request by passing in your url, headers, and payload data if it was defined directly in python.
Python Response
Get the response as a JSON object which can then be used as python dictionary. We first check if the query was successful. This is because error messages are strings not JSONs.
Full Code
To run the code below, fill in the organization id, model id, authentication key, and file name.
#Or pass in a JSON file
payload = open('example.json', 'rb').read()
r = requests.post(url,headers=headers,data=payload)
#Check response status
if r.status_code == requests.codes.ok:
#Responses are returned as JSON
response = r.json()
#Can index on JSON object like a dictionary
response_data = response["data"]
else:
#Errors are returned as text
error = r.text
import requests
import json
#User Specific inputs
organization_id = ""
model_id = ""
authentication_key = ""
file_name = ""
#Headers
headers = {
"Content-Type": "application/json",
"x-corsali-organization-id" : organization_id,
"Authorization" : "Bearer {Authentication_Key}".format(Authentication_Key=authentication_key)
}
#URL
url = "https://api.corsali.com/predict/{Model_Id}".format(Model_Id = model_id)
#JSON
payload = open(file_name, 'rb').read()
#Post Request
r = requests.post(url,headers=headers,data=payload)
#Check response status
if r.status_code == requests.codes.ok:
#Responses are returned as JSON
response = r.json()
#Can index on JSON object like a dictionary
response_data = response["data"]
print(response_data)
else:
#Errors are returned as text
error = r.text
print(error)