How to call private endpoints
Practical guide on how to start calling Kuna's private endpoints
First of all, please generate API keys, so you may start calling private endpoints.
After the exploration is completed, we highly recommend using signed requests option
Header settings if a single API key is used
Header | Value | Description |
---|---|---|
accept | application/json | The client expects response data as JSON. |
content-type | application/json | The client sends data as JSON in the request body. |
api-key | YOUR_API_KEY | A single API keys string to authenticate. |
Example. Get account balance using API key
const apiKey = "YOUR_API_KEY"; // put here your Api key
const url = "https://api.kunapay.io";
const path = "/v1/asset/balance"; // put here request path. To get your account balance: /v4/private/getBalance
const options = {
method: "GET",
headers: {
accept: "application/json",
"Content-Type": "application/json",
"api-key": apiKey,
},
};
fetch(url + path, options)
.then((response) => response.json())
.then((showResponse) => console.log(showResponse.data));
import requests
api_key = "YOUR_API_KEY" # put here your Api key
url = "https://api.dashboard.kuna.io"
path = "/v1/asset/balance" # put here request path. To get your account balance: /v4/private/getBalance
headers = {
"accept": "application/json",
"Content-Type": "application/json",
"api-key": api_key,
}
request = requests.get(url + path, headers=headers)
print(request.json())
Example. Create invoice using API key
const apiKey = "YOUR_API_KEY"; // put here your Api key
const url = "https://api.kunapay.io";
const path = "/v1/invoice"; // put here request path.
const body = {
asset: "USD",
amount: "1000",
};
const options = {
method: "POST",
headers: {
accept: "application/json",
"Content-Type": "application/json",
"api-key": apiKey,
},
body: JSON.stringify(body),
};
fetch(url + path, options)
.then((response) => response.json())
.then((showResponse) => console.log(showResponse.data));
import requests
api_key = "YOUR_API_KEY"
url = "https://api.dashboard.kuna.io"
path = "/v1/invoice" # put here request path.
headers = {
"accept": "application/json",
"Content-Type": "application/json",
"api-key": api_key,
}
body = {
"asset": "USD",
"amount": "1000",
}
request = requests.post(url + path, headers=headers, json=body)
print(request.json())
Header settings if public + private keys are used
Header | Value | Description |
---|---|---|
accept | application/json | The client expects response data as JSON. |
content-type | application/json | The client sends data as JSON in the request body. |
public-key | YOUR_PUBLIC_KEY | Public key (can be obtained when generating keys) string to authenticate. |
nonce | NONCE | Time Stamp. Put in Unix Time Stamp format in milliseconds (ms). |
signature | SIGNATURE | Unique signature for your request. |
Example. Get account balance using public + private keys
const crypto = require("crypto");
const publicKey = "YOUR_PUBLIC_KEY"; // put here your public key
const privateKey = "YOUR_PRIVATE_KEY"; // put here your private key
const url = "https://api.kunapay.io";
const path = "/v1/asset/balance"; // put here request path.
const body = {}; // empty object for GET request
// Get UTC time in milliseconds
const nonce = +new Date(); // nonce is a number that is always higher than the previous request number
// Hashing signature
const signature = crypto
.createHmac("sha384", privateKey)
.update(`${path}${nonce}${JSON.stringify(body)}`)
.digest("hex");
const options = {
method: "GET",
headers: {
accept: "application/json",
"Content-Type": "application/json",
"public-key": publicKey,
nonce: nonce.toString(),
signature: signature,
},
};
fetch(url + path, options)
.then((response) => response.json())
.then((showResponse) => console.log(showResponse.data));
import json
import requests
import time
import hashlib
import hmac
public_key = "YOUR_PUBLIC_KEY" # put here your public key
private_key = "YOUR_PRIVATE_KEY" # put here your private key
url = "https://api.dashboard.kuna.io"
path = "/v1/asset/balance"
body = {} # empty object for GET request
# Get UTC time in milliseconds
nonce = str(int(time.time() * 1000)) # nonce is a number that is always higher than the previous request number
signature_string = path + nonce + json.dumps(body)
# Hashing signature
signature = hmac.new(private_key.encode("utf-8"), signature_string.encode("utf-8"), hashlib.sha384).hexdigest()
headers = {
"accept": "application/json",
"Content-Type": "application/json",
"public-key": public_key,
"nonce": nonce,
"signature": signature,
}
request = requests.get(url + path, headers=headers, json=body)
print(request.json())
Example. Create invoice using public + private keys
const crypto = require("crypto");
const publicKey = "YOUR_PUBLIC_KEY"; // put here your public key
const privateKey = "YOUR_PRIVATE_KEY"; // put here your private key
const url = "https://api.kunapay.io";
const path = "/v1/invoice"; // put here request path.
const body = {
asset: "USD",
amount: "1000",
};
// Get UTC time in milliseconds
const nonce = +new Date(); // nonce is a number that is always higher than the previous request number
// Hashing signature
const signature = crypto
.createHmac("sha384", privateKey)
.update(`${path}${nonce}${JSON.stringify(body)}`)
.digest("hex");
const options = {
method: "POST",
headers: {
accept: "application/json",
"Content-Type": "application/json",
"public-key": publicKey,
nonce: nonce.toString(),
signature: signature,
},
body: JSON.stringify(body),
};
fetch(url + path, options)
.then((response) => response.json())
.then((showResponse) => console.log(showResponse.data));
import json
import requests
import time
import hashlib
import hmac
public_key = "YOUR_PUBLIC_KEY" # put here your public key
private_key = "YOUR_PRIVATE_KEY" # put here your private key
url = "https://api.dashboard.kuna.io"
path = "/v1/invoice"
body = {
"asset": "USD",
"amount": "1000"
}
# Get UTC time in milliseconds
nonce = str(int(time.time() * 1000)) # nonce is a number that is always higher than the previous request number
signature_string = path + nonce + json.dumps(body, separators=(',', ':'))
# Hashing signature
signature = hmac.new(private_key.encode("utf-8"), signature_string.encode("utf-8"), hashlib.sha384).hexdigest()
headers = {
"accept": "application/json",
"Content-Type": "application/json",
"public-key": public_key,
"nonce": nonce,
"signature": signature,
}
request = requests.post(url + path, headers=headers, json=body)
print(request.json())
Updated 9 months ago