# קריאה ל-API

> שולח בקשה ל-API ומשתמש בתשובה שלו בשלבים שאחריו.

Source: https://docs.go-lumen.ai/he/reference/steps/http-request

## במבט אחד

| מאפיין | ערך |
| --- | --- |
| **שם השלב** | `http-request` |
| **משאב** | ClusterStep (`lumen.ai/v1alpha1`) |
| **קבוצה וקטגוריה** | control, connections |
| **קרדיטים** | **1** קרדיט בכל פעם שהוא מצליח |
| **השפעה חיצונית** | כן: הוא משנה משהו מחוץ ל-Lumen, ולכן ניסיון חוזר שואל קודם, ובדיקה מראה מה הוא היה עושה במקום לעשות את זה. |
| **ההתקנה צריכה לספק** | כלום |

## קלט

| מאפיין | ערך |
| --- | --- |
| **צריך** | כלום |
| **מפיק** | `fields` |
| **עובד על** | item: מסמך אחד בכל פעם |

״צריך״ ו״מפיק״ הם סוגי נתונים (file, text, fields, email). העורך מציע שלב רק במקום שבו מה שהוא צריך כבר נמצא במסלול. ראו [מסמכים ונתונים](https://docs.go-lumen.ai/he/concepts/how-flows-run.md#documents-and-data).

## פלט

צומת מאוחר יותר מפנה לפלט כ-`{nodeId.field}` בטקסט, או כ-`nodeId.field` בתנאי.

| פלט | סוג |
| --- | --- |
| `status` | number |
| `body` | string |

More outputs are declared in the setting `outputs`.

## הגדרות

מגדירים תחת `config:` בצומת של התהליך. הגדרות טקסט יכולות להכיל מצייני מקום כמו `{nodeId.field}`.

| הגדרה | סוג | ברירת מחדל | תיאור |
| --- | --- | --- | --- |
| `connectorRef` | string |  | 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) |
| `url` | string |  | 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) |
| `method` | string | `"GET"` | (one of GET, POST, PUT, PATCH, DELETE) |
| `path` | string |  | Path is appended to the Connector's base address: /invoices/`{n1.id}`. |
| `query` | map of string |  |  |
| `headers` | map of string |  | Headers are sent as given, over the Connector's default headers. Credentials do not belong here: the Connector adds them. |
| `bodyType` | string | `"json"` | BodyType is how Body or Form is sent: json (the default), text or form. (one of json, text, form) |
| `body` | string |  | Body is a template, sent as is after placeholders are filled; for a JSON body the result must be JSON. |
| `form` | map of string |  | Form is the fields of a form body (bodyType form). |
| `idempotencyKey` | string |  | 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) |
| `timeoutSeconds` | integer | `20` | TimeoutSeconds is how long one request may take; 20 by default, 60 at most. (minimum 1; maximum 60) |
| `expect` | list of integer |  | Expect lists the statuses that are a success; any 2xx by default. (minItems 1) |
| `outputs` | list of object |  | Outputs map values of the JSON answer to fields. The answer's status and (truncated) body are always fields too. |
| `outputs[].name` (חובה) | string |  | Name is the field the value becomes, for the steps after this one. (maxLength 64; pattern \`^\[A-Za-z\]\[A-Za-z0-9\_\]\*$\`) |
| `outputs[].type` | string | `"string"` | Type is what the value is. It decides how later steps compare it. (one of string, number, date, money, boolean) |
| `outputs[].jsonPath` (חובה) | string |  | JSONPath finds the value in the answer: $.invoice.total, $.items\[0\].id. (minLength 1) |

ה-JSON Schema המלא של ההגדרות: [http-request.schema.json](https://docs.go-lumen.ai/schemas/steps/http-request.schema.json).

## דוגמה

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

## שימוש בתהליך

צומת שמריץ את `http-request` נכנס תחת `spec.nodes` של [Flow](https://docs.go-lumen.ai/he/concepts/how-flows-run.md#the-flow-as-yaml). תנו לו כל מזהה, ורשמו ב-next את מזהי הצמתים הבאים.

```yaml title="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
```
