SDKs
The API from TypeScript and JavaScript: typed methods, paging, safe retries and webhook signatures.
@mobiari/api is the API for servers (Node 20+, Bun, Deno):
one typed method per operation, named after its operationId in the
reference. It has no dependencies. A Python package (mobiari) follows.
npm install @mobiari/apiMake a call
import { Mobiari, MobiariError } from '@mobiari/api'
const mobiari = new Mobiari({ apiKey: process.env.MOBIARI_KEY! })
const product = await mobiari.getProduct(productId)
await mobiari.updateProduct(productId, { title: 'Vela de lavanda' })A method takes the path's ids first, then the body, then the query:
updateProduct(id, body), listOrders(query),
createBooking({ service_id, starts_at, customer_name }). Bodies, query
parameters and answers are typed from the API's own OpenAPI document;
Schema<'Order'> names an object.
A store API key (mobi_sa_…) names its store. With another credential,
pass store (the store's id) to the client or to one call.
Pages
Lists answer a Page. The client
follows next_cursor for you, with the operation's own arguments:
for await (const order of mobiari.iterate('listOrders', { status: 'paid' })) {
console.log(order.number, order.total_cents)
}
const variants = await mobiari.all(500, 'listProductVariants', productId)pages(op, ...args) gives each page, iterate each item, and all(max, …)
an array of at most max items.
Errors and retries
A refusal throws MobiariError with status, code (branch on it; see
errors), fields (validation messages by
field), retryAfter and traceId (quote it to support).
The client retries what is safe to retry, up to maxRetries (default 2),
waiting Retry-After:
- a
GET,PUT,PATCHorDELETEafter a network failure,429,502,503or504; - a
POSTafter a network failure or429, with the sameIdempotency-Key(passidempotencyKeyto choose it), so the API answers it once.
A POST answering 503 (the store's payment gateway or carrier failed)
may or may not have acted: look at the order or shipment before you try
again. An upload is never repeated.
Webhooks
verifyWebhook checks a delivery's Mobiari-Signature and answers its
event, typed by its type:
import { verifyWebhook } from '@mobiari/api'
const event = await verifyWebhook(rawBody, request.headers.get('mobiari-signature'), secret)
if (event.type === 'orders.paid') {
const order = event.data.object
}Pass the body exactly as received. See Webhooks.
Options
| Option | |
|---|---|
apiKey | A store API key. |
store | The store's id, for a credential that is not a store key. |
baseUrl | Default https://api.mobiari.com/v1. |
timeoutMs | Default 60000. |
maxRetries | Default 2. |
userAgent | Added to the SDK's own, e.g. my-erp/1.4. |
fetch | Your own fetch. |
Every method also takes { idempotencyKey, signal, store } last.