> The index of all pages is at [llms.txt](https://developers.qliro.com/llms.txt). Add `.md` to any page URL for its Markdown.

# Authorization (/qliro-checkout/get-started/authorization)

## Authorization token

Every API call to Qliro Checkout must have an authorization token in the request header. The authentication scheme is `Qliro`.

To generate the token:

1. Create the input string. Append the MerchantAPISecret key to the JsonPayload.
2. Hash the string with SHA256.
3. Encode the hash in base64.

The result is the token for the authorization header.

If you send no JsonPayload, use an empty string in its place in step 1.

The Authorization header contains the authentication scheme and the token, in this syntax: **Authorization: Qliro token**.

<Callout type="info">
Notifications do not support authentication. Supply a generated URL that is only valid for a short period of time.
</Callout>

![Authentication](<https://developers.qliro.com/assets/authentication-2vhnCLm9.webp>)

## The JsonPayload

The JsonPayload consists of several parameters. The example below shows a possible JsonPayload. For the exact specification of the parameters, see the API Reference.

```json
{
  "MerchantReference": "MerchantUniqueReference",
  "Currency": "SEK",
  "Country": "SE",
  "Language": "sv-se",
  "MerchantConfirmationUrl": "http://Merchant.com/confirmation/",
  "MerchantTermsUrl": "http://Merchant.com/terms/",
  "PrimaryColor": "#00FF00",
  "CallToActionColor": "#0000FF",
  "OrderItems": [
    {
      "MerchantReference": "XXX",
      "Description": "ZZZ",
      "Quantity": 4,
      "PricePerItemIncVat": 450,
      "PricePerItemExVat": 450
    }
  ],
  "MerchantApiKey": "MERCHANTKEY"
}
```

### MerchantAPISecret

Authentication also requires a key called MerchantAPISecret. If you do not have one, contact your Onboarding agent or email [integration@qliro.com](mailto:integration@qliro.com).

## How-to

Use one of the following examples to generate a token.

<Tabs items={["JavaScript","C# .NET","PHP"]}>
<Tab value="JavaScript">
```javascript
var generateToken = function () {
  var payload = request.data;
  console.log("Payload: ", payload);
  var secret = postman.getEnvironmentVariable("ApiSecret");
  var input = '';
  if (payload && Object.keys(payload).length > 0) {
    input += payload;
  }
  input += secret;
  var token = CryptoJS.SHA256(input).toString(CryptoJS.enc.Base64);
  return "Qliro " + token;
};
```
</Tab>

<Tab value="C# .NET">
```csharp
public string CreateAuthorizationToken(string jsonPayoload, string apiSecret)
{
   using (var algorithm = new SHA256Managed())
   {
      var data = jsonPayload + apisecret;
      var bytes = Encoding.UTF8.GetBytes(data);
      var hash = algorithm.ComputeHash(bytes);
      return string.Format("Qliro {0}", Convert.ToBase64String(hash));
   }
}
```
</Tab>

<Tab value="PHP">
```php
$json = json_encode(array (
  'MerchantReference' => 'MerchantUniqueReference',
  'Currency' => 'SEK',
  'Country' => 'SE',
  'Language' => 'sv-se',
  'MerchantConfirmationUrl' => 'http://Merchant.com/confirmation/',
  'MerchantTermsUrl' => 'http://Merchant.com/terms/',
  'PrimaryColor' => '#00FF00',
  'CallToActionColor' => '#0000FF',
  'OrderItems' =>
  array (
    0 =>
    array (
      'MerchantReference' => 'XXX',
      'Description' => 'ZZZ',
      'Quantity' => 4,
      'PricePerItemIncVat' => 450,
      'PricePerItemExVat' => 450,
    ),
  ),
  'MerchantApiKey' => 'API-KEY',
));
print $json;
echo "<br>";
echo "Authentication Header = <br>";
print 'Qliro '.base64_encode(hex2bin(hash('sha256', $json.'<API-SECRET>')));
```
</Tab>
</Tabs>

## Error codes

If a call fails, you get an HTTP status code in the range 400-599.

The following authentication error can occur:

401 Unauthorized

The error has a content body in the following format.

### Error response parameters

| Name | Type | Description |
| :- | :- | :- |
| ErrorCode | String | Unique error code |
| ErrorMessage | String | Detailed error message |
| ErrorReference | String | A tracking ID from Qliro Checkout |

### Error response body example

```json
{
  "ErrorCode": "SYSTEM_ERROR",
  "ErrorMessage": "Details about the error",
  "ErrorReference": "GUID-CorelationId"
}
```

For more on errors, see the [API Reference](https://developers.qliro.com/api-reference/merchant/orders/create-order).

<Cards>
<Card title="Notifications" href="/qliro-checkout/get-started/notifications-checkout">
Continue to Notifications
</Card>
</Cards>