Skip to main content

API Authentication

Overview​

Calypso Public API uses API keys and request signatures for authentication.

To send API requests, create a public key and a secret key in the Calypso UI. The public key is sent in the Key header. The secret key is used only on the merchant side to create the request signature and must not be shared.

how-to-create-new-api-key.md

Required headers​

HeaderRequiredDescription
KeyYesPublic API key.
SignYesHEX-encoded HMAC-SHA512 signature of the exact request body.
Content-TypeYesMust be application/json.

Request body requirements​

Every API request body must be valid JSON and must include timestamp.

FieldTypeRequiredDescription
timestampnumberYesCurrent Unix UTC timestamp in milliseconds. The value must not be less than 3 minutes in the past or greater than 3 minutes in the future.

Account-scoped methods also include account, and methods with business parameters include payload. See each API method for its exact request body.

How to create a signature​

  1. Build the final JSON request body, including the current timestamp.
  2. Convert the request body to the exact string that will be sent to Calypso.
  3. Create an HMAC-SHA512 hash using the request body string as the message and the secret key as the key.
  4. Convert the hash bytes to a lowercase hexadecimal string and send it in the Sign header.

Signature examples​

JavaScript​

const crypto = require("crypto-js");

function signature(body, secretKey) {
return crypto.HmacSHA512(body, secretKey).toString(crypto.enc.Hex);
}

Python​

import hashlib
import hmac


def signature(body, secret_key):
return hmac.new(
secret_key.encode(),
body.encode(),
hashlib.sha512
).hexdigest()

Timestamp examples​

JavaScript​

const timestamp = Date.now();

Python​

import time

timestamp = round(time.time() * 1000)

Complete signing example​

api_key = "c529e14832b34b74972365cf7bf02430"
secret_key = "b823a6b9ea72408583cef9ec8d67fa52"

body = '{"timestamp":1}'
sign = "b16e9d45f49f2069becbc4f108b237bee588cfc353fe9501df103e692acbc68d482a10d34c12bea22fedde7e28e1b8e57a6a0a373b0e9a27c5257bd8b36e13b9"

Handling unknown response fields​

Calypso API may add new fields to responses without breaking existing integrations.

RequirementDescription
Ignore unknown response fieldsAPI clients must continue processing a response even if it contains fields that are not used by the integration.
Do not use strict response schemasResponse parsing must allow additional fields.
Send only documented request fieldsUnknown request fields can be rejected by API validation.
DocumentLink
ErrorsErrors
Webhook signature checkSign check