POST /api/v1/routing

Creates a new Route model. A route model is a group of users and stops that needs to be routed. Each created route model is independent of other route models. Ideal usage is to create a route model for a particular day or particular time frame then use the PUT endpoint to add or update Stops or Users.

Request body

The request body should be in raw format and should include the following parameters:

{
  "settings": {
    "startTime": "2024-03-20T22:55:02.573Z",
    "endTime": "2024-03-24T07:55:02.573Z",
    "startLocation": {
      "latitude": -33.8706672,
      "longitude": 151.192487
    },
    "endLocation": {
      "latitude": -33.8706672,
      "longitude": 151.192487
    }
  },
  "stops": [
    {
      "sourceReference": "12331A",
      "quantities": [
        1
      ],
      "durationMinutes": 15,
      "name": "ABC Stop",
      "location": {
       "latitude": -33.8706672,
       "longitude": 151.192487
      },
	"assignedPublicUserId": "608b34bb-8b9a-4f0a-9184-414fde9ff5f7",
    },
     {
      "sourceReference": "12331B",
      "quantities": [
        1
      ],
      "durationMinutes": 15,
      "name": "ABC Stop2",
      "location": {
        "latitude": -33.8743446,
        "longitude": 151.2131667
      }
    }
  ],
  "users": [
    {
      "publicUserId": "608b34bb-8b9a-4f0a-9184-414fde9ff5f7",
      "vehicleCapacities": [
        30
      ],
      "startLocation": {
        "latitude": -33.8743446,
        "longitude": 151.2131667
      },
      "endLocation": {
        "latitude": -33.8706672,
        "longitude": 151.192487
      }
    }
  ]
}

  1. settings (Object): Configuration settings for the route.
    • startTime (Date Time): Start time of each of the users. If you want to have a different start time for each user. You can set it on the User level.
    • endTime (Date Time): End time of each of the users. If you want to have a different end time for each user. You can set it on the User level.
    • startLocation (Object): The starting location of the route. Start location of each of the users. If you want to have a different start location for each user. You can set it on the User level.
      • latitude (Number): The latitude coordinate of the starting location. Start location of each of the users. If you want to have a different start location for each user. You can set it on the User level.
      • longitude (Number): The longitude coordinate of the starting location.
      • endLocation (Object): The ending location of the route. End location of each of the users. If you want to have a different start location for each user. You can set it on the User level.
        • latitude (Number): The latitude coordinate of the ending location.
        • longitude (Number): The longitude coordinate of the ending location.
      • deleteModelAfter (Date time): The time the route model will be automatically deleted. By default will be set to a day after the model was created.
  2. stops (Array): List of stops along the route.
    • sourceReference (String): Unique identifier/reference for the stop.
    • quantities (Array of integer): Quantities associated with the stop.
    • assignedPublicUserId(string): The unique user identifier of a user. This will lock or assign the stop to a user.
    • durationMinutes (Integer): The duration of the stop in minutes. Is the amount of time the driver would stay on the stop.
    • name (String): Name or label for the stop.
    • location (Object): Geographic location of the stop.
      • latitude (Number): The latitude coordinate of the stop.
      • longitude (Number): The longitude coordinate of the stop.
  3. users (Array): List of users (team members or drivers) associated with the route.
    • publicUserId (String): Public identifier for the user.
    • vehicleCapacities (Array): Capacities associated with the user’s vehicle.
    • startLocation (Object): Starting location for the user’s route.
      • latitude (Number): The latitude coordinate of the starting location.
      • longitude (Number): The longitude coordinate of the starting location.
    • endLocation (Object): Ending location for the user’s route.
      • latitude (Number): The latitude coordinate of the ending location.
      • longitude (Number): The longitude coordinate of the ending location.

These fields provide detailed information necessary for creating and optimizing routes, including time constraints, locations, stops, and user details

Sample code

C#
Java
NodeJS
PHP
Python
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace RoutingApiClient
{
    class Program
    {
        static async Task Main(string[] args)
        {
            // Replace 'YOUR_API_KEY' with your actual API key
            string apiKey = "Your_BearerToken_Here";

            // Sample request body
            string requestBody = @"
            {
              ""settings"": {
                ""startTime"": ""2024-03-20T22:55:02.573Z"",
                ""endTime"": ""2024-03-24T07:55:02.573Z"",
                ""startLocation"": {
                  ""latitude"": -33.8706672,
                  ""longitude"": 151.192487
                },
                ""endLocation"": {
                  ""latitude"": -33.8706672,
                  ""longitude"": 151.192487
                },
                ""deleteModelAfter"": ""2024-03-25T07:55:02.573Z""
              },
              ""stops"": [
                {
                  ""sourceReference"": ""12331A"",
                  ""quantities"": [
                    1
                  ],
                  ""durationMinutes"": 15,
                  ""name"": ""ABC Stop"",
                  ""location"": {
                    ""latitude"": -33.8743446,
                    ""longitude"": 151.2131667
                  }
                }
              ],
              ""users"": [
                {
                  ""publicUserId"": ""608b34bb-8b9a-4f0a-9184-414fde9ff5f7"",
                  ""vehicleCapacities"": [
                    30
                  ],
                  ""startLocation"": {
                    ""latitude"": -33.8743446,
                    ""longitude"": 151.2131667
                  },
                  ""endLocation"": {
                    ""latitude"": -33.8706672,
                    ""longitude"": 151.192487
                  }
                }
              ]
            }";

            // API endpoint
            string apiUrl = "https://api.locate2u.com/api/routes";

            // Create HttpClient instance
            using (HttpClient client = new HttpClient())
            {
                // Add authorization header
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", apiKey);

                // Create HttpContent from request body
                HttpContent content = new StringContent(requestBody, Encoding.UTF8, "application/json");

                // Send POST request
                HttpResponseMessage response = await client.PostAsync(apiUrl, content);

                // Check if request was successful
                if (response.IsSuccessStatusCode)
                {
                    // Read response content
                    string responseContent = await response.Content.ReadAsStringAsync();
                    Console.WriteLine("Route created successfully:");
                    Console.WriteLine(responseContent);
                }
                else
                {
                    Console.WriteLine("Error creating route. Status code: " + response.StatusCode);
                }
            }
        }
    }
}

Response

Sample response

Reponse
Http 200
SaveRoutingModelResponse Object
Sample Response:
{
  "routeModelId": "34652-route-2024032105133057"
}

Http 422
Array of ErrorResponse Object