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 appdata fieldWhat it does
API endpointend_point, actionPick the endpoint from the searchable list (Search endpoints). The method comes with it.
Endpoint fields (like Store ID or Key)part of end_pointFill in the parts of the path the endpoint needs. Liquid works, so {{ store_id }} is fine.
Additional URL parameterspart of end_pointExtra query string, like limit=100.
Bodypost_bodyThe JSON body, for POST, PUT and PATCH endpoints. Usually {{ some_variable }} built in a Script step.
Fetch all pagesfetch_all_pagesShown on list endpoints only. Walks every page and saves the combined list.
Fail on bad response codefail_bad_statusStops the job, and retries it, when the call doesn't return a 2xx status.
Response variableresponse_variableSaves 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 wrapped

Get 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.

  1. API Request: Get Private Data, Key marketing, Response variable config_res, Fail on bad response code on.

  2. 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;
  3. API Request: Get Store, Store ID {{ store_id }}, Response variable store_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.

  4. 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.

  1. 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"
    });
  2. If Condition: If the event is a sale, Condition $.is_sale === true.

  3. 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.

  1. API Request: Get every product page, endpoint Get Products, Fetch all pages on, Response variable products.

  2. 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;
  3. If Condition: If any barcode is missing, Condition $.missing > 0.

  4. 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.

← All Glue step guides


Did this page help you?