Making a purchase involves several steps.
Please make sure you read the Conventions before continuing with this guide.
Prerequisites
You will need an X-API-KEY and a Basic Access Authentication token generated from your username and password.
Steps to complete a purchase
1) Select a product
Get the list of configured products, select one where "isBundle": true
.
You will need the values of the following properties type
and accountId
(from now on providerId
).
2) Select an specific bundle
Use the GET /inventory/bundles endpoint passing the type
and the providerId
from the selected product.
This will return all the bundles configured for that bundle type.
Select one of those bundles and save the _id
from now on bundleId
.
You will also have to save the _id_
from the products
array. You will be using that as the productId
from subsequent requests.
3) Select a fare for the specific bundle
Use the GET inventory/bundle/:bundleId/product/:productId
Select the _id
of the desired fare.
3) Select an origin station
Get all possible origin stations for your selected product.
Select an origin station, and remember its _id
and it's name
.
4) Select a destination station
After selecting an 'origin' station, get all possible destination stations that can be reached from that starting point.
This endpoint does not guarantee that there are schedules available between the origin and destination stations - this can only be determined when pushing to the cart.
Select a destination station, and remember its _id
and it's name
.
6) Authenticate
You are almost ready to add the trip into the shopping cart. First, you must authenticate.
Store the shortToken
from the authentication response, so that you can use it in subsequent API calls.
7) Add the bundle to the cart
Notice to replace
Remember the cartId
and the total
from the response. You will need this information to complete the order.
8) Select a payment type
To complete the order, first retrieve the available payment types and select one. Remember the method
field.
9) Select country and province info for the customer
Get our list of country and province information, and remember the result.
You will need a valid ISO
code of a country and a province (if it applies) to complete the customer information when paying for the order, in the next step.
10) Create the order
Create an order (pay for the items in the cart) using the information from the previous steps.
Once the payment is accepted, the booking is complete. Take note of the transactionIds
if you need to perform further actions, like downloading the tickets.
11) (Optional) Download tickets
In some cases you may want to download tickets for the booking. The tickets are downloaded as PDF files.
Postman resources
If you would like to use Postman to test the API, we have included a collection you can use as a starting point below.
This collection is designed to allow you to purchase a reservation, by following the steps above.
In order to use it successfully, you will need your X-API-KEY and data (like stations, routes, payment types and so on) set up for your account.
After importing the collection, and the environment, make sure your collection is using the new environment, and that you have set the initial values. On each step, you should manually add the missing environmental values with the values you get from the previous steps.
If you are going to be using our API in sandbox, please change the {{basePath}} environment variable to https://sandbox-api.betterez.com
.