JavaScript / Node.js Examples — UnicyFalcon API
This guide shows how to integrate the UnicyFalcon API in Node.js.API access requires the API plan or higher.
1) Install dependencies
Copy
npm install axios crypto
2) Reusable Node.js client
Copy
const axios = require('axios');
const crypto = require('crypto');
class UnicyFalconApiClient {
constructor(apiKey, hmacSecret, baseUrl, timeout = 30000) {
this.apiKey = apiKey;
this.hmacSecret = hmacSecret;
this.baseUrl = baseUrl.replace(/\/$/, '');
this.timeout = timeout;
}
sign(method, uri, body, timestamp) {
const payload = `${method.toUpperCase()}|${uri}|${body}|${timestamp}`;
return crypto.createHmac('sha256', this.hmacSecret).update(payload).digest('base64');
}
async request(method, endpoint, data = null, params = null) {
const url = `${this.baseUrl}/${endpoint.replace(/^\//, '')}`;
const timestamp = Math.floor(Date.now() / 1000);
const body = data ? JSON.stringify(data) : '';
const basePath = new URL(this.baseUrl).pathname || '';
const uri = `${basePath}/${endpoint.replace(/^\//, '')}`;
const signature = this.sign(method, uri, body, timestamp);
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-API-Key': this.apiKey,
'X-Timestamp': timestamp.toString(),
'X-Signature': signature
};
const response = await axios({
method: method.toUpperCase(),
url,
headers,
data: data || undefined,
params: params || undefined,
timeout: this.timeout
});
return response.data;
}
get(endpoint, params = null) { return this.request('GET', endpoint, null, params); }
post(endpoint, data) { return this.request('POST', endpoint, data); }
put(endpoint, data) { return this.request('PUT', endpoint, data); }
delete(endpoint) { return this.request('DELETE', endpoint); }
}
3) Usage examples
Copy
const client = new UnicyFalconApiClient(
'ak_your_api_key_here',
'your_hmac_secret_here',
'https://your-subdomain.unicyfalcon.com/api/v1'
);
(async () => {
const customers = await client.get('/customers');
const order = await client.post('/orders', {
customer_id: 'uuid',
order_number: 'ORD-2026-001',
order_items: [
{ product_id: 'uuid', quantity: 2, unit_price: 99.99 }
],
status: 'pending',
pickup_address_id: 'uuid',
dropoff_address_id: 'uuid'
});
})();
