If you don’t have access to development resources, you can integrate your existing tech stack with Circuit’s API and import unassigned stops automatically by creating an integration using Zapier. First, set up a Zapier account, and then follow the process outlined below.
In the example below, we will imagine that we are an online retailer using Zapier to integrate with Circuit’s API to import new orders from our online store automatically. These orders are stored in a Google spreadsheet.
The process, once set up successfully, will work like this...
Online shop > Orders go into Google spreadsheet > Zapier integration automatically sends data to > Circuit’s API, which then sends data > into your Circuit for Teams unassigned stops list.
How to create a Zapier integration
Create a Zap
Log in to your Zapier account
Under Start from Scratch, click > Zap to create a new Zap
On your new Zap go to > Trigger
In this example, the Trigger is the Google spreadsheet that is populated with orders that we want to import into Circuit as unassigned stops. We recommend using Circuit’s example spreadsheet template.
Set up a Trigger
Click > Trigger and then select Google Sheets
Next, add your Trigger event
Click > Trigger event > and select the event ‘New or Updated Spreadsheet Row’
In this example, by choosing this trigger event it means that every time a new order is added to the spreadsheet, this action will automatically trigger the Zap.
Click > Account, select the account you want to use, and then click > Continue
Configure your Trigger
Next, click > spreadsheet and from the list select the spreadsheet you wish to use
Make sure that your spreadsheet does not contain any coloured cells or additional notes, only the information required
Click > Worksheet and select the worksheet/tab from the selected spreadsheet you wish to use
Click > Trigger column and select the column in your spreadsheet that you want the zap to be triggered when new data is added to that column
We recommend using Address Line 1 as a trigger column because this is a required field for all stops
Next, click > Continue
Test your Trigger
Click > Test trigger
This will import the data from your spreadsheet
Select one row of data to use for the test, and then click > Continue with selected record
In the pop-up box that appears, search ‘code’ and select the code option
With your App selected as > Code by Zapier
Next, set up your Action event, click the drop-down and select > Run Javascript, then click > Continue
Run Javascript
Next, you will see a box with code in it, and you will need to generate an API Key from your CFT a/c
To generate an API Key go to your Circuit for Teams account > Settings > Integrations > API
Click > Generate new key > click Reveal the key and click Copy
Return to your Zapier a/c and in the Input Data field write apiKey and paste the API Key into the text box next to that
Next, you need to add your value sets
Click > Add value set
In the left column, add Circuit’s API values
In the right column, add your spreadsheet values
You can find all the available API values that you can import here you can import all or any of the fields from that list.
Add value sets until you have mapped all API fields to the spreadsheet fields that you wish to import
Next, click into the Code box and delete any text so that the box is empty
Next, copy and paste the code in the blue box below into the empty Code box in Zapier
Copy this code
const timing = () => {
let timingObject = {};
if(inputData.earliestArrivalTime) {
const earliestTime = inputData.earliestArrivalTime.split(":")
timingObject['earliestAttemptTime'] = {
hour: parseInt(earliestTime[0]),
minute: parseInt(earliestTime[1])
}
}
if(inputData.latestArrivalTime) {
const latestTime = inputData.latestArrivalTime.split(":")
timingObject['latestAttemptTime'] = {
hour: parseInt(latestTime[0]),
minute: parseInt(latestTime[1])
}
}
if(inputData.estimatedAttemptDuration) {
timingObject['estimatedAttemptDuration'] = parseInt(inputData.estimatedAttemptDuration)
}
return timingObject
}
const getArray = (input) => {
if (input) {
return input.split(",");
}
return undefined;
}
const stop = {
address: {
addressName: inputData.addressName,
addressLineOne: inputData.addressLineOne,
addressLineTwo: inputData.addressLineTwo,
city: inputData.city,
state: inputData.state,
zip: inputData.zip,
country: inputData.country,
latitude: parseInt(inputData.latitude),
longitude: parseInt(inputData.longitude),
},
depot: inputData.depot,
timing: timing(),
recipient: {
externalId: inputData.recipientExternalId,
email: inputData.recipientEmail,
name: inputData.recipientName,
phone: inputData.recipientPhone,
},
orderInfo: {
products: getArray(inputData.orderInfoProducts),
sellerOrderId: inputData.orderInfoSellerOrderId,
sellerName: inputData.orderInfoSellerName,
sellerWebsite: inputData.orderInfoSellerWebsite,
},
allowedDrivers: getArray(inputData.allowedDrivers),
activity: inputData.typeOfStop,
optimizationOrder: inputData.optimizationOrder,
packageCount: parseInt(inputData.packageCount),
notes: inputData.notes,
circuitClientId: inputData.circuitClientId,
barcodes: getArray(inputData.barcodes)
}
const res = await fetch (`https://api.getcircuit.com/public/v0.2b/unassignedStops`, {
method: 'post',
headers: {
'Content-Type': 'application/json',
'Authorization' : `Bearer ${inputData.apiKey}`
},
body: JSON.stringify(stop)
})
return res.json()
Once you have pasted that code into the box, click > Continue
Next, you can test that your Zap has been set up correctly by clicking > Test Zap
This will test your Zap using the row of data from your spreadsheet that you selected eg Address Line 1 in this example
If your Zap is set up correctly, this test should be successful and pull that test row of data into Circuit for Teams
You can check this by going to Circuit for Teams > Unassigned stops to see if your test row has been imported (this may take a few minutes)
If your test has been successful, then click > Publish to set your Zap live
Read next...
Find the Webhook API technical documentation or ask a technical question about integrating with the API using Live Chat on this page > developer.team.getcircuit.com
Got a question?
Contact your account manager, start a live chat, or email [email protected]