Creating a task
This API is designed for creating tasks related to contracts where the PTM module is enabled.
Base API Path:
/backend/public/api/task
|
Request address
To make a request, use the following URL format:
https://<server_address>/backend/public/api/task
|
API Access
API access is authenticated using HTTP Basic authentication. The username and password should be formatted as:
username_from_PILOT:password_from_PILOT
|
Example API request
https://demo:demo@tasks.pilot-gps.com/backend/public/api/task/create_universal
|
API Response format
The API response is standardized and has the following format:
{
"success": true, // TRUE - successful request, FALSE - error
"msg": "OK", // Error message, if any
"httpCode": 200, // Error code
"data": [], // Response data, if available
"et": 0, // Request execution time
"exceptionMsg": "Exception" // Exception message, if any
}
|
Status codes and error codes
-
200 — Successful request
-
400 — Missing required parameters
-
401 — Authorization error: Incorrect username or password
-
404 — API route not found
-
500 — Server error
How to create a task
Request method: POST
To create a task using the Universal template, you need to send parameters. The Universal template is automatically created in the system, while additional templates should be pre-configured in the PTM interface.
Parameters for a Universal template task
For a task with the Universal template, the following parameters are used:
1. external_id: External task identifier (string, default is NULL)
2. vehicle_plate: Vehicle license plate number (default is NULL). If the number does not exist in the system, it will be created as a rental vehicle
3. driver_name: Driver's full name (default is NULL). If not specified, the name from the vehicle_plate will be used. If the driver doesn't exist, they will be created as a rental driver
4. type_name: Task type (default is "Delivery"). If the type doesn't exist, it will be created
5. template_name: Task template name (default is "Universal"). If the template doesn't exist, it will be created
6. time_zone: Time zone offset from UTC (number, in minutes from UTC, default is NULL)
7. time_zone_name: Time zone name (string, default is NULL)
8. c_begin_time: Scheduled task start time (number — timestamp in seconds, default is current time)
9. c_return_time: Scheduled task end time (number, default is NULL)
10. route_name: Route name (string, default is NULL)
11. cargo: Cargo description (string, default is NULL)
12. temp_min: Minimum temperature (number, default is 2°C)
13. temp_max: Maximum temperature (number, default is 8°C)
14. description: Task description (string, default is NULL)
15. addresses_list (required): List of addresses or route points (strings with addresses or coordinates)
Route address parameters
Each route address may include additional parameters with suffixes that describe the route characteristics and geographical data:
1. addresses_list: List of addresses or route points (strings with addresses or coordinates)
2. addresses_list_lat: Array of latitudes for the route points
3. addresses_list_lng: Array of longitudes for the route points
4. addresses_list_date_point: Array of timestamps (in seconds) for the planned arrival times
5. addresses_list_date_point_to: Array of timestamps (in seconds) for the planned departure times (automatically calculated if not specified)
6. addresses_list_time_point: Array of loading/unloading times at the route points (in minutes)
7. addresses_list_redirect: Flag for redirecting the current address to the next
8. addresses_list_geofence_id: Geofence IDs for each route point
9. addresses_list_warehouse: Warehouse or object names for each route point
10. addresses_list_ticket: Array of unique order identifiers for each route point
11. addresses_list_phones: Contact phone numbers for each route point
12. addresses_list_schedule: Working schedule for each route point
13. addresses_list_vehicle_volume: Cargo volume in the vehicle
14. addresses_list_trailer_volume: Cargo volume in the trailer
15. addresses_list_action: Description of actions to perform at each route point
16. addresses_list_agent_id: Agent ID from the PILOT system, used for trash containers
Example request
fetch("https://tasks.pilot-gps.com/backend/public/api/task/create_universal", {
"headers": {
"Authorization": "Basic ZGVtbzpkZW1v", // base64 encoding "demo:demo"
"Content-Type": "application/json"
},
"method": "POST",
"body": JSON.stringify({
"external_id": "T-5677786754",
"vehicle_plate": "PT 125 AA 66",
"driver_name": null,
"type_name": "Delivery",
"template_name": "Universal",
"time_zone": -180,
"time_zone_name": "Europe/Moscow",
"c_begin_time": 1723233360,
"c_return_time": 1723238700,
"route_name": "My route",
"cargo": "Milk",
"temp_min": 2,
"temp_max": 6,
"description": "Test",
"addresses_list": [
"215, ul. Narodnogo Opolcheniya, Rostov-on-Don",
"47.227196,39.705228",
"Client 2"
],
"addresses_list_lat": [
47.234256,
47.227196,
47.216077
],
"addresses_list_lng": [
39.706467,
39.705228,
39.706928
],
"addresses_list_date_point": [
1723233360,
1723234800,
1723237800
],
"addresses_list_time_point": [
10,
20,
15
],
"addresses_list_rad_geo": [
50,
40,
30
]
})
});
|
Example response
{
"success": true,
"msg": "OK",
"httpCode": 200,
"data": {
"id": 12563
},
"et": 0.5612
}
|