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 a voucher program

import requests

url = "https://api.uber.com/v1/organizations/{{organization_id}}/voucher-programs/{{voucher_program_id}}"

payload={}
headers = {
  'Content-Type': 'application/x-www-form-urlencoded',
  'Authorization': 'Bearer {{access_token}}'
}

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

print(response.text)

POST : Create a voucher program

import requests
import json

url = "https://api.uber.com/v1/organizations/{{organization_id}}/voucher-programs"

payload = json.dumps({
  "name": "Acme Holiday Party",
  "description": "This is a test voucher.",
  "currency_code": "USD",
  "timezone": "America/Los_Angeles",
  "starts_at": 1575136800000,
  "ends_at": 1575180000000,
  "code_scheme": "SINGLE_CODE_MULTI_REDEEM",
  "redemptions_per_code": 5,
  "value_per_trip_max_amount": 5,
  "value_per_period_max_trips": 2
})
headers = {
  'Content-Type': 'application/json',
  'Accept-Language': 'en_US',
  'Authorization': 'Bearer {{access_token}}'
}

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

print(response.text)

PATCH : Update a voucher program

import requests
import json

url = "https://api.uber.com/v1/organizations/{{organization_id}}/voucher-programs/{{voucher_program_id}}"

payload = json.dumps({
  "ends_at": 1575180000000
})
headers = {
  'Content-Type': 'application/json',
  'Accept-Language': 'en_US',
  'Authorization': 'Bearer {{access_token}}'
}

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

print(response.text)

PHP

GET : Get a voucher program

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.uber.com/v1/organizations/{{organization_id}}/voucher-programs/{{voucher_program_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/x-www-form-urlencoded',
    'Authorization: Bearer {{access_token}}'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

POST : Create a voucher program

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.uber.com/v1/organizations/{{organization_id}}/voucher-programs',
  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 =>'{
        "name": "Uber Vouchers",
        "description": "Test vouchers.",
        "currency_code": "USD",
        "timezone": "America/Los_Angeles",
        "starts_at": 1575136800000,
        "ends_at": 1575180000000,
        "code_scheme": "SINGLE_CODE_MULTI_REDEEM",
        "redemptions_per_code": 5,
        "value_per_trip_max_amount": 5,
        "value_per_period_max_trips": 2
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'Accept-Language: en_US',
    'Authorization: Bearer {{access_token}}'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

PATCH : Update a voucher program

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.uber.com/v1/organizations/{{organization_id}}/voucher-programs/{{voucher_program_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 => 'PATCH',
  CURLOPT_POSTFIELDS =>'{
       "ends_at": 1575180000000
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'Accept-Language: en_US',
    'Authorization: Bearer {{access_token}}'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Uber

Developers
© 2023 Uber Technologies Inc.