Skip to main content
POST
/
viajes
/
create_trip.php
Create Trip
curl --request POST \
  --url https://api.example.com/viajes/create_trip.php \
  --header 'Content-Type: <content-type>' \
  --data '
{
  "usuario_id": 123,
  "tipo_servicio": "<string>",
  "origen": {
    "direccion": "<string>",
    "latitud": 123,
    "longitud": 123,
    "referencia": "<string>"
  },
  "destino": {
    "direccion": "<string>",
    "latitud": 123,
    "longitud": 123,
    "referencia": "<string>"
  }
}
'
{
  "400": {},
  "404": {},
  "500": {},
  "success": true,
  "message": "<string>",
  "trip": {
    "id": 123,
    "usuario_id": 123,
    "conductor_id": 123,
    "tipo_servicio": "<string>",
    "estado": "<string>",
    "origen": {},
    "destino": {},
    "precio_estimado": 123,
    "distancia_km": 123,
    "duracion_estimada_minutos": 123,
    "fecha_solicitud": "<string>"
  }
}

Endpoint

POST /viajes/create_trip.php
Create a new trip request. This initiates the ride-hailing process and matches the passenger with available drivers.

Headers

Content-Type
string
required
Must be application/json

Request Body

usuario_id
integer
required
Passenger user ID making the request
tipo_servicio
string
required
Service type requestedPossible values:
  • motocicleta - Motorcycle taxi
  • auto - Car service
  • mototaxi - Motorcycle taxi with passenger cabin
origen
object
required
Trip origin location
destino
object
required
Trip destination location (same structure as origen)

Response

success
boolean
required
Trip creation success status
message
string
Success or error message
trip
object
Created trip object

Request Example

curl -X POST https://76.13.114.194/viajes/create_trip.php \
  -H "Content-Type: application/json" \
  -d '{
    "usuario_id": 456,
    "tipo_servicio": "motocicleta",
    "origen": {
      "direccion": "Carrera 15 #85-30, Bogotá",
      "latitud": 4.6814,
      "longitud": -74.0479,
      "referencia": "Frente al Centro Comercial"
    },
    "destino": {
      "direccion": "Calle 72 #10-20, Bogotá",
      "latitud": 4.6533,
      "longitud": -74.0602,
      "referencia": "Edificio de oficinas"
    }
  }'

Response Example

{
  "success": true,
  "message": "Viaje creado exitosamente",
  "trip": {
    "id": 789,
    "usuario_id": 456,
    "conductor_id": null,
    "tipo_servicio": "motocicleta",
    "estado": "pendiente",
    "origen": {
      "direccion": "Carrera 15 #85-30, Bogotá",
      "latitud": 4.6814,
      "longitud": -74.0479,
      "referencia": "Frente al Centro Comercial"
    },
    "destino": {
      "direccion": "Calle 72 #10-20, Bogotá",
      "latitud": 4.6533,
      "longitud": -74.0602,
      "referencia": "Edificio de oficinas"
    },
    "precio_estimado": 18500,
    "precio_final": null,
    "distancia_km": 4.2,
    "duracion_estimada_minutos": 15,
    "fecha_solicitud": "2024-03-15T14:30:00.000Z",
    "fecha_aceptacion": null,
    "fecha_inicio": null,
    "fecha_fin": null
  }
}

Trip Status Flow

After creation, a trip goes through the following states:
1

pendiente

Trip created, waiting for driver acceptance
2

aceptado

Driver accepted the trip
3

en_ruta

Driver is on the way to pick up passenger
4

en_curso

Passenger picked up, trip in progress
5

completado

Trip successfully completed
Alternatively, the trip can be cancelled at any point before completion.

Service Types

Motocicleta

Standard motorcycle taxi for quick trips

Auto

Car service for comfort and multiple passengers

Mototaxi

Motorcycle taxi with passenger cabin

Pricing

The estimated price is calculated based on:
  • Base fare: Starting price
  • Distance: Price per kilometer
  • Duration: Price per minute (peak hours)
  • Service type: Different rates for moto/auto
  • Demand: Dynamic pricing during high demand

Error Responses

400
Bad Request
Invalid request data or coordinates
404
Not Found
User not found
500
Internal Server Error
Server error during trip creation

Notes

After creating a trip, use the Trip Status endpoint to monitor the trip state and driver assignment.
Ensure the origin and destination coordinates are accurate. Invalid coordinates will result in failed trip requests.

See Also

Build docs developers (and LLMs) love