API Authentication

Authentication is based on two headers:

X-Munzen-Key: your_api_key
X-Munzen-Signature: request_signature
  • X-Munzen-Key is your API key (public key) which you can get in your account dashboard.

  • X-Munzen-Signature — is a signature generated from the request body and signed by your secret API key HMAC-SHA256.

Keep in mind that it is mandatory to add a timestamp with every request. You can see a few examples below.

Code Examples

Here are a few examples with signature generation code:

// This is your API secret key
$apiSecret = 'PUT_YOUR_API_SECRET_HERE';

// How we will send our request
$requestMethod = 'POST';

// Request params
// timestamp — request UTC time in Unix Timestamp; 
$paramsArray = ['key1' => 'value1', 'key2' => 'value2', 'timestamp' => 1677237754];

// Sort recursive by keys
ksortRecursive($paramsArray);

// Concat request string recursive
$requestBody = implodeRecursive($paramsArray);

// Generate the string to sign
$stringToSign = $requestMethod . $requestBody;

// Recieve the hash
$signature = hash_hmac('sha256', $stringToSign, $apiSecret);


// Helper functions
function ksortRecursive(mixed &$array): void
{
    if (!is_array($array)) {
        return;
    }
    
    ksort($array);
    
    foreach ($array as $k => $v) {
        ksortRecursive($array[$k]);
    }
}

function implodeRecursive(mixed $array): string
{
    $output = '';
    foreach ($array as $item) {
        if (is_array($item)) {
            $output .= implodeRecursive($item);
        } else {
            $output .= $item;
        }
    }
    return $output;
}

Last updated