Working example

📘

Assumptions

In this working example we are assuming you have a proper username and password. We will refer from here as {username} and {password}.

Each time we have a variable, for example the authentication token, we will write it with brackets. For example {example}.

📘

Clone suntransfers.com!

There are many of ways to integrate with our API. In this example, we are going to try to "clone" Suntransfers.com.

Getting your credentials

Having your {username} and {password}, our first action is getting the authentication token.

curl --request POST \
  --url https://api.staging.suntransfers.biz/authentication \
  --header 'accept: application/json' \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data 'username={username}&password={password}'
{
  "status":"ok"
  "info":{
    "username":"{username}"
    "token":"{token}"
  }
}
🚧

Token

The token expires in an hour. If you have more than one process, they will get distinct tokens and there is no need to share or coordinate the refresh.

Choose the initial Gateway

We want to offer all the available gateways to our users

1285
curl --request GET \
  --url 'https://api.staging.suntransfers.biz/v1/gateways?locale=en' \
  --header 'accept: application/json' \
  --header 'authorization: Bearer {token}'
{
    "gateways": [
        {
            "id": 13,
            "name": "Alicante airport",
            "subtype": "airport",
            "code": "ALC",
            "country_code": "ES"
        },
        {
            "id": 15,
            "name": "Almeria airport",
            "subtype": "airport",
            "code": "LEI",
            "country_code": "ES"
        },
        {
            "id": 32,
            "name": "Barcelona airport",
            "subtype": "airport",
            "code": "BCN",
            "country_code": "ES"
        },
      ....

We take the Barcelona Airport Gateway id (32)

Getting the available routes from the Gateway

1403
curl --request GET \
  --url https://api.staging.suntransfers.biz/v1/routes/32 \
  --header 'accept: application/json' \
  --header 'authorization: Bearer {token}'
{
    "routes": [
        {
            "id": 138,
            "name": "Girona airport",
            "subtype": "airport",
            "code": "GRO",
            "country_code": "ES"
        },
        ...
        {
            "id": 11122,
            "name": "Badalona",
            "subtype": "",
            "code": "",
            "country_code": "ES"
        },
      ...

We will choose "Badalona" as our destination (id 11122)

Get Quotes

We want to go to from Barcelona Airport (location:32) to Badalona (location:11122) and we ask for 2 adults (2,0,0), for a specific date.

🚧

About locations

There are plenty of ways to find routes. Going by our locations is the easy one but you can search by other parameters.

Check "All About Quotes" guide for more information

curl --request GET \
  --url https://api.staging.suntransfers.biz/v1/quotes/EUR/location:32/location:11122/2,0,0/2021-12-22T11:35:00 \
  --header 'accept: application/json' \
  --header 'authorization: Bearer {token}'
{
    "restrictions": [],
    "route": {
        "id": 1265,
        "minutes": 35,
        "kilometers": 27
    },
    "quotes": [
        {
            "id": "b488d84c-f35f-4f63-b576-cbed943dd6fe",
            "vehicle": {
                "id": 58,
                "code": "tx3",
                "type": "taxi",
                "title": "Private Taxi",
                "model": "",
                "description": "private",
                "max_passengers": 3,
                "max_luggage": 3,
                "is_shared": false
            },
            "extras": [
                {
                    "code": "golf_bag",
                    "max_quantity": 1,
                    "unitary_price": {
                        "currency": "EUR",
                        "value": 0.0,
                        "prefix_symbol": "",
                        "suffix_symbol": "€"
                    }
                },
                {
                    "code": "child_booster_seat",
                    "max_quantity": 1,
                    "unitary_price": {
                        "currency": "EUR",
                        "value": 7.0,
                        "prefix_symbol": "",
                        "suffix_symbol": "€"
                    }
                },
                {
                    "code": "baby_seat",
                    "max_quantity": 1,
                    "unitary_price": {
                        "currency": "EUR",
                        "value": 7.0,
                        "prefix_symbol": "",
                        "suffix_symbol": "€"
                    }
                }
            ],
            "price": {
                "currency": "EUR",
                "value": 45.5936,
                "prefix_symbol": "",
                "suffix_symbol": "€"
            },
            "exchange_prices": [
                {
                    "currency": "EUR",
                    "value": 45.5936,
                    "prefix_symbol": "",
                    "suffix_symbol": "€"
                }
            ],
            "base_price": {
                "currency": "EUR",
                "value": 41.4487,
                "prefix_symbol": "",
                "suffix_symbol": "€"
            },
            "extra_data": {
                "price_id": 3541955,
                "rate_id": 8804
            }
        },
      .....
      ],
    "cross_selling": {
        "sms": {
            "price": {
                "currency": "EUR",
                "value": 1.75,
                "prefix_symbol": "",
                "suffix_symbol": "€"
            }
        },
        "gold_protection": {
            "price": {
                "currency": "EUR",
                "value": 3.0,
                "prefix_symbol": "",
                "suffix_symbol": "€"
            }
        }
    },
    "_metadata": {
        "offer": {
            "expiration_time": "2019-12-20T15:54:01+00:00",
            "hash": "api_af7e63f86c73fe482aecec7e719a1c5b43cb25c758f3229d2b5605951c61536d"
        }
    }
}

Let's see the response.

First we do have basic information about the route

"restrictions": [],
    "route": {
        "id": 1265,
        "minutes": 35,
        "kilometers": 27

Then we have an enumeration of quotes. Each one with an id. That id is important when you are going to make a booking. In our example, we are going to take "Private Taxi" (id: "b488d84c-f35f-4f63-b576-cbed943dd6fe").

Then we do have properties about the offer and extras

"quotes": [
        {
            "id": "b488d84c-f35f-4f63-b576-cbed943dd6fe",
            "vehicle": {
                "id": 58,
                "code": "tx3",
                "type": "taxi",
                "title": "Private Taxi",
                "model": "",
                "description": "private",
                "max_passengers": 3,
                "max_luggage": 3,
                "is_shared": false
            },
            "extras": [
                {
                    "code": "golf_bag",
                    "max_quantity": 1,
                    "unitary_price": {
                        "currency": "EUR",
                        "value": 0.0,
                        "prefix_symbol": "",
                        "suffix_symbol": "€"
                    }
                },
                {
                    "code": "child_booster_seat",
                    "max_quantity": 1,
                    "unitary_price": {
                        "currency": "EUR",
                        "value": 7.0,
                        "prefix_symbol": "",
                        "suffix_symbol": "€"
                    }
                },
                {
                    "code": "baby_seat",
                    "max_quantity": 1,
                    "unitary_price": {
                        "currency": "EUR",
                        "value": 7.0,
                        "prefix_symbol": "",
                        "suffix_symbol": "€"
                    }
                }
            ],
            "price": {
                "currency": "EUR",
                "value": 45.5936,
                "prefix_symbol": "",
                "suffix_symbol": "€"
            },
            "exchange_prices": [
                {
                    "currency": "EUR",
                    "value": 45.5936,
                    "prefix_symbol": "",
                    "suffix_symbol": "€"
                }
            ],
            "base_price": {
                "currency": "EUR",
                "value": 41.4487,
                "prefix_symbol": "",
                "suffix_symbol": "€"
            },
            "extra_data": {
                "price_id": 3541955,
                "rate_id": 8804
            }
        },

At the bottom of the document we do have the offer's hash (hash: api_af7e63f86c73fe482aecec7e719a1c5b43cb25c758f3229d2b5605951c61536d). You will need that info for the booking

"_metadata": {
        "offer": {
            "expiration_time": "2019-12-20T15:54:01+00:00",
            "hash": "api_af7e63f86c73fe482aecec7e719a1c5b43cb25c758f3229d2b5605951c61536d"
        }
    }

Make the booking

Knowing the trip that we want to do and the vehicle type we want, it is the moment to make the booking!

curl --request POST \
  --url https://api.staging.suntransfers.biz/v1/bookings \
  --header 'authorization: Bearer {token}' \
  --header 'content-type: application/json' \
  --data '{"quote_id":"b488d84c-f35f-4f63-b576-cbed943dd6fe","offer":{"hash":"api_af7e63f86c73fe482aecec7e719a1c5b43cb25c758f3229d2b5605951c61536d"},"customer":{"title":"Mr","name":"customer name","surname":"customer surname","mobile_country_code":"ES","mobile_phone":"111222333444","email":"[email protected]"},"lead_passenger":{"title":"Mr","name":"name of the one doing the trip","surname":"surname of the one doing the trip","mobile_country_code":"ES","mobile_phone":"6664442222","email":"[email protected]"},"gold_protection":false,"sms_notification":false,"passengers":{"total":1},"currency":"EUR","language":"en","transfers":[{"outward":{"flight":{"airline_code":"vueling","flight_number":"VL345","airport_code":"BCN","flight_date_time":"2021-11-15 15:53:00"}},"destination":{"accommodation": {"pickup_date_time": "2021-09-20T15:00:00","name": "Some hotel","address": "Carrer llacuna 22"	}}}]}'
{
  "reference": "SUNTR_AZ1234",
  "price": {
    "currency": "EUR",
    "value": 45.59,
    "prefix_symbol": "",
    "suffix_symbol": "€"
  },
  "price_eur": {
    "currency": "EUR",
    "value": 45.59,
    "prefix_symbol": "",
    "suffix_symbol": "€"
  }
}

Cancel the booking

Finally, we cancel the booking

curl --request DELETE \
  --url https://api.staging.suntransfers.biz/v1/bookings/SUNTR_KM8612 \
  --header 'authorization: Bearer {token}'

What’s Next