Authentication

Authentication is required only for API partner methods.
You can authenticate by adding your partner API-Key and a Signature to the header.
More information about these parameters is given below.

API-Key

Security Scheme TypeAPI Key
Header parameter name:API-Key

The API key is a unique identifier given by Switchere to each partner.
This parameter is required in the header of the partner API request for authentication

Signature

Security Scheme TypeAPI Key
Header parameter name:API-Signature

The signature used to verify your request.
The following parameters are required to create a signature:

  • secret -- provided to you by our service
  • path -- only the URI request path
  • content -- the body of the request, converted to a string When all the parameters are ready, you need to use the cryptographic hashing for those parameters, as shown below:
    signature = hmac_sha512_base64( sha256(path + content), secret )
    You have to add the prepared signature to the header of the request

Examples

Perl

my $secret    = 'xxxxxxxx';  # provided by our service
my $path      = '/api/endpoint';
my $content   = '{"partner_order_id":"xxxxx-xxxxx-xxxx"}';
my $signature = hmac_sha512_base64(sha256($path . $content), $secret);

print $signature;

TypeScript

import { createHash, createHmac } from 'crypto';

const secret = 'xxxxxxxx'; // provided by our service
const path    = '/api/endpoint';
const content = '{"partner_order_id":"xxxxx-xxxxx-xxxx"}';

const contentSha256 = createHash('sha256').update(path + content, 'utf8').digest();
const signature = createHmac('sha512', secret).update(contentSha256).digest('base64').replace(/=+$/, '');

console.log(signature);

PHP

$secret    = 'xxxxxxxx';  # provided by our service
$path      = '/api/endpoint';
$content   = '{"partner_order_id":"xxxxx-xxxxx-xxxx"}';
$signature = trim(base64_encode(hash_hmac('sha512', hash('sha256', $path . $content, true), $secret, true)), '=');

print $signature;

Python

import hashlib
import hmac
import base64

secret  = b'xxxxxxxx'  # provided by our service
path    = '/api/endpoint'
content = '{"partner_order_id":"xxxxx-xxxxx-xxxx"}'

content_sha256 = hashlib.sha256((path + content).encode('utf-8')).digest()
signature = base64.b64encode(
    hmac.new(secret, content_sha256, hashlib.sha512).digest()
).decode().rstrip('=')

print(signature)

Java

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Base64;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

public class Signature {
    public static void main(String[] args) throws Exception {
        String secret  = "xxxxxxxx"; // provided by our service
        String path    = "/api/endpoint";
        String content = "{\"partner_order_id\":\"xxxxx-xxxxx-xxxx\"}";

        MessageDigest sha256 = MessageDigest.getInstance("SHA-256");
        byte[] contentSha256 = sha256.digest((path + content).getBytes(StandardCharsets.UTF_8));

        Mac hmac = Mac.getInstance("HmacSHA512");
        hmac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA512"));
        byte[] hmacBytes = hmac.doFinal(contentSha256);

        String signature = Base64.getEncoder().encodeToString(hmacBytes).replaceAll("=+$", "");

        System.out.println(signature);
    }
}
Last Updated: