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 : List All Employees
import requests
url = "https://api.uber.com/v1/business/organizations/{{organization_id}}/employees"
payload={}
headers = {
'Authorization': 'Bearer {{access_token}}'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
POST : Create Employee
import requests
import json
url = "https://api.uber.com/v1/business/organizations/{{organization_id}}/employees"
payload = json.dumps({
"employee": {
"first_name": "UberSandbox",
"last_name": "findhelp",
"email": "sample_email@gmail.com"
}
})
headers = {
'Authorization': 'Bearer {{access_token}}',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
DELETE : Delete Employee
import requests
url = "https://api.uber.com/v1/business/organizations/{{organization_id}}/employees?email={{email}}"
payload={}
headers = {
'Authorization': 'Bearer {{access_token}}'
}
response = requests.request("DELETE", url, headers=headers, data=payload)
print(response.text)
¶ PHP
GET : List All Employees
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.uber.com/v1/business/organizations/{{organization_id}}/employees',
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(
'Authorization: Bearer {{access_token}}'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
POST : Create Employee
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.uber.com/v1/business/organizations/{{organization_id}}/employees',
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 =>'{
"employee": {
"first_name": "UberSandbox",
"last_name": "findhelp",
"email": "sample_email@gmail.com"
}
}',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer {{access_token}}',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
DELETE : Delete Employee
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.uber.com/v1/business/organizations/{{organization_id}}/employees?email={{email}}',
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(
'Authorization: Bearer {{access_token}}'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;