Three lines

Uber

Developers

Curl

This tutorial walks you through the steps to implement the Business API in your app using curl.

Watch for the Try It tags, so you can try the examples as you read along!

We recommend using jq to pipe curl commands through so you can view JSON responses in a clean format. After installing, append | jq '.' to the following cURL examples to get JSON formatted bliss.


Authorize your application

Uber’s API complies with the OAuth 2.0 specification, so you can use a library in your favorite language to navigate this flow. To access the API, instead of authenticating as a user, authenticate as your application using the client credentials grant type. This will create an OAuth 2.0 access token with the specified scopes. These tokens cannot be refreshed, but they can be created as many times as needed (e.g., for each server/thread or when they expire).

The key things you need to know about OAuth can all be found in your application dashboard in the Auth tab:

  • client_id
  • client_secret
  • redirect_uri
  • scope (select from the list)

It may help to read our in-depth guide on navigating the OAuth 2.0 flow.

To create a client credential token, use the POST /token endpoint as follows, using your app’s client ID and secret from the developer dashboard:

Request

curl -F "client_secret=<CLIENT_SECRET>" \
    -F "client_id=<CLIENT_ID>" \
    -F "grant_type=client_credentials" \
    -F "scope=business.receipts" \
    https://auth.uber.com/oauth/v2/token

Response

{
    "access_token": "xxx",
    "token_type": "Bearer",
    "expires_in": 2592000,
    "scope": "business.receipts"
}

Listen for receipt webhook

Follow the instructions in account setup to ensure that you have been approved for access to your organization’s data and the business.receipts scope.

To enable webhooks, log in to the developer dashboard and go the Settings tab for your app. Under the Ride Requests section, add your webhook URL and click save. Webhooks sent from Uber’s servers will follow a standard format so that your application can easily understand what action it may want to take based on the contents of the payload. Below are the POST parameters that can be expected with each POST request received.

Example Request

{
   "event_id": "3a3f3da4-14ac-4056-bbf2-d0b9cdcb0777",
   "event_time": 1427343990,
   "event_type": "business_trips.receipt_ready",
   "meta": {
       "user_id": "d13dff8b-das-asd-1212e",
       "resource_id": "5152dcc5-b88d-4754-8b33-975f4067c943",
       "status": "ready"
   },
   "resource_href": "https://api.uber.com/v1/business/trips/5152dcc5-b88d-4754-8b33-975f4067c943/receipt"
}

Get a receipt

Now that you have a token, you can make requests to the Uber for Business API.

Try It The following example calls the GET /business/trips/{trip_id}/receipt endpoint and returns a receipt for a given trip id.

Request

curl -H 'Authorization: Bearer <TOKEN>' \
     -H 'Accept-Language: en_US' \
     -H 'Content-Type: application/json' \
     'https://api.uber.com/v1/business/trips/<TRIP_ID>/receipt'

Response

Status-Code: 200 OK

{
  "trip_uuid": "123-4567-890-abcd5",
  "organization_uuid":"abcddg-defkjh-dfgsd",
  "given_name": "John",
  "family_name": "Adams",
  "email": "john.adams@xyz.com",
  "employee_id": "123456",
  "product_name": "uberX",
  "duration": "00:20:13",
  "distance": 5.89,
  "distance_unit": "miles",
  "expense_code": "ABCD",
  "expense_memo": null,
  "pickup": {
    "location": {
      "latitude": 44.4431,
      "longitude": -71.6372,
      "address": "Street address, Seattle, WA 98052, United States",
      "city": "Seattle",
      "state": "WA",
      "country": "US"
    },
    "time": {
      "unix_timestamp": 1483665615,
      "utc_timestamp": "2017-01-06T01:20:15.000Z",
      "utc_offset": "-05:00"
    }
  },
  "dropoff": {
    "location": {
      "latitude": 45.4188,
      "longitude": -75.7041,
      "address": "Street address, city, WA 98052, United States",
      "city": "city",
      "state": "WA",
      "country": "US"
    },
    "time": {
      "unix_timestamp": 1483666828,
      "utc_timestamp": "2017-01-06T01:40:28.000Z",
      "utc_offset": "-05:00"
    }
  },
  "total_charged": 13.64,
  "total_owed": 0,
  "vat_amount": null,
  "currency_code": "CAD",
  "transaction_history": [
    {
      "transaction_uuid": "abcd-123345-defgjh-2342",
      "transaction_type": "SALE",
      "utc_timestamp": "2017-01-06T01:42:13.521Z",
      "amount": 13.64,
      "currency_code": "USD",
      "short_reference": "PXSOB"
    }
  ]
}

Congratulations! You finished the Business tutorial and can fetch receipts for business rides!

Uber

Developers
© 2023 Uber Technologies Inc.