Skip to content

Call External API

The Call External API step sends one HTTP request from a workflow to a public URL and stores the response on the work item. It is the only way a workflow reaches another system: a Custom Step has no network access. Use it to:

  • fetch a value (an exchange rate, a vendor record);
  • post work-item data to your API;
  • call your own endpoint, an Azure Function or AWS Lambda that does the heavy work through the KnowledgeLake API.

At a glance

  • Runs On the workflow worker, when a work item reaches the step. One request per run.
  • Language No code in the step. The URL, headers and body can come from a Liquid Template, Javascript or Global Variable preprocessor.
  • Authored in The Workflow designer, toolbox group External Steps, step Call External API.
  • Can reach Public HTTPS hosts. Local and private addresses are refused.
  • Best for Enrichment lookups, posting to your API, and triggering your own endpoint.

The round trip

sequenceDiagram
  participant W as Workflow worker
  participant S as Call External API step
  participant Y as Your API
  W->>S: Work item reaches the step
  S->>S: Run preprocessors and check that the host is public
  S->>Y: GET or POST with your headers and the WorkItemId header
  Y-->>S: Status code and body
  S->>W: Write ApiResults.LastHttpStatusCode and the body key
  alt Status is 2xx
    W->>W: Evaluate the step's routes
  else Other status, timeout or refused host
    W->>W: Step fails, then Retries and Error Behavior apply
  end

Where you author it

  1. In the Workflow designer, drag Call External API from the External Steps group of the toolbox onto the canvas. You need permission to edit the workflow (feature Create Workflows or Manage All Workflows).
  2. Double-click it to set it.
  3. To take a setting's value from a preprocessor, select the gear icon next to the setting's name. See Templating Step Settings with Liquid.
Setting What to enter
External API URL The full HTTPS URL, with query string.
REST Verb GET or POST. The list also shows DELETE, PUT and PATCH, but the step fails with "Rest verb ... is not supported. Allowed: [GET, POST]".
HTTP Headers Key and value pairs, for example an API key header.
Body Type Shown for POST. Sets the Content-Type: JSON (application/json), XML, Text, Form-Encode (application/x-www-form-urlencoded). Do not use Form or Raw (see Rules).
Body The request text. Fixed text, or a Liquid or Javascript preprocessor over the work item.
Response Metadata Key The key that receives the response body, in bucket ApiResults. Leave it empty to discard the body.
Timeout Seconds to wait for the response. 0 means 15 minutes.

Runtime contract

Item Value
Engine Server-side .NET HTTP client. One request per run.
Runs when The work item reaches the step.
Timeout The Timeout setting; 0 means 15 minutes.
Network access Public hosts only. The host name must resolve to a public address.
Request Your URL, verb, headers and body, plus the header WorkItemId with the work item's id.
Writes ApiResults.LastHttpStatusCode and, if set, ApiResults.<Response Metadata Key>, at work-item level.

What the step writes

At work-item level, in bucket ApiResults:

  • ApiResults.LastHttpStatusCode: the status code as text, for example "200".
  • ApiResults.<Response Metadata Key>: the response body as text, if you set a key.

Both are written for every response, successful or not. Then:

  • On a 2xx status, the step succeeds and the routes run.
  • On any other status, the step fails. The error message is HTTP Response status code does not indicate success: <code> (<reason>). followed by Content: <body> when you set a Response Metadata Key.

The step writes nothing to ApiResults when the URL is refused, the host cannot be reached, or the timeout is reached. LastHttpStatusCode then keeps the value of any earlier call.

Rules

  1. Use only GET and POST. GET sends no body.
  2. The host must resolve to a public address. localhost, 127.0.0.1, and addresses in 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 are refused before any request with "Api domain is not valid". So is a host name that does not resolve.
  3. Do not add Content-Type in HTTP Headers. The Body Type sets it. A Content-Type header makes the step fail.
  4. Do not use Body Type Raw: the step sends no body. Do not use Form (multipart/form-data): the step sends the body text without a multipart boundary, which most servers reject.
  5. The step cannot send a file. To process a document file, call your own endpoint and let it download the file through the API.
  6. Every response body is stored as text. Parse it in a Custom Step with JSON.parse.
  7. Set the timeout below the limit of the system you call.
  8. Make the receiving endpoint safe to call twice. Retries and loops run the step again.
  9. Put a credential in HTTP Headers, never in the URL or the body. The URL and body can appear in error messages and logs.

Failure behavior

A failed call follows the step's error settings (in the step dialog):

Setting Effect
Retries (0 to 3) Runs the step again. The waits are about 1 second, 1 minute and 4 minutes.
Error Behavior: Stop (default) The work item goes into an error state.
Error Behavior: Continue The routes run as if the step succeeded. Route on ApiResults.LastHttpStatusCode.
Error Behavior: Route The work item goes to the step you pick.

When the step fails after its retries, the engine also writes the work-item bucket Error: LastErrorMessage, LastErrorType, LastErrorStepName, LastErrorStepId, LastErrorDateTime, LastErrorWorkflowName, LastErrorWorkflowId.

Secrets in headers

A secret global variable can supply the HTTP Headers through the gear icon. The value then travels to the host named in the URL. Check the URL before you save: a typo or a Liquid value that changes the host sends your credential to someone else. Never echo a header into the Body or the Response Metadata Key.

Gotchas

Mistakes that bite

  • The routes never run after a failed call. The default Error Behavior is Stop. Set Continue and route on ApiResults.LastHttpStatusCode.
  • Misused header name. HTTP Headers contains Content-Type. Remove it; Body Type sets it.
  • The server receives an empty body. Body Type is Raw, or the verb is GET. Use JSON or Text with POST.
  • Api domain is not valid. The host is local, private or does not resolve. Deploy to a public host.
  • HTTP 400 from your API. A Liquid body inserted a quote or the wrong type ("True" for true). Build JSON with a Javascript preprocessor and JSON.stringify.
  • The status code is stale. A timeout writes nothing, so LastHttpStatusCode keeps an earlier value. Clear it before the call when the work item can pass the step twice.

Worked example: currency conversion

Convert an invoice total with a live exchange rate. An accounts payable team receives invoices in Mexican pesos. Before approval, the workflow converts each total to US dollars with the day's rate.

Assumed fields (case-sensitive):

  • Reads document-level Index.InvoiceTotal, Index.Currency
  • Writes The Custom Step writes Index.InvoiceTotalMXN, Index.FxRate, Index.FxDate, Index.ReviewReason

Step 1: Call External API "Get MXN Rate"

Setting Value
External API URL https://api.frankfurter.dev/v1/latest?base=MXN&symbols=USD
REST Verb GET
Response Metadata Key FxRate
Timeout 30
Error Behavior Continue

After the step, the work item holds:

ApiResults.LastHttpStatusCode = 200
ApiResults.FxRate = {"amount":1.0,"base":"MXN","date":"2026-10-01","rates":{"USD":0.05822}}

Step 2: Custom Step "Convert to USD"

Custom Step: Convert to USD
// Reads ApiResults.FxRate (work item) and Index.InvoiceTotal (each document).
// Writes the USD total and keeps the original for the audit trail.
var api = batch.Metadata["ApiResults"] || {};
var rate = 0;
var rateDate = "";
var rateError = "";

if (api["LastHttpStatusCode"] !== "200") {
  rateError = "FX lookup returned HTTP " + (api["LastHttpStatusCode"] || "none");
} else {
  try {
    var fx = JSON.parse(api["FxRate"] || "");
    rate = parseFloat(fx.rates && fx.rates.USD) || 0;
    rateDate = fx.date || "";
    if (!rate) { rateError = "FX response had no USD rate"; }
  } catch (e) {
    rateError = "FX response was not JSON";
  }
}

function toNumber(s) {
  return parseFloat(String(s || "").replace(/[^0-9.\-]/g, "")) || 0;
}

for (var i = 0; i < batch.Documents.length; i++) {
  var d = batch.Documents[i];
  var index = d.Metadata["Index"] || {};
  var totalMXN = toNumber(index["InvoiceTotal"]);
  var reason = rateError;

  if (!reason && totalMXN <= 0) { reason = "InvoiceTotal missing or zero"; }

  if (!reason) {
    var totalUSD = Math.round(totalMXN * rate * 100) / 100;
    builder.SetDocumentMetadata(d.DocumentId, "Index", "InvoiceTotalMXN", totalMXN.toFixed(2));
    builder.SetDocumentMetadata(d.DocumentId, "Index", "InvoiceTotal", totalUSD.toFixed(2));
    builder.SetDocumentMetadata(d.DocumentId, "Index", "Currency", "USD");
    builder.SetDocumentMetadata(d.DocumentId, "Index", "FxRate", rate.toFixed(6));
    builder.SetDocumentMetadata(d.DocumentId, "Index", "FxDate", rateDate);
  }
  builder.SetDocumentMetadata(d.DocumentId, "Index", "ReviewReason", reason);
}

Test it

  1. Upload one peso invoice.
  2. In Monitor or Insight, open the work item.
  3. Check ApiResults.FxRate on the work item, then Index.InvoiceTotal and Index.InvoiceTotalMXN on the document.

You should see

ApiResults.LastHttpStatusCode = 200, the converted Index.InvoiceTotal in USD, the original in Index.InvoiceTotalMXN, and an empty Index.ReviewReason.

What can go wrong

If the rate service is down, the call fails.

  • Continue With Error Behavior Continue, the Custom Step records the reason in Index.ReviewReason and leaves the total unconverted. Route on that value.
  • Stop With the default Stop, the work item errors instead.

Examples

Copy this into your assistant

Call External API and your own endpoint share one integration context. Copy it from Your Own Endpoint: Copy this into your assistant, and paste it with the AI Assistant Primer. It covers the step's settings, what it writes, and the function pattern.