# Blocworx Gateway

The Blocworx Gateway Field is designed to send requests to API and then use the response in the bloc. This is useful for gathering information to fill fields in the bloc.

{% hint style="info" %}
The default behavior is when the Blocworx Gateway field is triggered, a POST request of multipart/form-data will be sent to the API.
{% endhint %}

### Initial Field Parameters

| Parameter                                                      | Description                                                                                                                                                                                                           |
| -------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Gateway URL                                                    | <p>This is the URL of the API. </p><p></p>                                                                                                                                                                            |
| Send your current Auth Token with the request                  | If this field is selected the authenticated user's token will be sent in the request.                                                                                                                                 |
| Show the original response from the API in the browser console | Tick if you want to see the original API response and not the blocworx response.                                                                                                                                      |
| Select GET or POST                                             | This option is to change the request action.                                                                                                                                                                          |
| Choose when trigger the gateway                                | This option is to choose when to trigger the request. The current options are when submitting the form, editing a field, or manually using a created button.                                                          |
| Choose actions with the response                               | The current options are to populate the fields in the form using the data of the API response and to trigger rules on populated fields.                                                                               |
| Field to Trigger the request                                   | This option is to choose which fields in the bloc will trigger the request to the API.                                                                                                                                |
| Select Frequency                                               | If the 'Run On Schedule' trigger option is selected above, you can use this dropdown to select how often you want to trigger the request.                                                                             |
| Blocworx Gateway Conditions (local field and value to compare) | These are the conditions that must occur in order to trigger the request. It uses the value in the local field (the field on the bloc you are on) and compares it to the value entered based on the condition chosen. |
| Add Header                                                     | This option is to enable the user to include any necessary header with the request. It is possible to choose between a set of pre-defined options and type the desired value.                                         |
| Body Request                                                   | This allows the user to specify a Body to send custom information with the Request                                                                                                                                    |

### An example of how to build the gateway API to translate texts.

In the gateway URL, write the endpoint of the API. e.g. <https://microsoft-translator-text>

<figure><img src="https://1186088597-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MSr2uF2m-DtSpCxknCK-887967055%2Fuploads%2FEQY1byBWfMe3mSXx1gHO%2Fimage.png?alt=media&#x26;token=0110f3cc-8b76-4c03-a343-1f0d5e5bb607" alt=""><figcaption><p>Example of gateway URL</p></figcaption></figure>

Choose if the action is a post or a get

<figure><img src="https://1186088597-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MSr2uF2m-DtSpCxknCK-887967055%2Fuploads%2FqOvf6Ppw1qA5gr3gVGJ7%2Fimage.png?alt=media&#x26;token=37f63c32-f0d2-4dfa-bc22-1154d9195c90" alt=""><figcaption><p>Example of request action</p></figcaption></figure>

Choose when the gateway is triggered, in this example, we are using a button to do it. It's also possible to choose the name and color of the button.

<figure><img src="https://1186088597-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MSr2uF2m-DtSpCxknCK-887967055%2Fuploads%2Fe1uJHhI8oX0HKHTdBjxo%2Fimage.png?alt=media&#x26;token=600cb71e-3d53-4fe4-8964-8561435c10ce" alt=""><figcaption><p>Example how to trigger the gateway API</p></figcaption></figure>

Add headers that are required to call the API properly. e.g. content-type: application/JSON.

<figure><img src="https://1186088597-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MSr2uF2m-DtSpCxknCK-887967055%2Fuploads%2FAyV0KQjPJAiRICyucDUE%2Fimage.png?alt=media&#x26;token=24cd6c99-d367-48db-9ece-63f391c322a0" alt=""><figcaption><p>Example of Header</p></figcaption></figure>

{% hint style="info" %}
You may add as many headers are necessary to call the API properly.
{% endhint %}

Finally, add the request body that is going to be sent using the gateway API.&#x20;

e.g. \[{text: \[BW]Text\[/BW]}].

<figure><img src="https://1186088597-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MSr2uF2m-DtSpCxknCK-887967055%2Fuploads%2FuBFU023zvNp2g6UtjjlN%2Fimage.png?alt=media&#x26;token=f45a013a-fe23-43bd-9ece-b24de489f561" alt=""><figcaption><p>Example of the Request's Body</p></figcaption></figure>

{% hint style="info" %}
In the request body field, the user should use the pattern \[BW]field\_slug\[/BW] that will be changed to the value in the chosen field before calling the API.

It's possible to click in the desired field that shows when you click in *"Click to view fields to add"* and the pattern will be automatically added to the request's body.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://manual.blocworx.com/blocworx-documentation/bloc-editor/fields-tools-and-charts/third-party-integration-components/blocworx-gateway.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
