Create Legs
Creating Legs
Create a leg as part of route planning. Legs are created by the contract owner to plan the route for a trip. The same leg is used for both the operator and rider contracts, tying the operator to the rider. When all legs are created, the corresponding rider or operator trip is created.
📚 Full API Documentation: For all endpoints, see https://api.opteverything.com/docs
Prerequisites​
- You have created a bid (see Bid Creation Guide)
- You have your authentication token
- You have a vehicle ID
Step 1: Create a Leg​
Endpoint​
POST /leg/legs
Required Information​
Name | Type | Required | Description | Default |
---|---|---|---|---|
vehicle_id | integer | Yes | ID of the vehicle performing this leg | — |
scheduled_start_time | datetime | Yes | Scheduled start time for the leg | — |
scheduled_end_time | datetime | Yes | Scheduled end time for the leg | — |
Optional Information​
Name | Type | Required | Description | Default |
---|---|---|---|---|
trip_id | integer | No | ID of the cargo trip this leg is part of | — |
operator_trip_id | integer | No | ID of the operator trip this leg is part of | — |
status | string | No | Current status of the leg | Created |
Example Request​
curl -X POST "https://api.opteverything.com/leg/legs" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <YOUR_TOKEN>" \
-d '{
"vehicle_id": 123,
"trip_id": 456,
"operator_trip_id": 789,
"scheduled_start_time": "2024-06-01T10:00:00Z",
"scheduled_end_time": "2024-06-01T11:00:00Z",
"status": "Created"
}'
Responses​
Success (201 Created)​
Status Code: 201 Created
{
"leg_id": 0,
"vehicle_id": 0,
"trip_id": 0,
"operator_trip_id": 0,
"scheduled_start_time": "2024-07-29T12:00:00Z",
"scheduled_end_time": "2024-07-29T13:00:00Z",
"status": "Created"
}
Field | Type | Description |
---|---|---|
leg_id | integer | Unique identifier for the newly created leg |
vehicle_id | integer | ID of the vehicle performing this leg |
trip_id | integer | ID of the cargo trip this leg is part of |
operator_trip_id | integer | ID of the operator trip this leg is part of |
scheduled_start_time | datetime | Scheduled start time for the leg |
scheduled_end_time | datetime | Scheduled end time for the leg |
status | string | Current status of the leg |
Error (400 Bad Request)​
Status Code: 400 Bad Request
{
"success": false,
"error_code": "INVALID_VEHICLE_ID",
"message": "The vehicle_id provided does not exist"
}
Field | Type | Description |
---|---|---|
success | boolean | Always false on error |
error_code | string | Machine-readable error identifier |
message | string | Human-readable error explanation |
Leg Details​
Leg Status​
- Created: Leg is scheduled/created and not yet assigned
- Assigned: Leg has been assigned to an operator/vehicle
- Started: Leg is currently in progress
- Completed: Leg has been completed
Leg Information​
- vehicle_id: The vehicle assigned to perform this leg
- trip_id: The cargo trip this leg belongs to (if applicable)
- operator_trip_id: The operator trip this leg belongs to (if applicable)
- scheduled_start_time: When the leg is scheduled to begin
- scheduled_end_time: When the leg is scheduled to end
Validation Rules​
Time Validation​
- scheduled_end_time must be after scheduled_start_time
- Both times should be in the future when creating the leg
- Times should be timezone-aware (UTC recommended)
Vehicle Assignment​
- vehicle_id must reference a valid vehicle in the system
- Vehicle must be available for the scheduled time period
Next Steps​
Continue to the next guide: Rider/Operator Trip Creation
Or see the full API documentation.