Developers / Recipes
Integration recipes
The integrations companies ask for most, as a few API calls each. Run any of them in your sandbox, step by step, then copy the finished script. With a sandbox on, the scripts below already hold your key and sample ids.
Feed your payroll every month
Wait for HR to lock the month, then read paid days, LOP and expenses to pay.
Subscribe to the event HR’s lock sends.
POST/v1/webhooks{ "url": "inbox", "events": [ "payroll.month.locked" ], "description": "Payroll" }See which months are locked.
GET/v1/payroll/monthsRead a locked month. Each person’s paid days and LOP are ready for your salary run.
GET/v1/payroll/months/{month}
The complete script
// Feed your payroll every month: an ANOMA API recipe.
// Wait for HR to lock the month, then read paid days, LOP and expenses to pay.
// Run it with Node 18 or later: ANOMA_KEY=ank_… node payroll.mjs
const API = 'https://app.anomahq.com/api';
const KEY = process.env.ANOMA_KEY || '__KEY__';
async function anoma(method, path, body) {
const res = await fetch(API + path, {
method,
headers: { Authorization: `Bearer ${KEY}`, ...(body ? { 'Content-Type': 'application/json' } : {}) },
body: body ? JSON.stringify(body) : undefined,
});
const data = await res.json();
if (!res.ok) throw new Error(`${method} ${path}: ${res.status} ${data.error?.message} (request ${res.headers.get('x-request-id')})`);
return data;
}
// 1. Subscribe to the event HR’s lock sends.
const step1 = await anoma('POST', '/v1/webhooks', { url: 'inbox', events: ['payroll.month.locked'], description: 'Payroll' });
console.log('1.', step1);
// 2. See which months are locked.
const step2 = await anoma('GET', '/v1/payroll/months');
console.log('2.', step2);
// 3. Read a locked month. Each person’s paid days and LOP are ready for your salary run.
if (!step2.data.length) throw new Error('No month is locked yet. HR locks one in ANOMA: Close the month for payroll.');
const step3 = await anoma('GET', `/v1/payroll/months/${step2.data[0].month}`);
console.log('3.', step3);
"""Feed your payroll every month: an ANOMA API recipe.
Wait for HR to lock the month, then read paid days, LOP and expenses to pay.
Run it with Python 3.8 or later: pip install requests then ANOMA_KEY=ank_… python payroll.py
"""
import os
import requests
API = "https://app.anomahq.com/api"
KEY = os.environ.get("ANOMA_KEY", "__KEY__")
def anoma(method, path, body=None):
res = requests.request(method, API + path, headers={"Authorization": f"Bearer {KEY}"}, json=body, timeout=30)
data = res.json()
if not res.ok:
raise SystemExit(f"{method} {path}: {res.status_code} {data['error']['message']} (request {res.headers.get('x-request-id')})")
return data
# 1. Subscribe to the event HR’s lock sends.
step1 = anoma("POST", "/v1/webhooks", {"url": "inbox", "events": ["payroll.month.locked"], "description": "Payroll"})
print("1.", step1)
# 2. See which months are locked.
step2 = anoma("GET", "/v1/payroll/months")
print("2.", step2)
# 3. Read a locked month. Each person’s paid days and LOP are ready for your salary run.
if not step2["data"]:
raise SystemExit("No month is locked yet. HR locks one in ANOMA: Close the month for payroll.")
step3 = anoma("GET", f"/v1/payroll/months/{step2['data'][0]['month']}")
print("3.", step3)
Keep another system’s people in step
Copy everyone once, then apply changes as they happen.
Copy everyone (page through with after=next_cursor).
GET/v1/employees?limit=5Subscribe to joins, changes and exits.
POST/v1/webhooks{ "url": "inbox", "events": [ "employee.created", "employee.updated", "employee.exited" ] }Add someone, and watch employee.created arrive.
POST/v1/employees{ "first_name": "Arjun", "last_name": "Mehta", "email": "arjun.{rand}@sandbox.test", "join_date": "{today}", "designation": "Sales executive" }
The complete script
// Keep another system’s people in step: an ANOMA API recipe.
// Copy everyone once, then apply changes as they happen.
// Run it with Node 18 or later: ANOMA_KEY=ank_… node directory.mjs
const API = 'https://app.anomahq.com/api';
const KEY = process.env.ANOMA_KEY || '__KEY__';
const today = new Date().toLocaleDateString('en-CA'); // YYYY-MM-DD
const rand = Math.random().toString(36).slice(2, 8);
async function anoma(method, path, body) {
const res = await fetch(API + path, {
method,
headers: { Authorization: `Bearer ${KEY}`, ...(body ? { 'Content-Type': 'application/json' } : {}) },
body: body ? JSON.stringify(body) : undefined,
});
const data = await res.json();
if (!res.ok) throw new Error(`${method} ${path}: ${res.status} ${data.error?.message} (request ${res.headers.get('x-request-id')})`);
return data;
}
// 1. Copy everyone (page through with after=next_cursor).
const step1 = await anoma('GET', '/v1/employees?limit=5');
console.log('1.', step1);
// 2. Subscribe to joins, changes and exits.
const step2 = await anoma('POST', '/v1/webhooks', {
url: 'inbox',
events: ['employee.created', 'employee.updated', 'employee.exited'],
});
console.log('2.', step2);
// 3. Add someone, and watch employee.created arrive.
const step3 = await anoma('POST', '/v1/employees', {
first_name: 'Arjun',
last_name: 'Mehta',
email: `arjun.${rand}@sandbox.test`,
join_date: today,
designation: 'Sales executive',
});
console.log('3.', step3);
"""Keep another system’s people in step: an ANOMA API recipe.
Copy everyone once, then apply changes as they happen.
Run it with Python 3.8 or later: pip install requests then ANOMA_KEY=ank_… python directory.py
"""
import os
import random
import string
from datetime import date, timedelta
import requests
API = "https://app.anomahq.com/api"
KEY = os.environ.get("ANOMA_KEY", "__KEY__")
today = date.today().isoformat()
rand = "".join(random.choices(string.ascii_lowercase + string.digits, k=6))
def anoma(method, path, body=None):
res = requests.request(method, API + path, headers={"Authorization": f"Bearer {KEY}"}, json=body, timeout=30)
data = res.json()
if not res.ok:
raise SystemExit(f"{method} {path}: {res.status_code} {data['error']['message']} (request {res.headers.get('x-request-id')})")
return data
# 1. Copy everyone (page through with after=next_cursor).
step1 = anoma("GET", "/v1/employees?limit=5")
print("1.", step1)
# 2. Subscribe to joins, changes and exits.
step2 = anoma("POST", "/v1/webhooks", {
"url": "inbox",
"events": ["employee.created", "employee.updated", "employee.exited"],
})
print("2.", step2)
# 3. Add someone, and watch employee.created arrive.
step3 = anoma("POST", "/v1/employees", {
"first_name": "Arjun",
"last_name": "Mehta",
"email": f"arjun.{rand}@sandbox.test",
"join_date": today,
"designation": "Sales executive",
})
print("3.", step3)
Time off from your own app
Request leave from your intranet or bot, and follow it through approval.
Subscribe to every leave event.
POST/v1/webhooks{ "url": "inbox", "events": [ "leave.submitted", "leave.approved", "leave.rejected" ] }Pick a person and a leave type.
GET/v1/leave/typesRequest time off. leave.submitted fires.
POST/v1/leave/requests{ "employee_id": "{employee_id}", "leave_type_id": "{leave_type_id}", "start_date": "{in_14_days}", "end_date": "{in_15_days}", "reason": "Sent from my app" }Approve it as HR. leave.approved fires.
POST/v1/approvals/leave/{leave_id}/decide{ "decision": "approved" }
The complete script
// Time off from your own app: an ANOMA API recipe.
// Request leave from your intranet or bot, and follow it through approval.
// Run it with Node 18 or later: ANOMA_KEY=ank_… node leave.mjs
const API = 'https://app.anomahq.com/api';
const KEY = process.env.ANOMA_KEY || '__KEY__';
const EMPLOYEE_ID = __EMPLOYEE_ID__; // someone in your company
const LEAVE_TYPE_ID = __LEAVE_TYPE_ID__; // from GET /v1/leave/types
const weekday = n => { const d = new Date(Date.now() + n * 864e5); while ([0, 6].includes(d.getDay())) d.setDate(d.getDate() + 1); return d.toLocaleDateString('en-CA'); };
async function anoma(method, path, body) {
const res = await fetch(API + path, {
method,
headers: { Authorization: `Bearer ${KEY}`, ...(body ? { 'Content-Type': 'application/json' } : {}) },
body: body ? JSON.stringify(body) : undefined,
});
const data = await res.json();
if (!res.ok) throw new Error(`${method} ${path}: ${res.status} ${data.error?.message} (request ${res.headers.get('x-request-id')})`);
return data;
}
// 1. Subscribe to every leave event.
const step1 = await anoma('POST', '/v1/webhooks', {
url: 'inbox',
events: ['leave.submitted', 'leave.approved', 'leave.rejected'],
});
console.log('1.', step1);
// 2. Pick a person and a leave type.
const step2 = await anoma('GET', '/v1/leave/types');
console.log('2.', step2);
// 3. Request time off. leave.submitted fires.
const step3 = await anoma('POST', '/v1/leave/requests', {
employee_id: EMPLOYEE_ID,
leave_type_id: LEAVE_TYPE_ID,
start_date: weekday(14),
end_date: weekday(15),
reason: 'Sent from my app',
});
console.log('3.', step3);
// 4. Approve it as HR. leave.approved fires.
const step4 = await anoma('POST', `/v1/approvals/leave/${step3.id}/decide`, { decision: 'approved' });
console.log('4.', step4);
"""Time off from your own app: an ANOMA API recipe.
Request leave from your intranet or bot, and follow it through approval.
Run it with Python 3.8 or later: pip install requests then ANOMA_KEY=ank_… python leave.py
"""
import os
from datetime import date, timedelta
import requests
API = "https://app.anomahq.com/api"
KEY = os.environ.get("ANOMA_KEY", "__KEY__")
EMPLOYEE_ID = __EMPLOYEE_ID__ # someone in your company
LEAVE_TYPE_ID = __LEAVE_TYPE_ID__ # from GET /v1/leave/types
def weekday(n):
d = date.today() + timedelta(days=n)
while d.weekday() >= 5:
d += timedelta(days=1)
return d.isoformat()
def anoma(method, path, body=None):
res = requests.request(method, API + path, headers={"Authorization": f"Bearer {KEY}"}, json=body, timeout=30)
data = res.json()
if not res.ok:
raise SystemExit(f"{method} {path}: {res.status_code} {data['error']['message']} (request {res.headers.get('x-request-id')})")
return data
# 1. Subscribe to every leave event.
step1 = anoma("POST", "/v1/webhooks", {
"url": "inbox",
"events": ["leave.submitted", "leave.approved", "leave.rejected"],
})
print("1.", step1)
# 2. Pick a person and a leave type.
step2 = anoma("GET", "/v1/leave/types")
print("2.", step2)
# 3. Request time off. leave.submitted fires.
step3 = anoma("POST", "/v1/leave/requests", {
"employee_id": EMPLOYEE_ID,
"leave_type_id": LEAVE_TYPE_ID,
"start_date": weekday(14),
"end_date": weekday(15),
"reason": "Sent from my app",
})
print("3.", step3)
# 4. Approve it as HR. leave.approved fires.
step4 = anoma("POST", f"/v1/approvals/leave/{step3['id']}/decide", {"decision": "approved"})
print("4.", step4)
Connect a punch machine
Send punches from your device software; ANOMA turns them into attendance.
Send a day’s punches by employee code.
POST/v1/attendance/punches{ "punches": [ { "emp_code": "{emp_code}", "at": "{today}T09:05" }, { "emp_code": "{emp_code}", "at": "{today}T18:20" } ] }Read the attendance it made.
GET/v1/attendance?from={today}&to={today}
The complete script
// Connect a punch machine: an ANOMA API recipe.
// Send punches from your device software; ANOMA turns them into attendance.
// Run it with Node 18 or later: ANOMA_KEY=ank_… node punches.mjs
const API = 'https://app.anomahq.com/api';
const KEY = process.env.ANOMA_KEY || '__KEY__';
const EMP_CODE = '__EMP_CODE__'; // the employee code on the punch machine
const today = new Date().toLocaleDateString('en-CA'); // YYYY-MM-DD
async function anoma(method, path, body) {
const res = await fetch(API + path, {
method,
headers: { Authorization: `Bearer ${KEY}`, ...(body ? { 'Content-Type': 'application/json' } : {}) },
body: body ? JSON.stringify(body) : undefined,
});
const data = await res.json();
if (!res.ok) throw new Error(`${method} ${path}: ${res.status} ${data.error?.message} (request ${res.headers.get('x-request-id')})`);
return data;
}
// 1. Send a day’s punches by employee code.
const step1 = await anoma('POST', '/v1/attendance/punches', {
punches: [
{ emp_code: EMP_CODE, at: `${today}T09:05` },
{ emp_code: EMP_CODE, at: `${today}T18:20` },
],
});
console.log('1.', step1);
// 2. Read the attendance it made.
const step2 = await anoma('GET', `/v1/attendance?from=${today}&to=${today}`);
console.log('2.', step2);
"""Connect a punch machine: an ANOMA API recipe.
Send punches from your device software; ANOMA turns them into attendance.
Run it with Python 3.8 or later: pip install requests then ANOMA_KEY=ank_… python punches.py
"""
import os
from datetime import date, timedelta
import requests
API = "https://app.anomahq.com/api"
KEY = os.environ.get("ANOMA_KEY", "__KEY__")
EMP_CODE = "__EMP_CODE__" # the employee code on the punch machine
today = date.today().isoformat()
def anoma(method, path, body=None):
res = requests.request(method, API + path, headers={"Authorization": f"Bearer {KEY}"}, json=body, timeout=30)
data = res.json()
if not res.ok:
raise SystemExit(f"{method} {path}: {res.status_code} {data['error']['message']} (request {res.headers.get('x-request-id')})")
return data
# 1. Send a day’s punches by employee code.
step1 = anoma("POST", "/v1/attendance/punches", {
"punches": [
{"emp_code": EMP_CODE, "at": f"{today}T09:05"},
{"emp_code": EMP_CODE, "at": f"{today}T18:20"},
],
})
print("1.", step1)
# 2. Read the attendance it made.
step2 = anoma("GET", f"/v1/attendance?from={today}&to={today}")
print("2.", step2)