Skip to main content
Version: v0.2b

Create and delete Stops from a live Plan

Here we will be using the Create Live Stop, the Delete Live Stop, the Re-Optimize Plan, and the Save Plan endpoints to create and delete a Stop from a Plan that was already optimized, and therefore not editable via the Create Stop and Delete Stop endpoints.

The Save Plan will be called instead of Re-Distribute to make sure the plan won't be distributed. We can call the Distribute endpoint in the end if we want to only distribute it.

# We create the stop using the liveCreate method
curl https://api.getcircuit.com/public/v0.2b/plans/KBoYtDxO3FMh7zJkWdU3/stops:liveCreate \
-X POST \
-H 'Content-Type: application/json' \
-d '{"address": {"addressLineOne": "Some valid address"}}' \
-u <your-api-key>:


# We delete the stop we created before
# Note that we can do multiple requests before applying the changes through
# reoptimize and redistribute/save. All changes will be applied at once.
# (we are considering a stop with the id plans/KBoYtDxO3FMh7zJkWdU3/stops/vgsTiQi85ueWRs1JnXx7)
curl https://api.getcircuit.com/public/v0.2b/plans/KBoYtDxO3FMh7zJkWdU3/stops/vgsTiQi85ueWRs1JnXx7:liveDelete \
-X POST \
-u <your-api-key>:

# Now we must use re-optimize and re-distribute to apply the changes to the plan,
# even in this case where we deleted our previously created stop.
curl https://api.getcircuit.com/public/v0.2b/plans/KBoYtDxO3FMh7zJkWdU3:reoptimize \
-X POST \
-H 'Content-Type: application/json' \
-d '{}' \
-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 finally we can save this plan's changes
curl https://api.getcircuit.com/public/v0.2b/plans/KBoYtDxO3FMh7zJkWdU3:save \
-X POST \
-u <your-api-key>: