Saltar al contenido principal

Call an API

Pasohttp-requestcontrolefectos externos

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

De un vistazo​

PropiedadValor
Nombre del pasohttp-request
RecursoClusterStep (lumen.ai/v1alpha1)
Grupo de la paleta, categoríacontrol, connections
Créditos1 crédito cada vez que tiene éxito
Efectos externossí Cambia algo fuera de Lumen, así que un reintento pregunta antes y una prueba muestra lo que haría en lugar de hacerlo.
La instalación debe aportarnada

Entradas​

PropiedadValor
Necesitanada
Producefields
Trabaja sobreitem un documento cada vez

Necesita y Produce son tipos de datos (file, text, fields, email). El editor ofrece un paso solo donde lo que necesita ya está en el camino. Consulta Documentos y datos.

Salidas​

Un nodo posterior se refiere a una salida como {nodeId.field} en un texto, o nodeId.field en una condición.

SalidaTipo
statusnumber
bodystring

More outputs are declared in the setting outputs.

Ajustes​

Se definen bajo config: en el nodo del flujo. Los ajustes de texto pueden contener marcadores de posición como {nodeId.field}.

AjusteTipoValor por defectoDescripción
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[].nameobligatoriostring-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[].jsonPathobligatoriostring-JSONPath finds the value in the answer: $.invoice.total, $.items[0].id.minLength 1

El JSON Schema completo de estos ajustes: http-request.schema.json.

Ejemplo​

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

Úsalo en un flujo​

Un nodo que ejecuta http-request va bajo spec.nodes de un Flow. Dale cualquier id y enumera en next los ids de los nodos siguientes.

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