Skip to main content
Version: v0.2b

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.

// 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)
}