Skip to main content

Create Trip

Creating a Rider/Operator Trip

This endpoint creates a new trip, associating it with a contract and setting the initial leg. The status of the leg in the request will be set to Assigned if it has been assigned a cargo trip and an operator trip.

📚 Full API Documentation: For all endpoints, see https://api.opteverything.com/docs

Prerequisites​

Step 1: Create a Trip​

Endpoint​

POST /trip/trips

Description​

Create a trip after all legs are planned. Only one of the following should be provided:

  • contract_id (for a CargoTrip), or
  • ride_contract_id and operator_contract_id (for an OperatorTrip).

Required Information​

NameTypeRequiredDescriptionDefault
contract_idstringNoThe contract ID—
ride_contract_idstringNoThe ride contract ID—
operator_contract_idstringNoThe operator contract ID—
current_leg_idintegerNoThe current leg ID—

Example Request​

curl -X POST "https://api.opteverything.com/trip/trips" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <YOUR_TOKEN>" \
-d '{
"contract_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"ride_contract_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"operator_contract_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"current_leg_id": 0
}'

Responses​

Success (201 Created)​

Status Code: 201 Created

{
"trip_id": 0,
"owner_id": 0,
"contract_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"ride_contract_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"operator_contract_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"current_leg_id": 0
}
FieldTypeDescription
trip_idintegerUnique identifier for the newly created trip
owner_idintegerID of the user who owns the trip
contract_idstringThe contract ID
ride_contract_idstringThe ride contract ID
operator_contract_idstringThe operator contract ID
current_leg_idintegerThe current leg ID

Error (400 Bad Request)​

Status Code: 400 Bad Request

{
"success": false,
"error_code": "INVALID_LEG_IDS",
"message": "One or more leg IDs are invalid"
}
FieldTypeDescription
successbooleanAlways false on error
error_codestringMachine-readable error identifier
messagestringHuman-readable error explanation

Next Steps​

Continue to the next guide: User Event Creation

Or see the full API documentation.