Loopfour
Blocks

API Request block

Call any HTTP API from a workflow step, with the method, headers and body you configure, and use the response in later steps.

The API Request block calls one HTTP endpoint and parses the response so later steps can use it. Use it for a system that has an API but no Loopfour integration. In a workflow definition it is a step with type: "action" and action: "api.request".

When to use it

  • Pull a report or a list of records from an internal or third-party API.
  • Post data to a system Loopfour has no block for.
  • Download a CSV or PDF over HTTP and hand it to a Data Table, PDF or Workspace Files step.

If the system has an integration block, prefer it: it uses the saved connection and maps the system's errors.

Configuration

Field (config key)Editor labelTypeRequiredMeaning
urlURLstringYesAbsolute https URL. Plain http is refused (see Errors and limits). Accepts template references such as {{input.reportId}}.
methodMethodstringYesGET, POST, PUT, PATCH or DELETE. Default GET.
paramsQuery Paramsobject or [{Key, Value}] tableNoAdded to the URL query string.
headersHeadersobject or [{Key, Value}] tableNoRequest headers. Put credentials in a secret: Authorization: Bearer {{secrets.MY_API_KEY}}.
bodyBodyobject or stringNoAn object is sent as JSON with Content-Type: application/json. A string is sent as is; a string that parses as JSON gets the JSON content type when you set none.
responseFormatResponse FormatstringNoauto (default), json, csv, text, pdf or binary. auto picks a format from the response content type.
csvDelimiterCSV DelimiterstringNoDelimiter for csv. Default ,.
timeoutTimeout (ms)numberNoRequest timeout. Default 300000, capped at 600000.
retriesRetriesnumberNoExtra attempts after a timeout, network error, 408, 429 or 5xx response. Default 0.
retryDelayMsRetry Delay (ms)numberNoFirst retry delay. Doubles each attempt. Default 500. A Retry-After header takes precedence.
retryMaxDelayMsMax Retry Delay (ms)numberNoUpper bound on a retry delay. Default 30000.
retryNonIdempotentRetry POST/PATCHbooleanNoAllow retries for POST and PATCH. Off by default, because a retry can repeat a side effect such as creating a payment twice.
maxResponseBytesMax Response (bytes)numberNoFail rather than load a larger response. Default 20971520 (20 MB).
failOnErrorFail On Error StatusbooleanNoDefault true: a non-2xx response fails the step. Set false to keep going and branch on status or ok.

Output

FieldTypeWhen presentMeaning
okbooleanAlwaystrue for a 2xx response.
statusnumberAlwaysHTTP status code.
statusTextstringAlwaysHTTP status text.
headersobjectAlwaysResponse headers, lower-case names.
contentTypestringAlwaysResponse content type.
sizeBytesnumberAlwaysResponse size in bytes.
responseFormatstringAlwaysThe format used to parse the body.
dataanyAlwaysParsed body: the JSON value, the CSV rows, the text, or the base64 content for binary.
textstringjson, csv, text, pdfThe body as text. For pdf, the extracted text.
rowsarraycsvOne object per data row, keyed by header.
columnsarraycsvHeader names.
rowCountnumbercsvNumber of data rows.
pageCountnumberpdfPages in the PDF.
contentstringpdf, binaryThe body as base64.
contentEncodingstringpdf, binarybase64.

Read a JSON field as {{steps.<step id>.data.<path>}}. Pass a downloaded file to a Workspace Files saveFile step with content set to {{steps.<step id>.content}}.

Example

This workflow fetches an aging report as CSV and upserts the rows into a table. The token is stored as a company secret named AR_REPORT_TOKEN.

{
  "name": "Import AR aging report",
  "trigger": { "type": "schedule", "cron": "0 7 * * 1-5", "timezone": "America/New_York" },
  "steps": [
    {
      "id": "fetch_aging",
      "type": "action",
      "name": "Fetch AR aging CSV",
      "action": "api.request",
      "config": {
        "url": "https://reports.example.com/v1/ar-aging",
        "method": "GET",
        "params": { "asOf": "today", "format": "csv" },
        "headers": { "Authorization": "Bearer {{secrets.AR_REPORT_TOKEN}}" },
        "responseFormat": "csv",
        "retries": 2
      }
    },
    {
      "id": "save_rows",
      "type": "data_table",
      "name": "Upsert aging rows",
      "config": {
        "operation": "upsertMany",
        "tableId": "8c1f0f5e-2a4b-4c55-9a64-0d2f3e6b7a10",
        "matchKey": "invoiceNumber",
        "rows": "{{steps.fetch_aging.rows}}"
      }
    }
  ]
}

Errors and limits

  • A non-2xx response fails the step with the status and up to 500 characters of the body, unless failOnError is false.
  • A response marked or forced as json that does not parse fails the step with Response was not valid JSON.
  • A response larger than maxResponseBytes fails the step and is not retried.
  • The request goes through Loopfour's outbound network policy. The policy refuses plain http, loopback and private or internal addresses. A refused destination fails the step and is not retried.
  • With retries exhausted, the step fails with API request to <origin><path> failed after N attempt(s).
  • Secrets in headers are substituted at run time and removed from the stored step output. See Variable references.

On this page