App Functions — Test on a Demo Store (preview)
Run a saved function with salla_functions action=preview: it invokes the function
server-side against a demo store and returns the response. Use it after save to verify
behavior before publishing — no Portal needed.
save and deploy_status also hand back a preview URL. Ignore it: it is authenticated and
not client-callable, so action=preview is the way to run the function — it holds the auth
that URL needs.
1. Wait for the deploy
save returns a deploy job. The function isn't runnable until that deploy finishes:
- Poll
salla_functions action=deploy_status,job(the value action=save returns) →statusCOMPLETEDmeans ready;FAILED→ readfailure_reasonand fix. - Or just call
salla_functions action=preview— it returns "still deploying … retry in ~30s" until it's ready.
2. Gather the form inputs (real ids)
preview needs the trigger's form fields (the function's form). Confirm the exact
field names via salla_functions before invoking, rather than assuming order_id /
shipment_id. Two kinds:
store_id(always required) — an installed demo store. List them withsalla_apps action=demo_storesand pick aconnectedstore.- Resource ids (
order_id,shipment_id, …) — must be real records, since preview runs the real function against real data. Fetch or create them via the Salla Admin API with that store's access token (see salla-api-core).
Token handling is in salla-app-auth (the token arrives via the app.store.authorize
webhook; the app must hold scopes matching the resources you fetch — request only those).
Webhook signature verification + idempotency are in salla-webhooks. Route there; don't
duplicate that logic here.
Secret/PII hygiene: the store access token is a live merchant credential — keep it in memory, scoped to the demo store it belongs to. Use a demo store with synthetic records, and restore any config you changed for testing afterward.
3. Invoke
Illustrative — substitute real ids for the placeholders below:
salla_functions action=preview
app_id = 2133776579
trigger = shipment.created
store_id = 660806774
payload = { shipment_id: 12312 } # the form fields, minus store_id
The tool runs the function server-side and returns its response as-is (http_status +
response). A success:false / Resp.error() result is a real function outcome to inspect,
not a tool failure.
This mirrors the Portal's Save and Preview panel
(Testing). Check in the returned response: execution
status (success/failure), the response data, execution time, your console.log() output, and
any errors. Test multiple scenarios — happy path, edge cases (null/empty fields), and error
cases (API failures, timeouts). Changes stay in the sandbox until you publish.
Errors
- "still deploying or failed to deploy" → wait ~30s / check
deploy_status. - "Missing required form field(s)" → add them to
payloadas real ids. - "store_id is required" → pass a
connecteddemo store fromsalla_apps demo_stores. - App not installed / inactive on the store → install/activate it on the demo store first
(a
connectedstore fromsalla_apps demo_stores). - 401 / 403 fetching the resource ids → token or scope problem; see salla-app-auth for tokens and confirm the app holds the scopes for that resource.
Gate: "Preview returned the expected response on a demo store?" → publish with salla-app-functions-release.