How to create a signature (md-5)

Let's review an example of creating a signature for a request to the Aviasales Flight Search API. For example, we have a set of parameters that we want to pass to the API to get data on airline tickets:

{
    "marker": "YourPartnerID",
    "host": "%server_host%",
    "user_ip": "%user_ip_address%",
    "locale": "en",
    "trip_class": "Y",
    "passengers": {
        "adults": 1,
        "children": 0,
        "infants": 0
    },
    "segments": [
        {
            "origin": "NYC",
            "destination": "LAX",
            "date": "2024-11-25"
        },
        {
            "origin": "LAX",
            "destination": "NYC",
            "date": "2024-12-18"
        }
    ]
}

1. First, you need to rearrange the parameters (and their values) so that they are in alphabetical order.

Note that the nesting of data is taken into account during sorting. This means that if an element contains an array (for example, segments) or a list of parameters (for example, passengers), the contents of this element are sorted separately and put in its place in the general list. The contents are not sorted with the top-level parameters. Parameters within an array are sorted in the order of curly braces { }.

To make it easier to understand the sorting process, check out the gif below (click to open in new window):

example.gif

As a result, you will get:

"host": "%server_host%",
"locale": "en",
"marker": "YourPartnerID",
"adults": 1,
"children": 0,
"infants": 0
"date": "2024-11-25"
"destination": "LAX",
"origin": "NYC",
"date": "2024-12-18"
"destination": "NYC",
"origin": "LAX",
"trip_class": "Y",
"user_ip": "%user_ip_address%"

2. Assemble a string containing only the values ​​of the parameters separated by a colon (ranking is the same as in step 1). For example:

beta.aviasales.com:en:PutYourPartnerIDHere:1:0:0:2024-11-25:LAX:NYC:2024-12-18:NYC:LAX:Y:127.0.0.1

You can find your partner ID at the bottom left corner of your Travelpayouts account:

3. Add to the beginning of this string the value of your affiliate API token:

PutYourTokenHere:beta.aviasales.com:en:PutYourMarkerHere:1:0:0:2022-05-25:BCN:LON:2022-06-18:LON:BCN:Y:127.0.0.1

You can find your token on the API page of the Aviasales program in your Travelpayouts account.

Use the resulting string to calculate the md-5 signature. The result is the signature of our request.
Important! Signature is case-sensitive.