Skip to main content
Version: v0.2b

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.

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