Adding stops to a route

In order to add stops to a route, you of course need a route, but also at least one container or ticket in your system. In this guide, we'll see how to add both a container and a ticket as a stop to a route.

Adding container stop

To add a container to a route, you need a container and to know its container ID. This is an ID that you (or someone on your team) chose when the container was created, and is unique in the project. You can find the container ID on the platform (Asset Management -> Containers) or use Get Containers. Both will show you all available containers and their ID.

Now all you need is the route ID for the route you want to add the stop to. If you just created the route, the ID should be in the response JSON (as "id"). Otherwise, Get Routes will give you all available routes.

import requests

route_id = "WW91ciBjaG9zZW4gUm91dGUgSUQ="
container_id = "Container_1"

url = "http://platform-api.wastehero.io/api/v3/route/" + route_id + "/add_stop"

headers = {
    "Accept": "application/json",
    "X-API-Key": "YOUR-API-KEY-HERE"
}

payload={
	"container_ids": [container_id]
}

response = requests.put(url, headers=headers, json=payload)

print(response.text)

If the container has not already been added to the route, you should get a list of all stops back.

Adding ticket stop

Adding a ticket to a route is almost the same as adding a container. You need the route ID as before and a ticket ID. If you do not have any tickets, you can learn how to create one HERE. Otherwise Get Tickets will give you a list of available tickets.

Now that you have both IDs, you can use the above code, replacing the keyword "container_ids" with "ticket_ids" and you are good to go.

import requests

route_id = "WW91ciBjaG9zZW4gUm91dGUgSUQ="
ticket_id = "VGlja2V0IElEIGhlcmU="

url = "http://platform-api.wastehero.io/api/v3/route/" + route_id + "/add_stop"

headers = {
    "Accept": "application/json",
    "X-API-Key": "YOUR-API-KEY-HERE"
}

body={
	"ticket_ids": [ticket_id]
}

response = requests.put(url, headers=headers, data=body)

print(response.text)

Multiple stops

You may have noticed that the container and ticket ID was added to the body as a list. This is because it is possible to add several stops at the same time. It is even possible to add ticket and container stops at the same time. Simply add a list of container IDs as "container_ids" and a list of ticket IDs as "ticket_ids" and let the API handle the rest.


What’s Next

Now we have a route with some stops. Lets see how we get the information about the route.