Install and configure#
npm install https://apps.salopha.com/sdk/v1/salopha-mini-app-server-sdk-1.6.0.tgz
import { PlatformClient, PlatformError } from "@salopha/mini-app-server-sdk";
const platform = new PlatformClient({
baseUrl: process.env.SALOPHA_API_BASE!, // https://api.salopha.com/v1
clientId: process.env.SALOPHA_CLIENT_ID!,
clientSecret: process.env.SALOPHA_CLIENT_SECRET!, // server only
appId: process.env.SALOPHA_APP_ID!,
// eventKey: { keyId, privateKeyPem }, // Ed25519, for publishTransactionEvent
// timeoutMs, fetch // optional
});
Node.js 18 or later, no dependencies. Errors are PlatformError { status, code, details }.
Methods#
| Method | Calls | Auth |
|---|---|---|
exchangeCode({ code, launchSessionId, nonce, codeVerifier? }) | POST /mini-apps/auth/token | client secret |
me(userToken) | GET /mini-apps/auth/me | user token |
addresses(userToken) | GET /mini-apps/auth/me/addresses | user token (addresses.read) |
transactions(userToken, limit = 30) | GET /mini-apps/auth/me/transactions | user token (transactions.read) |
businesses(userToken) | GET /mini-apps/auth/me/businesses | user token: SALOPHA businesses bound to your app where the user is staff |
serverToken() | POST /mini-apps/auth/client-token | client secret; cached for its 15 minutes |
notify({ sub | subs, title, body, path?, dedupeKey?, collapseKey? }) | POST /partner/notifications | server token |
user(sub) | GET /partner/users/{sub} | server token: the profile with the same consent |
stats() | GET /partner/stats | server token |
bindings(providerExternalId?) · bindings({ status?, providerExternalId? }) | GET /partner/bindings?status=&providerExternalId= | server token |
decideBinding(businessId, { decision, providerExternalId?, note? }) | POST /partner/bindings/{businessId}/decision | server token: approve or reject a pending business join (1.5) |
setProviderExternalId(businessId, providerExternalId) | PUT /partner/bindings/{businessId} | server token: assign your merchant id (1.5) |
bindMerchant({ sub, providerExternalId, businessId } | { sub, providerExternalId, create }) | POST /partner/bindings | server token (business.binding.manage) |
publishTransactionEvent(event) | POST /partner/apps/{appId}/transaction-events | Ed25519 signature (eventKey) |
verifyWebhook(headers, method, path, rawBody) | — | checks a platform call's signature against the published keys |
handlePlatformCall({ method, path, headers, rawBody }, { search?, resolve?, businessJoined?, businessLeft?, webhook? }) | — | answers platform calls; returns { status, body } |
Partner HTTP API#
Base URL https://api.salopha.com/v1. JSON in and out.
| Call | Auth | Notes |
|---|---|---|
POST /mini-apps/auth/token { clientId, clientSecret, code, launchSessionId, nonce, codeVerifier? } | client secret | { access_token, expires_in, sub, scope, profile?, actor }. Replaying a code revokes the session. actor says whether the app runs as the person or a business (acting identity). |
GET /mini-apps/auth/me · /me/addresses · /me/transactions · /me/businesses | user token | Consent re-checked live on every call |
POST /mini-apps/auth/client-token { clientId, clientSecret } | client secret | Server token for 15 minutes (aud miniapp-server:<appId>); rotating the secret ends old ones |
POST /partner/notifications { sub | subs[≤500], title ≤120, body ≤300, path?, dedupeKey?, collapseKey? } | server token | Per item: sent, no_consent, unknown_subject, rate_limited (20 per user per app per hour) |
GET /partner/users/{sub} · GET /partner/stats | server token | |
GET | POST /partner/bindings | server token | Merchant bindings and business memberships; GET filters by status and providerExternalId |
POST /partner/bindings/{businessId}/decision { decision: "approve" | "reject", providerExternalId?, note? } | server token | Decide a pending business join |
PUT /partner/bindings/{businessId} { providerExternalId } | server token | Assign your own merchant id |
POST /partner/apps/{appId}/transaction-events | Ed25519 signature | See Transactions and webhooks |
POST /share/search { appId, query, actionId?, limit ≤ 40, locale } | SALOPHA user (the app calls it) | The hub's side of chat search: forwards to your objects/search with the user's pairwise id and sanitizes the answer |
GET /mini-apps/{appId}/providers/{externalId}/business | SALOPHA user (the app calls it) | Which business chat a merchant maps to |
Calls from SALOPHA to you#
SALOPHA calls your webhookUrl base (for example https://shop.example.com/api/v1/platform), always signed with Ed25519. The public keys are published at https://api.salopha.com/v1/.well-known/salopha-webhook-keys.json.
| Path | When | Timeout |
|---|---|---|
POST <webhookUrl>/webhooks | Consent revoked, binding changed, business joined or left, transaction rated, version published, transaction actions | 10 s (asynchronous, retried) |
POST <webhookUrl>/actions | A user runs a transaction action | 8 s |
POST <webhookUrl>/objects/search | Chat search | 4 s |
POST <webhookUrl>/objects/resolve | A chat card is created or opened | 3 s |
api.post("/api/v1/platform/*", express.raw({ type: "*/*" }), async (req, res) => {
const r = await platform.handlePlatformCall({ method: req.method, path: req.originalUrl, headers: req.headers, rawBody: req.body }, {
search: (q) => searchCatalog(q),
resolve: (q) => cardFor(q.ref),
webhook: (event) => onPlatformEvent(event),
});
res.status(r.status).json(r.body);
});
Verify the raw body bytes as received: hash first, then parse. Answer 2xx within the timeout and process asynchronous events idempotently by eventId. Signing details are in Request signing.
Notifications#
const r = await platform.notify({ subs: [a, b], title: "New offer", body: "20% off today", path: "/offers", dedupeKey: "offer:2026-11-04" });
for (const item of r.items) if (item.status === "rate_limited") retryLater(item.sub);
Keep an outbox (id, sub, title, body, path, attempts, next attempt) and deliver from it. no_consent and unknown_subject are final; retry the rest with backoff. See Notifications for how users see them.
Statistics#
stats() returns your subscribers (users who opened the app at least once), active users, favourites, home-screen shortcuts, notification opt-ins, and 30-day series. The same numbers, with 90-day series and a subscriber list, are in the admin console.
Merchant bindings#
Connect each merchant in your app (your id: a store slug, an agency id…) to a SALOPHA business, so customers message it through the business chat.
// In your merchant console, after the merchant signed in through SALOPHA:
const mine = await platform.businesses(userToken); // businesses they manage
await platform.bindMerchant({ sub, providerExternalId: "store-1", businessId: mine[0].businessId });
// Or create the business from the merchant's data:
await platform.bindMerchant({ sub, providerExternalId: "store-1", create: { name: { ar: "…", en: "…" }, categoryIds: ["restaurants"], phones: ["+964…"] } });
// On your server, cached:
const reachable = await platform.bindings(); // [{ providerExternalId, status, chatAvailable, businessName, … }]
Businesses can also join your app themselves from SALOPHA (source: "join", providerExternalId: null until you assign one); see Business audience and joins for approving joins and assigning your merchant id.
A binding's status is one of active, pendingReview, needsInfo, paused, suspended, rejected, expired, cancelled or notRegistered; chatAvailable is true when it is active and the business is open. Official apps and trusted developers are active at once; others after review. One business per merchant.