# REST API - Post

This function block sends JSON POST requests to a HTTP server address and returns the server response. It is designed for integration with external REST APIs while keeping the user interface responsive.

## 📥 Inputs <a href="#inputs" id="inputs"></a>

`Enable Condition` — Logic signal to start a POST request when True.

`Server Address` — Text input for the full server endpoint (use full URL starting with http\:// or https\://).

`Response Data ID` — Optional key name to extract a specific field from a JSON response.

`Post Data` — Generic data payload that will be sent as JSON in the request body.

## 📤 Outputs <a href="#outputs" id="outputs"></a>

`Status Code` — HTTP status code returned by the server.

`Error` — Error message or reason when the request fails.

`Response` — Server response body or the extracted value when `Response Data ID` is provided.

## 🕹️ Controls <a href="#controls" id="controls"></a>

`Timeout (s)` — Number of seconds to wait before the request times out (adjust to suit slow/fast servers).

## 🎨 Features <a href="#features" id="features"></a>

* Asynchronous requests: POST operations run in the background so the interface remains responsive.
* Optional response parsing: If you provide a `Response Data ID` the block will attempt to return that specific field from a JSON response.
* Simple integration: Accepts a generic payload so you can send images, numbers, text or structured data prepared by other blocks.

## ⚙️ Running mechanism <a href="#running-mechanism" id="running-mechanism"></a>

When `Enable Condition` is True and a valid `Server Address` is provided, the block sends a POST request with the `Post Data` payload. The request uses the configured `Timeout (s)` and runs without blocking the UI. When the server responds, the block updates its outputs with `Status Code`, `Error` (if any), and `Response` (or the selected response field).

## 📝 Usage instructions <a href="#usage" id="usage"></a>

1. Provide the target endpoint in `Server Address` (include http\:// or https\://).
2. Connect or prepare the payload on the `Post Data` input (use other blocks to build structured data if needed).
3. Use a logic signal on `Enable Condition` to trigger sending (e.g., manual toggle or a conditional block).
4. Optionally set `Response Data ID` to extract a specific field from the server's JSON response.
5. Adjust `Timeout (s)` if the server is slow or to avoid long waits.

## 💡 Tips and Tricks <a href="#tips-and-tricks" id="tips-and-tricks"></a>

* Use `Logic Input` or `Rising Edge` to control when the request is sent (single-shot triggers or manual control).
* Prepare structured payloads with `Data to JSON` before feeding into `Post Data` for reliable JSON formatting.
* Use `String Input` to provide the `Server Address` or `Number Input` for numeric fields inside the payload.
* Log or persist responses with `CSV Export` or `Image Logger` (if your payload/response contains images or timestamps).
* Pair with `REST API - Get` when you need both POST and GET interactions with the same service (e.g., send data then poll for results).
* Include `Date-Time` or `Date-Time List` in your payload to timestamp requests.
* Use `Debug Input` to inspect the request payload or server response during development.

## 🛠️ Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

* No response / network error: Verify that `Server Address` is correct, reachable from the machine, and includes the protocol (http/https). Check firewall or network settings.
* Authentication required: Ensure the target API accepts unauthenticated POSTs or add whatever authentication the service needs outside of this block (e.g., via headers managed by the server).
* Invalid JSON or unexpected response: Use `Data to JSON` to ensure payload is valid JSON, and check the API documentation for expected field names. If you requested a specific `Response Data ID` and the field is missing, the `Response` output may be empty.
* Timeouts: Increase `Timeout (s)` for slow endpoints or check server load. If requests frequently time out, test the service separately to confirm responsiveness.
* Repeated triggers: If you only want to send a single POST per event, use `Rising Edge` to convert a continuous True signal into a single trigger.

If you need examples of how to chain this block with data formatting, logging or trigger controls, combine it with blocks such as `Data to JSON`, `Logic Input`, `Rising Edge`, `CSV Export`, and `REST API - Get` for common integration patterns.
