API & Webhooks
Astra exposes a REST API so your own systems can read and write your organization's data without going through the screen, plus outbound webhooks so Astra can tell your system when something changes. Both live in the API & Webhooks add-on and are managed from two pages: one for API Keys and one for Webhooks. This article is written for whoever builds the integration: it lists the real endpoints, the headers, the error codes, and how to verify a webhook signature.
The connection to the Costa Rican tax authority for issuing electronic documents is a separate service Astra operates for you: it is not driven by these keys or these webhooks. Everything about digital signing, document keys and Hacienda responses lives in Electronic Invoicing.
Who can use it and where it lives
The API and webhooks are part of the API & Webhooks add-on, which the plan catalog offers with the Plus plan. If your organization does not have it active, both pages return an access error and every API call answers 403 with the code feature_disabled, even when the key itself is valid. To turn it on, see Subscription & Billing.
With the add-on active, both pages open from Settings → Integrations, in the API & Webhooks section, with a button for each (they also answer at their address):
- API Keys — /settings/api-keys
- Webhooks — /settings/webhooks
The Owner, the Admin and any custom role with the Settings permission Integrations can open them. The Organization permission alone is not enough: a key or a webhook reaches all of the company's data. Each page has Back to Integrations at the top. The rest of the company setup lives in Organization Settings.
Besides this article, Astra publishes the v1 OpenAPI specification at /api/openapi.json and a browsable reference at /api/docs. Both are public (no key needed) and are generated from the same code that serves the calls, so they are safe to use for generating a client or checking a field-level detail.
Create an API key
In Settings → Integrations, open API Keys and click Create API key. The form has five fields:
- Name — Required, up to 120 characters. It is only a label for you ("Billing sync", "Production ERP"). Use one key per integration: when one has to be revoked, you will know which.
- Scopes — Required, at least one. There is one row per kind of data (Contacts, Invoices, Products, Work orders) with a short explanation and the boxes Read and, where the API can change data, Write. Each box is granted independently and read does not imply write: if your integration both reads and writes contacts, tick both. Invoices and products only have Read, and the work-orders row appears only when your organization has that add-on. For developers, each box is a
resource:actionscope (contacts:read,work_orders:write…); hover over it to see it. - Expiration — Never expires, 30 days, 90 days or 1 year. On expiry the key moves to the Expired status and stops authenticating; it does not renew itself.
- IP allowlist (optional) — IPv4/IPv6 addresses or CIDR blocks, comma- or newline-separated. If you set any, calls from any other address are rejected. Empty means no restriction.
- Create as test key — When ticked, the key reads and writes real data, but none of its writes trigger outbound webhooks. Use it to exercise the integration end to end without hammering your receivers. The row is tagged Test.
Clicking Create key reveals an amber panel, Copy this key now, with the full token and a copy button. That is the only time it is shown: Astra stores only a hash, so if you dismiss the panel with I have copied the key before saving it, there is no way to recover it — you have to revoke it and create another. Under the token, Try it from a terminal gives a ready-to-copy curl command with a read the new key is allowed to make.
The token looks like ast_live_<identifier>_<secret>, or ast_test_… for a test key. In the list, the Identifier column shows only the prefix and the last four characters (for example ast_live_k7fq2b…9c14) — enough to tell keys apart without exposing the secret.
Every call is recorded in history under the user who created the key. If that person is deactivated or leaves the organization, the key stops working immediately and answers 401. When someone leaves the team, check which keys they created and re-issue them from an account that stays.
Revoking and rotating
Every active key has a Revoke button, which asks for confirmation in a dialog. The cut is immediate and cannot be undone: a revoked key can never be reactivated. To rotate a key without downtime, the order is: create the new one, swap the token in your system, confirm it works, and only then revoke the old one. Revoked and expired keys stay in the list with their status so the trail remains.
Your first call
The API lives under https://astra.astranexo.com/api/v1. The token goes in either of these two headers, your choice — Astra looks at Authorization first:
Authorization: Bearer ast_live_YOUR_KEY_HERE
X-Api-Key: ast_live_YOUR_KEY_HERE
A quick call to confirm the key works:
curl -s "https://astra.astranexo.com/api/v1/contacts?per_page=2" \
-H "Authorization: Bearer ast_live_YOUR_KEY_HERE" \
-H "Accept: application/json"
Every list response uses the same envelope: the records in data and the pagination in meta.
{
"data": [
{
"id": "0f0a1f5e-1c2b-4a77-9a10-8c3d2e5b7a41",
"name": "Ferretería El Roble",
"email": "purchasing@example.com",
"identification_type": "02",
"identification_number": "3101234567",
"contact_role": "customer",
"status": "active",
"billing_currency": "CRC",
"credit_terms": 30,
"created_at": "2026-08-14T09:12:44-06:00",
"updated_at": "2026-08-30T16:03:05-06:00"
}
],
"meta": {
"page": 1, "per_page": 2, "total": 184,
"last_page": 92, "has_more": true
}
}
A single record (/contacts/<id>) returns the same object inside data, with no meta.
Pagination
- Page-based (default) —
pageandper_page.per_pagestarts at 25 and is clamped to the range 1–100; asking for 500 returns 100, not an error. - Cursor-based — Send
use_cursor=1on the first call, then pass the value ofmeta.next_cursorin thecursorparameter. A cursor does not skew when new records arrive while you page through, so it is the recommended mode for large exports. In exchange,metacarriesnext_cursor,prev_cursorandhas_more, but nottotalorlast_page.
Available endpoints
This is everything version 1 exposes today. Any other route you see in browser traffic is internal to the application and is not part of the API.
| Method and path | What it does | Scope |
|---|---|---|
GET /api/v1/contacts |
Paginated list of contacts, newest first. Filters: search (name, email, mobile or company) and role (customer, supplier, both, prospect, other). |
contacts:read |
GET /api/v1/contacts/<id> |
One contact. | contacts:read |
POST /api/v1/contacts |
Creates a contact. Returns 201 with the created record. |
contacts:write |
PATCH /api/v1/contacts/<id> |
Updates the fields you send. Returns the updated record. | contacts:write |
DELETE /api/v1/contacts/<id> |
Deletes the contact. Returns 204 with no body. |
contacts:write |
GET /api/v1/invoices |
List of invoices by issue date, newest first. Filters: status, contact_id, issued_from and issued_to (YYYY-MM-DD dates). |
invoices:read |
GET /api/v1/invoices/<id> |
One invoice: numbering, document key, currency, exchange rate, subtotal, tax, total, amount paid and balance. | invoices:read |
GET /api/v1/products |
List of products ordered by name. Filters: search (name, SKU or barcode), category_id and is_active. |
products:read |
GET /api/v1/products/<id> |
One product. | products:read |
GET /api/v1/work-order-options |
What you need to create or move orders: each enabled type with its fields and statuses (and the custom statuses, if the organization uses them), the priorities and the people orders can be assigned to. | work_orders:read |
GET /api/v1/work-orders |
List of work orders. Filters: search (number, title, device, serial, customer or technician; accents ignored), order_number (exact number), status, contact_id, assigned_to, is_open and updated_since (only orders changed since that moment, oldest first: use it to check for changes every few minutes). |
work_orders:read |
GET /api/v1/work-orders/<order> |
One work order, with its status, the status name, the custom status and the type's own fields. | work_orders:read |
POST /api/v1/work-orders |
Creates an order in the type's initial status, under the type's field rules. It does not sign the intake or notify the customer. | work_orders:write |
PATCH /api/v1/work-orders/<order> |
Changes only the fields you send: title, problem, priority, dates, technician and device details. | work_orders:write |
POST /api/v1/work-orders/<order>/status |
Changes the status under the same rules as the screen: only the type's statuses, and blocked changes are refused with the reason. Nothing is sent to the customer. | work_orders:write |
GET / POST /api/v1/work-orders/<order>/notes |
Reads or adds internal notes. The customer never sees them; notes added through the API start with [API · key name] and notify nobody. | read: work_orders:readadd: work_orders:write |
GET / POST /api/v1/work-orders/<order>/files |
Reads or uploads files in the Files tab (one per call, up to 50 MB, as multipart/form-data). An uploaded file stays hidden from the customer unless you send customer_visible. Each download link lasts 60 minutes. |
read: work_orders:readupload: work_orders:write |
Where it says <order>, use the order's id or its number, for example R123 (case-insensitive).
Contacts and work orders can be created and changed through the API. That is why the form only offers Read for invoices and products (an older key that has invoices:write or products:write keeps them, but they enable nothing). Issuing an invoice touches the Hacienda flow and is done from the application (see Electronic Invoicing).
On top of the key's scope, the person who created it must hold that action's permission in their role: Create to create orders, Edit to change them, add notes or upload files, and Edit plus Change status to move the status. Reading an order's files also needs View files, as the Files tab does. If their role loses a permission, the key loses it too, without touching the key.
Work-order endpoints carry an extra lock: on top of the scope on the key, the organization must have the Work Orders add-on active. Without it the response is 403 with a short body, {"error": "addon_required", "addon": "work_orders"}. The check runs on every call, so dropping the add-on cuts access instantly without touching the key.
Limits, headers and idempotency
Rate limit
The limit is per key — not per organization and not per user: each key gets its own bucket of 600 requests per minute. That way a runaway integration cannot starve the others. If one key genuinely needs a different ceiling, support can adjust it.
Once over, the response is 429 with the code rate_limited and a Retry-After header in seconds. Do not retry immediately or in a tight loop: wait what Retry-After says.
Response headers
| Header | What it is for |
|---|---|
X-API-Version | Always 1. If your client sees another value, something rewrote the response in transit. |
X-RateLimit-Reset | Unix timestamp when your key's bucket refills. It is sent on every response, not only on 429, so you can pace yourself before hitting the wall. |
X-Request-Id | Request identifier. If you send your own, Astra keeps it; otherwise it generates one. It comes back on the response and also inside the error body. This is the value to quote to support. |
Retry-After | Only on 429: seconds left before you may call again. |
Idempotency
On mutating calls (POST, PATCH, PUT, DELETE) you may send an Idempotency-Key header holding a unique value you generate (a UUID works). It is optional: without it everything behaves as normal. With it:
- Repeating the call with the same key and the same body within 24 hours returns the stored original response, marked
X-Idempotency-Replay: true, and the operation does not run again. This is the safety net for "the connection dropped — did it go through or not?". - Reusing the key with a different body returns
409with the codeidempotency_conflict: every distinct operation needs its own key. - Only successful responses (
2xx) under 64 KB are stored. Errors are not cached, so retrying after a failure does re-execute. - Records expire after 24 hours.
Errors
Every error inside version 1 comes back in the same envelope — no HTML, no surprise shapes:
{
"error": {
"code": "insufficient_scope",
"message": "Missing required scope: contacts:write",
"request_id": "3f7c1a9e-52b4-4c8d-9f21-6a0e5d3b8c77"
}
}
Validation errors add a details object listing the problems per field. The codes are stable: you can branch on them without parsing the message.
| Status | Code | What happened |
|---|---|---|
| 401 | unauthenticated | Key missing, malformed, revoked, expired, calling from a disallowed IP, or its creator is no longer active in the organization. |
| 403 | feature_disabled | The key is valid, but the organization no longer holds the API & Webhooks add-on. |
| 403 | insufficient_scope | The key lacks the scope that route requires. |
| 403 | addon_required | The add-on the resource depends on is missing (today, Work Orders). |
| 404 | not_found | The record does not exist, or belongs to another organization. |
| 405 | method_not_allowed | The method does not apply to that route (for example, a POST to invoices). |
| 409 | idempotency_conflict | You reused an idempotency key with a different body. |
| 422 | validation_failed | The data you sent failed validation. Read details. |
| 429 | rate_limited | You passed the rate limit. Wait what Retry-After says. |
| 500 | internal_error | Our fault. Keep the request_id and write to us. |
The 401 message is always identical — it does not say whether the key exists, expired, or was blocked by the IP allowlist. That is deliberate: a more specific answer would help someone probing keys at random. If you get a 401 and the key should work, check the row's status on the page (Active, Expired, Revoked), the IP allowlist, and whether the user who created it is still active.
Checking a key's usage
The Details link on each row expands three parts:
- The key's data — Created (date and who created it), Expires and Allowed IPs.
- Last 7 days — four figures (Total requests, Successful, Errors and Avg latency) and one bar per day with its total on top. The red part of a bar is that day's share of requests with errors. The Today bar is counted live; earlier days come from a roll-up computed every early morning.
- Latest requests — the 10 most recent: when, the method and path, the response (red when it was an error) and how long it took. Hover over the path to see the request id, the one to quote to support.
It is the quickest way to spot an integration that started failing or suddenly spiked in volume, and to see exactly which call failed.
Create a webhook
In Settings → Integrations, open Webhooks and click New webhook. Four fields:
- Name — Required, up to 120 characters.
- Endpoint URL — The address that will receive the
POST. In production it must be https, on port 80 or 443, and the hostname must resolve to a public address:localhost, internal hostnames and private ranges are rejected. The rule is re-checked on every delivery, so if DNS later points at an internal address, deliveries stop. - Description (optional) — Up to 500 characters. Use it to note who owns the receiver.
- Events — At least one, grouped by kind of data (Contacts, Invoices, Work orders, Products). Each one shows its name, an explanation and its technical code; each group's All box ticks them at once. Work-order events appear only when your organization has that add-on. You will receive a
POSTfor every event you select.
On save, a Copy this signing secret now panel appears with a value starting in whsec_. Like the API key, it is shown once: it is the secret you use to verify the signature on every delivery.
Edit, new secret and delete
- Edit — Opens the same form with the subscription's name, URL, description and events. The URL is checked again on save and the secret does not change.
- New secret (in Details) — Generates another secret and shows it once, as on creation. The old one stops working at that moment, so your receiver will reject deliveries until it saves the new one. Use it if you lost the secret or think someone else saw it.
- Delete (in Details) — Asks for confirmation. Astra stops sending it events and its delivery history is deleted too; this cannot be undone.
The events
| Event | When it fires |
|---|---|
contact.created | A contact is created, by any route (screen, import or API). |
contact.updated | A change to a contact is saved. |
contact.deleted | A contact is deleted. |
invoice.created | An invoice is created. |
invoice.paid | Recorded payments reach the invoice total. Fires once per invoice, the first time it is fully covered. |
invoice.voided | An invoice becomes voided. |
work_order.created | A work order is created. |
work_order.status_changed | A work order's status changes. The body includes previous_status and new_status. |
product.created | A product is created. |
product.updated | A change to a product is saved. |
listing.published | A product or a used unit appears on your website. |
listing.updated | The price, photos, name or stock of something published on the website changed. |
listing.unavailable | Something published on the website sold, ran out or was unpublished. |
Events fire on the change itself, not on the channel: it makes no difference whether the contact was created from the screen, by an import, or by your own integration. The one exception is the test key — writes made with a key tagged Test really happen, but produce no deliveries.
The delivery: headers, body and signature
Every delivery is a POST with a JSON body and these headers:
Content-Type: application/jsonUser-Agent: Astra-Webhooks/1.0X-Astra-Event— The event type, for exampleinvoice.paid.X-Astra-Delivery-Id— Unique identifier for this delivery. It stays the same across retries, so use it to discard duplicates.Astra-Signature— The signature, shapedt=<timestamp>,v1=<hmac>.
The body is always the same envelope, whatever the event:
{
"id": "b1d9c0a4-6e7f-4f21-9a3c-0d5e8f2b1a66",
"type": "invoice.paid",
"created_at": "2026-09-02T11:04:17-06:00",
"organization_id": "7c2a5f31-9b48-4d0e-8a6f-2e1c4b7d9a03",
"data": {
"invoice": {
"id": "9a41e7d2-33bc-4f18-b0d5-7e6a1c9f4b20",
"invoice_number": "00100001010000000842",
"contact_id": "0f0a1f5e-1c2b-4a77-9a10-8c3d2e5b7a41",
"issue_date": "2026-09-01",
"status": "sent",
"currency_code": "CRC",
"total": 282500,
"amount_paid": 282500,
"balance_due": 0
}
}
}
The four top-level fields are always there: id (unique to the event), type, created_at and organization_id. Whatever is specific to the event goes inside data, under the resource key (contact, invoice, product or work_order), carrying the same fields the API returns for that resource.
Verifying the signature
Verify before you process anything. The procedure is:
- Read the
Astra-Signatureheader and split its two parts:t(Unix timestamp) andv1(the hex signature). - Build the signed string by joining the timestamp, a dot, and the raw body exactly as it arrived:
<t>.<body>. It must be the un-reserialized body — if your framework parses it to an object and dumps it back to text, the signature will not match. - Compute
HMAC-SHA256over that string with the subscription'swhsec_…secret. - Compare the result to
v1using a constant-time comparison. - Reject the delivery if the timestamp is more than 5 minutes away from the current time. That is what stops someone replaying a captured delivery.
Deliveries, retries and auto-disable
The Details link expands, under the action buttons, the last 20 deliveries for that subscription, with the Event, the Status, the number of Attempts, when it was Sent at, and the Response (the HTTP status your server returned, or the connection error). View, next to each one, opens the exact body that was sent and what your server answered.
The possible statuses are Pending (queued or in flight), Delivered, Failed, will retry (with the time of the next attempt) and Not delivered (attempts exhausted). In the technical data they are pending, succeeded, failed and dead.
Retries
A delivery succeeds if your server answers any 2xx within 10 seconds. Anything else — a 500, a 404, a timeout, a connection or certificate error — counts as a failure and is retried on this ladder:
- Attempt 1: immediate.
- Attempt 2: 1 minute later.
- Attempt 3: 5 minutes later.
- Attempt 4: 30 minutes later.
- Attempt 5: 2 hours later.
- Attempt 6: 12 hours later.
If the sixth attempt also fails, the delivery is marked Not delivered and is not retried again on its own. In total the retry window covers a little under 15 hours.
The 10-second cutoff applies to the HTTP response, not to what you do with the data. The healthy pattern is to store the event, answer 200 right away, and process it in the background. And because retries can repeat a delivery, use the body's id (or the X-Astra-Delivery-Id header) to ignore what you already handled.
Auto-disable
Each time a delivery dies after exhausting its six attempts, the subscription counts one consecutive failure — the row shows it as "N consecutive failures". At 3, Astra switches the subscription off by itself and the status becomes Auto-disabled. It does not come back on its own: once your receiver is healthy again, click Enable, which also resets the counter. Any successful delivery resets it too.
While a subscription is disabled, deliveries queued for it die immediately with the reason "Subscription is disabled": events that happened during the outage are not held for later replay. If the outage was long, reconcile that period by reading through the API rather than waiting on webhooks.
Manual replay, testing and retention
- Replay — Shown on deliveries that failed or were not delivered. It resets that delivery's attempt counter and starts a fresh cycle with the same body and delivery id.
- Send test (in Details) — Queues a synthetic
webhook.testdelivery to that URL. It is sent even if the subscription does not list that event (which is why the event is absent from the form), and itsdatacarries a fixed message. Use it to confirm your receiver is reachable and your signature check works, without inventing an invoice. - Retention — The history prunes itself: successful deliveries are kept for 30 days and undelivered ones for 90 days. If you need a longer record, store it on your receiver's side.
Permissions and final notes
- Add-on — Everything in this article requires API & Webhooks to be active. Without it the pages do not open and the API answers
403. - Role — The Owner, the Admin and custom roles with the Settings permission Integrations see and manage keys and webhooks.
- Work orders — Those endpoints additionally require the Work Orders add-on, checked on every call.
- Data scope — A key only ever sees the data of its organization, the one that was active when it was created. There is no way to repoint a key or query another organization with it.
- Impersonation — While a support agent is operating your account with your authorization, the API keys page is blocked for them. Keys can only be issued by someone signed in with their own session.
- Secrets — Neither an API key nor a webhook signing secret can ever be viewed again. Store them in your system's secret manager, never in code or email.
Need more help?
Our team is ready to assist you.