Zum Hauptinhalt springen

Call an API

Schritthttp-requestcontrolexterne Wirkung

Sends a request to an API and uses its answer in the steps after it.

Auf einen Blick​

EigenschaftWert
Schrittnamehttp-request
RessourceClusterStep (lumen.ai/v1alpha1)
Palettengruppe, Kategoriecontrol, connections
Credits1 Credit bei jedem Erfolg
Externe Wirkungja Er ändert etwas außerhalb von Lumen, deshalb fragt ein Wiederholungsversuch vorher nach, und ein Test zeigt, was er tun würde, statt es zu tun.
Die Installation muss bereitstellennichts

Eingaben​

EigenschaftWert
Brauchtnichts
Liefertfields
Arbeitet aufitem einem Dokument nach dem anderen

Braucht und Liefert sind Datentypen (file, text, fields, email). Der Editor bietet einen Schritt nur dort an, wo das, was er braucht, schon auf dem Pfad liegt. Siehe Dokumente und Daten.

Ausgaben​

Ein späterer Knoten verweist auf eine Ausgabe als {nodeId.field} in einem Text oder als nodeId.field in einer Bedingung.

AusgabeTyp
statusnumber
bodystring

More outputs are declared in the setting outputs.

Einstellungen​

Wird unter config: im Knoten des Flows gesetzt. Texteinstellungen dürfen Platzhalter wie {nodeId.field} enthalten.

EinstellungTypStandardwertBeschreibung
connectorRefstring-ConnectorRef names the HTTP Connector this call goes through: its base address, its default headers and its credentials. Without it the call needs a URL, and may carry no credentials.minLength 1
urlstring-URL is the full address, for a public API that needs no credentials. With a ConnectorRef, Path says where under its base address instead.minLength 1
methodstring"GET"one of GET, POST, PUT, PATCH, DELETE
pathstring-Path is appended to the Connector's base address: /invoices/{n1.id}.
querymap of string-
headersmap of string-Headers are sent as given, over the Connector's default headers. Credentials do not belong here: the Connector adds them.
bodyTypestring"json"BodyType is how Body or Form is sent: json (the default), text or form.one of json, text, form
bodystring-Body is a template, sent as is after placeholders are filled; for a JSON body the result must be JSON.
formmap of string-Form is the fields of a form body (bodyType form).
idempotencyKeystring-IdempotencyKey is sent as the Idempotency-Key header, so a retried step does not repeat a side effect on an API that honours it.minLength 1
timeoutSecondsinteger20TimeoutSeconds is how long one request may take; 20 by default, 60 at most.minimum 1; maximum 60
expectlist of integer-Expect lists the statuses that are a success; any 2xx by default.minItems 1
outputslist of object-Outputs map values of the JSON answer to fields. The answer's status and (truncated) body are always fields too.
outputs[].nameerforderlichstring-Name is the field the value becomes, for the steps after this one.maxLength 64; pattern `^[A-Za-z][A-Za-z0-9_]*$`
outputs[].typestring"string"Type is what the value is. It decides how later steps compare it.one of string, number, date, money, boolean
outputs[].jsonPatherforderlichstring-JSONPath finds the value in the answer: $.invoice.total, $.items[0].id.minLength 1

Das vollständige JSON Schema dieser Einstellungen: http-request.schema.json.

Beispiel​

config
body: '{"number": "{invoiceNumber}", "total": {total}}'
bodyType: json
method: POST
url: https://api.example.co.il/invoices

Im Flow verwenden​

Ein Knoten, der http-request ausführt, steht unter spec.nodes eines Flow. Geben Sie ihm eine beliebige id und nennen Sie in next die ids der nächsten Knoten.

flow.yaml
apiVersion: lumen.ai/v1alpha1
kind: Flow
metadata:
name: http-request-example
namespace: tenant-acme
spec:
displayName: "Call an API"
triggers:
- id: start
ref: {name: manual-run}
next: [http-request]
nodes:
- id: http-request
stepRef: {name: http-request}
config:
body: '{"number": "{invoiceNumber}", "total": {total}}'
bodyType: json
method: POST
url: https://api.example.co.il/invoices