Create a Plan for a Depot
Here we will be showing how to use the Depot List and the Plans Create endpoints to get your depots' IDs and create a Plan for a Depot.
- JS Web
- Node
- Python
- curl
// Set the API key
const apiKey = '<your-api-key>'
// Set the authorization header
const headers = new Headers()
headers.append('Authorization', `Basic ${btoa(`${apiKey}:`)}`)
async function createPlanWithDepot() {
let depotsResponse = await fetch(
'https://api.getcircuit.com/public/v0.2b/depots',
{
method: 'GET',
headers: headers,
},
)
// The response will be similar to the following:
// {
// "depots": [
// {
// "id": "depots/abcd1234",
// "name": "something"
// },
// ...
// ],
// "nextPageToken": null
// }
let depotsList = await depotsResponse.json()
console.log(depotsList)
// Get the first of the depots endpoint (this is an example, you can choose
// any other depot, just check their name to know what their ID is
// beforehand)
const depotId = depotsList.depots[0].id
const headersPost = new Headers(headers)
headersPost.append('Content-Type', 'application/json')
// Now use the returned ID in the plan request
const planData = {
title: 'Test',
starts: {
day: 31,
month: 5,
year: 2023,
},
depot: depotId,
}
// Now create the plan
let planResponse = await fetch(
'https://api.getcircuit.com/public/v0.2b/plans',
{
method: 'POST',
headers: headersPost,
body: JSON.stringify(planData),
},
)
// This will return a response similar to the following:
// {
// "id": "plans/FQ95Ex714KYeojkeIm77",
// "title": "Test",
// "starts": {
// "day": 31,
// "month": 5,
// "year": 2023
// },
// "depot": "depots/abcd1234",
// ...
// }
let plan = await planResponse.json()
console.log(plan)
}
// We are using the axios library here to make requests from Node
const axios = require('axios')
// Set the API key
const apiKey = '<your-api-key>'
async function createPlanWithDepot() {
// Retrieve a list of existing depots
let depotsResponse = await axios.get(
'https://api.getcircuit.com/public/v0.2b/depots',
{
auth: {
username: apiKey,
},
},
)
// The response will be similar to the following:
// {
// "depots": [
// {
// "id": "depots/abcd1234",
// "name": "something"
// },
// ...
// ],
// "nextPageToken": null
// }
console.log(depotsResponse.data)
// Get the ID of the first depot (this is an example, you can choose any other depot,
// just check their name what their ID is beforehand)
const depotId = depotsResponse.data.depots[0].id
// Now use the returned ID in the plan request
const planData = {
title: 'Test',
starts: {
day: 31,
month: 5,
year: 2023,
},
depot: depotId,
}
// Now create the plan
let planResponse = await axios.post(
'https://api.getcircuit.com/public/v0.2b/plans',
planData,
{
auth: {
username: apiKey,
},
},
)
// This will return a response similar to the following:
// {
// "id": "plans/FQ95Ex714KYeojkeIm77",
// "title": "Test",
// "starts": {
// "day": 31,
// "month": 5,
// "year": 2023
// },
// "depot": "depots/abcd1234",
// ...
// }
console.log(planResponse.data)
}
# Using requests to make a request to the server
import requests
from requests.auth import HTTPBasicAuth
apiKey = "<your-api-key>"
# Retrieve a list of existing depots
depotsResponse = requests.get(
"https://api.getcircuit.com/public/v0.2b/depots", auth=HTTPBasicAuth(apiKey, "")
)
# The response will be similar to the following:
# {
# "depots": [
# {
# "id": "depots/abcd1234",
# ...
# },
# ...
# ],
# "nextPageToken": null
# }
print(depotsResponse.json())
# Get the ID of the first depot (this is an example, you can choose any other depot,
# just check their name to know the ID beforehand)
depotId = depotsResponse.json()["depots"][0]["id"]
# Now use the returned ID in the plan request
planData = {
"title": "Test",
"starts": {"day": 31, "month": 5, "year": 2023},
"depot": depotId,
}
# Now create the plan
planResponse = requests.post(
"https://api.getcircuit.com/public/v0.2b/plans",
json=planData,
auth=HTTPBasicAuth(apiKey, ""),
)
# This will return a response similar to the following:
# {
# "id": "plans/FQ95Ex714KYeojkeIm77",
# "title": "Test",
# "starts": {
# "day": 31,
# "month": 5,
# "year": 2023
# },
# "depot": "depots/abcd1234",
# ...
# }
print(planResponse.json())
# First, retrieve a list of existing depots
# Replace <your-api-key> with your actual API key
curl https://api.getcircuit.com/public/v0.2b/depots -u <your-api-key>:
# This will return a response similar to the following:
# {
# "depots": [
# {
# "id": "depots/abcd1234",
# "name": "something"
# },
# ...
# ],
# "nextPageToken": null
# }
# Retrieve the ID of the first depot from the response
# Now, create a plan for a specific day using any of the depots IDs
# Again, replace <your-api-key> and <depot-id> with your actual API key and the
# depot ID, respectively
curl https://api.getcircuit.com/public/v0.2b/plans \
-d '{"title": "Test", "starts": {"day":31, "month": 5, "year": 2023}, "depot": "<depot-id>"}' \
-H 'Content-Type: application/json' \
-u <your-api-key>:
# This will return a response similar to the following:
# {
# "id": "plans/FQ95Ex714KYeojkeIm77",
# "title": "Test",
# "starts": {
# "day": 31,
# "month": 5,
# "year": 2023
# },
# "depot": "depots/abcd1234",
# ...
# }