Skip to main content

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​

NameTypeRequiredDescriptionDefault
vehicle_idintegerYesID of the vehicle performing this leg—
scheduled_start_timedatetimeYesScheduled start time for the leg—
scheduled_end_timedatetimeYesScheduled end time for the leg—

Optional Information​

NameTypeRequiredDescriptionDefault
trip_idintegerNoID of the cargo trip this leg is part of—
operator_trip_idintegerNoID of the operator trip this leg is part of—
statusstringNoCurrent status of the legCreated

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"
}
FieldTypeDescription
leg_idintegerUnique identifier for the newly created leg
vehicle_idintegerID of the vehicle performing this leg
trip_idintegerID of the cargo trip this leg is part of
operator_trip_idintegerID of the operator trip this leg is part of
scheduled_start_timedatetimeScheduled start time for the leg
scheduled_end_timedatetimeScheduled end time for the leg
statusstringCurrent 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"
}
FieldTypeDescription
successbooleanAlways false on error
error_codestringMachine-readable error identifier
messagestringHuman-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.