Code examples
Minimal examples for authentication, listing documents and creating a business partner. Replace YOUR_KEY_ID, YOUR_SECRET and the base URL with your real values.
cURL
Authentication on each request
bash
export KEY_ID="abk_xxxx"
export SECRET="your_secret"
export BASE="https://api.abaco.hn"
curl -X GET "$BASE/documents?page=1&limit=5" \
-H "Authorization: Bearer $KEY_ID:$SECRET"Create a business partner
bash
curl -X POST "$BASE/business-partners" \
-H "Authorization: Bearer $KEY_ID:$SECRET" \
-H "Content-Type: application/json" \
-d '{"name":"Example Client","taxId":"0801-1990-12345","type":"C","email":"client@example.com"}'Node.js (fetch)
javascript
const BASE = 'https://api.abaco.hn';
const KEY_ID = 'abk_xxxx';
const SECRET = 'your_secret';
const token = `${KEY_ID}:${SECRET}`;
// List documents
const res = await fetch(`${BASE}/documents?page=1&limit=10`, {
headers: { Authorization: `Bearer ${token}` },
});
if (!res.ok) {
if (res.status === 429) throw new Error('Rate limit; retry later');
if (res.status === 401) throw new Error('Invalid API key');
throw new Error(await res.text());
}
const data = await res.json();
console.log(data.documents);Python (requests)
python
import os
import requests
BASE = os.environ.get("ABACO_API_BASE", "https://api.abaco.hn")
KEY_ID = os.environ.get("ABACO_KEY_ID", "abk_xxxx")
SECRET = os.environ.get("ABACO_SECRET", "your_secret")
token = f"{KEY_ID}:{SECRET}"
headers = {"Authorization": f"Bearer {token}"}
# List documents
r = requests.get(f"{BASE}/documents", params={"page": 1, "limit": 10}, headers=headers)
if r.status_code == 429:
raise Exception("Rate limit; wait and retry")
if r.status_code == 401:
raise Exception("Invalid API key")
r.raise_for_status()
data = r.json()
print(data["documents"])Handling 401 and 429 errors
- 401: Verify that Key ID and Secret are correct and that the key is not revoked or expired. See Authentication.
- 429: Wait a few seconds and retry with backoff (e.g. 2 s, 4 s, 8 s). See Rate limits.