Skip to main content
Version: v0.2b

Optimize and distribute plan

Here we will be using the Plan Optimize and the Plan Distribute endpoints to optimize and distribute an already existing plan with stops to the drivers. We will also use the Get Operations endpoint to retrieve the status of the plan optimization. Read their descriptions to see all the available options.

# With the plan already created and stops imported, start the optimization (we
# are considering a plan with the id plans/KBoYtDxO3FMh7zJkWdU3 here):
curl https://api.getcircuit.com/public/v0.2b/plans/KBoYtDxO3FMh7zJkWdU3:optimize \
-X POST \
-u <your-api-key>:

# The response will return an operation object similar to the following:
# {
# "id": "operations/FQ95Ex714KYeojkeIm77",
# "done": false,
# "type": "plan_optimization",
# ...
# }
#
# Why an operation? Because the optimization can take a long while to finish, so
# we process it in an asynchronous manner.

# Now, with the returned ID, we can periodically call the GET operation endpoint
# to check it until the `done` field is `true`
curl https://api.getcircuit.com/public/v0.2b/operations/FQ95Ex714KYeojkeIm77 \
-u <your-api-key>:

# Now wait until the operation is done, which means it finished processing, and
# it might have had a successful result or an error one.
#
# The error one will have the `result.code` and `result.message` fields set,
# while the successful one will have the result fields, which include the
# skipped stops and the amount of optimized stops.

# Now if you want, you can distribute the optimized routes to your drivers:
curl https://api.getcircuit.com/public/v0.2b/plans/KBoYtDxO3FMh7zJkWdU3:distribute \
-X POST \
-u <your-api-key>: