Three lines

Uber

Developers

Code Samples

The purpose of this guide is to provide code samples in most commonly used programming languages. Namely

  • Python
  • PHP

The examples that we provided are for various possible HTTP methods as opposed to every endpoint that is offered in this product.

Python

GET : Get Guest Trip

import requests
import json

url = "https://api.uber.com/v1/guests/trips/{{trip_id}}"

payload={}
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer {{access_token}}'
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

POST : Get Guest Trip Estimates

import requests
import json

url = "https://api.uber.com/v1/guests/trips/estimates"

payload = "{
    "pickup":{
        "latitude":{{start_latitude}},
        "longitude":{{start_longitude}}
        },
    "dropoff":{
            "latitude":{{end_latitude}},
            "longitude":{{end_longitude}}
        }
    }"
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer {{access_token}}'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

PUT : Create Trip Communication Session

import requests
import json

url = "https://api.uber.com/v1/guests/trips/<request_id>/communication"

payload = json.dumps({
  "phone_number": "+123456789"
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer {{access_token}}'
}

response = requests.request("PUT", url, headers=headers, data=payload)

print(response.text)

DELETE : Cancel Guest Trip

import requests
import json

url = "https://api.uber.com/v1/guests/trips/{{request_id}}"

payload = ""
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer {{access_token}}'
}

response = requests.request("DELETE", url, headers=headers, data=payload)

print(response.text)

PHP

GET : Get Guest Trip

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.uber.com/v1/guests/trips/estimates',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
     "pickup":{
        "latitude":{{start_latitude}},
        "longitude":{{start_longitude}}
     },
     "dropoff":{
        "latitude":{{end_latitude}},
        "longitude":{{end_longitude}}
     }
  }
  ',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'Authorization: Bearer {{access_token}}'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

POST : Get Guest Trip Estimates

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.uber.com/v1/guests/trips/{{trip_id}}',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'Authorization: Bearer {{access_token}}'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

PUT : Create Trip Communication Session

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.uber.com/v1/guests/trips/<request_id>/communication',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'PUT',
  CURLOPT_POSTFIELDS =>'{
  "phone_number": "+123456789"
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'Authorization: Bearer {{access_token}}'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

DELETE : Cancel Guest Trip

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.uber.com/v1/guests/trips/{{request_id}}',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'DELETE',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'Authorization: Bearer {{access_token}}'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Uber

Developers
© 2023 Uber Technologies Inc.