Authentication Guide
All requests to the Hubby eSIM API must be authenticated using HMAC-SHA256 signatures. This guide explains how to properly authenticate your requests.
API Endpoints
Before making any requests, ensure you're using the correct API endpoint:
- Production:
https://api.hubbyesim.com/api- For live applications - Staging:
https://api-staging.hubby.dev/api- For testing and development
Required Headers
Every API request must include these authentication headers:
x-api-key: YOUR_API_KEY
x-timestamp: CURRENT_TIMESTAMP_IN_MS
x-signature: HMAC_SIGNATUREGenerating the HMAC Signature
The signature is generated by:
- Concatenating the timestamp (in milliseconds), HTTP method, and full request path (including query parameters if present)
- Creating an HMAC-SHA256 hash using your secret key
- Converting the hash to a hexadecimal string
For example, for a GET request to /api/bookings?perPage=10 at timestamp 1715558400000:
- Payload would be:
1715558400000GET/api/bookings?perPage=10
Example Implementation
const crypto = require('crypto');
function generateHeaders(method, path, timestamp) {
// Ensure timestamp is a string and in milliseconds
const ts = String(timestamp);
// Create the payload string - include query parameters if present
const payload = ts + method + path;
// Generate HMAC signature
const signature = crypto
.createHmac('sha256', process.env.HUBBY_API_SECRET)
.update(payload)
.digest('hex');
// Return all required headers
return {
'x-api-key': process.env.HUBBY_API_KEY,
'x-timestamp': ts,
'x-signature': signature,
'Content-Type': 'application/json'
};
}Python Implementation
import hmac
import hashlib
import time
import os
def generate_headers(method, path):
# Get current timestamp in milliseconds
timestamp = str(int(time.time() * 1000))
# Create payload string - include query parameters if present
payload = timestamp + method + path
# Generate HMAC signature
signature = hmac.new(
os.environ['HUBBY_API_SECRET'].encode(),
payload.encode(),
hashlib.sha256
).hexdigest()
# Return headers dictionary
return {
'x-api-key': os.environ['HUBBY_API_KEY'],
'x-timestamp': timestamp,
'x-signature': signature,
'Content-Type': 'application/json'
}Important Notes
Timestamp Format
- Use Unix timestamp in milliseconds (e.g., 1715558400000)
- Must be within 400 minutes of current time
- Cannot be in the future
Request Path
- Include the full path starting with
/api - MUST include query parameters if present
- Example:
/api/bookings?perPage=10
- Include the full path starting with
API Keys
- Keep your secret key secure
- Never expose it in client-side code
- Keys expire after 1 year
- Contact support for key rotation
Common Issues
Invalid Signature
If you receive a 401 error with "Invalid signature", check:
- Timestamp is in milliseconds
- Query parameters are included in signature calculation
- Proper path formatting
- Correct concatenation order
- Secret key validity
Request Timestamp Expired
If you receive a "Request timestamp expired" error:
- Ensure your server's clock is synchronized
- Verify timestamp is in milliseconds
- Check if timestamp is within 400 minutes
Example Request
const timestamp = Date.now().toString();
const method = 'GET';
const path = '/api/bookings?perPage=10';
const headers = generateHeaders(method, path, timestamp);
// Use staging for development, production for live
const API_BASE_URL = process.env.NODE_ENV === 'production'
? 'https://api.hubbyesim.com'
: 'https://api-staging.hubby.dev';
const response = await fetch(`${API_BASE_URL}/api/bookings?perPage=10`, {
method: method,
headers: headers
});Security Best Practices
Environment Variables
- Store API keys in environment variables
- Never commit keys to version control
- Use different keys for development and production
Key Management
- Rotate keys periodically
- Revoke compromised keys immediately
- Monitor API usage for suspicious activity
Request Validation
- Validate all input parameters
- Use HTTPS for all requests
- Implement rate limiting
Getting Help
If you're having trouble with authentication:
- Check our troubleshooting guide
- Review the API reference
- Contact support@hubbyesim.com