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 Health Trip
import requests
import json
url = "https://api.uber.com/v1/health/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 Health Trip Estimates
import requests
import json
url = "https://api.uber.com/v1/health/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 Health Trip Communication Session
import requests
import json
url = "https://api.uber.com/v1/health/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 Health Trip
import requests
import json
url = "https://api.uber.com/v1/health/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 Health Trip
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.uber.com/v1/health/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 Health Trip Estimates
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.uber.com/v1/health/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 Health Trip Communication Session
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.uber.com/v1/health/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 Health Trip
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.uber.com/v1/health/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;