Creating a route

The first step in setting up a route is to create the route itself. To do this you need a Route Scheme, a vehicle, a driver, a vehicle trailer, and a waste station location. You do not need to know anything about them (we'll find what we need with the API), you just need to make sure they exist.

The endpoint to create a route can be found here , but before we can call it we need to get some information.

Getting the required info

The first thing we need is a project ID. If you have completed the Quickstart Guide you know how to get the ID.

import requests

url = "http://platform-api.wastehero.io/api/v3/project/"

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

response = requests.get(url, headers=headers)

print(response.text)

You should be getting a list of your projects. Find the project you want to create a route for and save the ID somewhere you can find it.

📘

Automation

You may have noticed, that in this guide we manually write the IDs for the drivers/vehicles/containers etc.
It is of course possible to write a program that does all the calls and adds the correct values, but this would require some filtering, which would differ from project to project.
For any purpose other than this guide, we recommend doing all the filtering in code.

To get the Vehicle id , Driver id , Vehicle trailer id and Route scheme id , is the same as getting the Projects id with only the URL being different. you can use the above code, and replace line 3 with one of the following lines:

# vehicle_id
url = "http://platform-api.wastehero.io/api/v3/vehicle/"

# driver_id
url = "http://platform-api.wastehero.io/api/v3/driver/"

# trailer_id
url = "http://platform-api.wastehero.io/api/v3/vehicle_trailer/"

# route_scheme_id
url = "http://platform-api.wastehero.io/api/v3/route_scheme/"

Building the request body

Now that we have the needed information we are ready to create the route. First, we need to create the request body. The body is a JSON as with the IDs and a date, as shown below.

{
  "project_id": "UHJvamVjdCBJRCBnb2VzIGhlcmU=",
  "vehicle_id": "VGhpcyBpcyB5b3VyIFZlaGljbGUgaWQ=",
  "driver_id": "UHV0IHlvdXIgZGlydmVyIGlkIGhlcmU=",
	"vehicle_trailer_id": "VmVoaWNsZSB0cmFpbGVyIElE",
  "route_scheme_id": "Um91dGUgc2NoZW1lIElE",
  "scheduled_date": 2022-09-01
}

🚧

All keys are example keys

The keys/IDs in these code examples are not real values (and wouldn't work with your API key even if they were). Make sure you replace them all with the real values for your project.

Insert the IDs you found in the previous step into the JSON, and write the date you want to schedule the route for as "schedule_date". Now it's just a matter of making a POST request with the request body to the route's endpoint, and the route should be created.

import requests

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

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

body = {
    "project_id": "UHJvamVjdCBJRCBnb2VzIGhlcmU=",
    "vehicle_id": "VGhpcyBpcyB5b3VyIFZlaGljbGUgaWQ=",
    "driver_id": "UHV0IHlvdXIgZGlydmVyIGlkIGhlcmU=",
    "vehicle_trailer_id": "VmVoaWNsZSB0cmFpbGVyIElE",
    "route_scheme_id": "Um91dGUgc2NoZW1lIElE",
    "scheduled_date": 2022-09-01
}

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

print(response.text)

If the route is created, you should get information of the created route back, and the route will be visible on the platform.


What’s Next

Now that you have a route, let's add some stops to it.