Create a Plan with Drivers
Here we will be showing how to use the Drivers List and the Plans Create endpoints to get your drivers' IDs and create a Plan with Drivers.
- 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 createPlanWithDriver() {
let driversResponse = await fetch(
'https://api.getcircuit.com/public/v0.2b/drivers',
{
method: 'GET',
headers: headers,
},
)
// The response will be similar to the following:
// {
// "drivers": [
// {
// "id": "drivers/abcd1234",
// ...
// },
// ...
// ],
// "nextPageToken": null
// }
let driversList = await driversResponse.json()
console.log(driversList)
// Get the first of the drivers endpoint (this is an example, you can choose
// any other driver, just check their name and email to know what their ID is
// beforehand)
const driverId = driversList.drivers[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,
},
drivers: [driverId],
}
// 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
// },
// "drivers": [
// {
// "id": "drivers/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 createPlanWithDriver() {
// Retrieve a list of existing drivers
let driversResponse = await axios.get(
'https://api.getcircuit.com/public/v0.2b/drivers',
{
auth: {
username: apiKey,
},
},
)
// The response will be similar to the following:
// {
// "drivers": [
// {
// "id": "drivers/abcd1234",
// ...
// },
// ...
// ],
// "nextPageToken": null
// }
console.log(driversResponse.data)
// Get the ID of the first driver (this is an example, you can choose any other driver,
// just check their name and email to know what their ID is beforehand)
const driverId = driversResponse.data.drivers[0].id
// Now use the returned ID in the plan request
const planData = {
title: 'Test',
starts: {
day: 31,
month: 5,
year: 2023,
},
drivers: [driverId],
}
// 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
// },
// "drivers": [
// {
// "id": "drivers/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 drivers
driversResponse = requests.get(
"https://api.getcircuit.com/public/v0.2b/drivers", auth=HTTPBasicAuth(apiKey, "")
)
# The response will be similar to the following:
# {
# "drivers": [
# {
# "id": "drivers/abcd1234",
# ...
# },
# ...
# ],
# "nextPageToken": null
# }
print(driversResponse.json())
# Get the ID of the first driver (this is an example, you can choose any other driver,
# just check their name and email to know what their ID is beforehand)
driverId = driversResponse.json()["drivers"][0]["id"]
# Now use the returned ID in the plan request
planData = {
"title": "Test",
"starts": {"day": 31, "month": 5, "year": 2023},
"drivers": [driverId],
}
# 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
# },
# "drivers": [
# {
# "id": "drivers/abcd1234",
# ...
# }
# ],
# ...
# }
print(planResponse.json())
# First, retrieve a list of existing drivers
# Replace <your-api-key> with your actual API key
curl https://api.getcircuit.com/public/v0.2b/drivers -u <your-api-key>:
# This will return a response similar to the following:
# {
# "drivers": [
# {
# "id": "drivers/abcd1234",
# ...
# },
# ...
# ],
# "nextPageToken": null
# }
# Retrieve the ID of the first driver from the response
# Now, create a plan for a specific day using any of the drivers IDs
# Again, replace <your-api-key> and <driver-id> with your actual API key and the
# driver ID, respectively
curl https://api.getcircuit.com/public/v0.2b/plans \
-d '{"title": "Test", "starts": {"day":31, "month": 5, "year": 2023}, "drivers": ["<driver-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
# },
# "drivers": [
# {
# "id": "drivers/abcd1234",
# ...
# }
# ],
# ...
# }