API Request step
Call the Smooth POS API from a Glue job.
The API Request step calls the Smooth POS API as your company. Use it to read or change anything the API can reach (sales, customers, products, stock, private data and so on) without managing a token yourself.
When to use it
- Look something up that a later step needs, like a store, a customer or a private data key.
- Create or update records, such as a log entry, a customer or an inventory adjustment.
- Read a whole list one page after another with Fetch all pages (see Fetch all pages).
To call any other system, use REST Request instead.
Set it up
| In the app | data field | What it does |
|---|---|---|
| API endpoint | end_point, action | Pick the endpoint from the searchable list (Search endpoints). The method comes with it. |
| Endpoint fields (like Store ID or Key) | part of end_point | Fill in the parts of the path the endpoint needs. Liquid works, so {{ store_id }} is fine. |
| Additional URL parameters | part of end_point | Extra query string, like limit=100. |
| Body | post_body | The JSON body, for POST, PUT and PATCH endpoints. Usually {{ some_variable }} built in a Script step. |
| Fetch all pages | fetch_all_pages | Shown on list endpoints only. Walks every page and saves the combined list. |
| Fail on bad response code | fail_bad_status | Stops the job, and retries it, when the call doesn't return a 2xx status. |
| Response variable | response_variable | Saves the response as {status, body, headers}. body is a string, so parse it in a script. |
What it saves
Without Fetch all pages, the response variable holds {status, body, headers}:
var store = JSON.parse($.store_res.body);
$.store_name = store.name;With Fetch all pages on, it holds {items, count, pages, total, truncated, next} instead. See Fetch all pages.
Private data comes back wrappedGet Private Data returns
{"<key>": "<stored string>"}. If you stored JSON, parse twice:JSON.parse(JSON.parse($.config_res.body).marketing).
Example 1: Add the store name to a sale
Trigger: System Hook, Create Sale.
-
API Request: Get Private Data, Key
marketing, Response variableconfig_res, Fail on bad response code on. -
Script: Read the marketing flag
var sale = JSON.parse($.default); $.sale = sale; $.store_id = sale.store_id; var cfg = JSON.parse(JSON.parse($.config_res.body).marketing); $.send_sales_events = cfg.send_sales_events === true; -
API Request: Get Store, Store ID
{{ store_id }}, Response variablestore_res. Leave Fail on bad response code off: the store name is nice to have, and a failed lookup shouldn't retry the whole job. -
Script: Attach the store name
$.store_name = ""; if ($.store_res && $.store_res.status === 200) { $.store_name = JSON.parse($.store_res.body).name || ""; }
Example 2: Turn a webhook into a log entry
Trigger: Webhook.
-
Script: Read the payload
var body = {}; try { body = JSON.parse($.default); } catch (e) { body = {}; } $.is_sale = body.event === "sale"; $.log_body = JSON.stringify({ category: "external_sales", message: "Sale " + (body.reference || "") + " received" }); -
If Condition: If the event is a sale, Condition
$.is_sale === true. -
API Request: Create a log entry, nested under THEN:
POST /log.json, Body{{ log_body }}, Fail on bad response code on.
Put the API Request inside the THEN branch so only sale events are logged.
Example 3: Check the catalogue every morning
Trigger: Scheduled, daily at 6:00 am.
-
API Request: Get every product page, endpoint Get Products, Fetch all pages on, Response variable
products. -
Script: Count products with no barcode
// Count products that have at least one item with no barcode $.missing = ($.products.items || []).filter(function (p) { return (p.items || [p]).some(function (i) { return !i.barcode; }); }).length; -
If Condition: If any barcode is missing, Condition
$.missing > 0. -
Email: Email the catalogue team, nested under THEN, with a Subject like
{{ missing }} items have no barcode.
Tips
- Liquid in fields,
$in scripts. Endpoint fields and Body use{{ name }}. Scripts and conditions use$.name. - Retries skip it at the top level. When a job is retried, a top-level API Request that already succeeded isn't sent again. Inside an If Condition or Loop it runs again, so keep writes there safe to repeat.
Updated about 23 hours ago
