# HTTP task

An HTTP task calls a web address. It is how a job talks to other systems: tell an application that a file arrived, start a workflow somewhere, fetch a document from an API, upload a file to a service that takes files by HTTP.

## Fields

| Field | What it does | On a new task |
|---|---|---|
| **URL** | the address to call, `http://` or `https://`, with [variables](Jobs-Variables.md) | |
| **Import from cURL** | fills the form from a `curl` command: see [Snippets and the curl import](Jobs-Snippets.md#import-from-curl) | |
| **HTTP Method** | `GET`, `POST`, `PUT`, `PATCH`, `DELETE` … | |
| **POST Data** | the body of the request | |
| **Request Headers** | lines of **Header** and **Value**, added with **Add Header** | |
| **Timeout** | seconds to wait for the answer | 30 |
| **Expected Response Codes** | the answers that count as success, with commas. Any other is a failure. | `200,204` |
| **Only use most recent item.** | one call, for the last item of the list, in place of one per item | off |
| **Don't log HTTP result.** | the answer is not written to the job's log. For answers that hold secrets. | off |
| **Route connection through DMZ when possible** | the call is made from a DMZ server | |

The task makes **one call per item** its filter matches, and one call when the list is empty.

### Signing in

**Authentication**:

| Choice | Fields | Sends |
|---|---|---|
| **None** | | nothing. An API key can still be given as a header. |
| **Username / Password (BASIC)** | **HTTP Username**, **HTTP Password** | the name and password with every call |
| **OAuth Connection Profile** | the profile | a token that the server gets and renews by itself from an OAuth [connection profile](Connection-Profiles.md). In the log: "Adding HTTP header:Authorization: Bearer ****". |
| **AWS Signature (v4)** | **Access Key ID**, **Secret Access Key**, **Region**, **Service**, **Session Token** | each call signed the way Amazon's services want it. Region and service are read from the address when left empty. With no keys on a server that runs at Amazon with a role, the role is used. |

**Do not sign the request body (UNSIGNED-PAYLOAD).** is for S3 only: "every other service rejects it."

### Sending a file

| To send | Do |
|---|---|
| the file itself as the body | write `{file}`, and nothing else, as the **POST Data** |
| the file as a form upload | add the header `Content-Type: multipart/form-data`. The file is sent as a form field, as a browser would. |
| facts about the file | write them: `{"name":"{name}","size":{size}}` with the header `Content-Type: application/json` |

### Keeping the answer

| Field | What it does |
|---|---|
| **Save response to file?** | the answer's body is saved |
| **Local path to save to** | where, as an address: `file:///data/in/{name}.json`. **Browse**, **Test**. |
| **Add local file to list for future tasks.** | the saved file is put on the list |

This is how a job **downloads** by HTTP: a GET with the answer saved.

After each call, the item has:

| Variable | Is |
|---|---|
| `{http_response_code}` | 200, 404 … |
| `{http_response_message}` | the text beside the code |
| `{http_response_log}` | the body of the answer |

A [UserVariable](Task-UserVariable.md) with `{json_parse_start}{http_response_log}{json_parse_end}` turns a JSON answer into variables.

### When it fails, and when there are many

| Field | What it does | On a new task |
|---|---|---|
| **Retry x times on failure** | | 0 |
| **Retry delay** | milliseconds between the tries | 10000 |
| **Maximum of** … **files in** … **seconds before delay of** … **milliseconds.** | a brake: after so many calls within so many seconds, wait. For services that limit how often they may be called. | |

A call that still fails after its retries is not lost. It is put on a waiting list, and the next run of the job tries it first: "QUEUE_RETRY: Starting processing prior failed queue…". The list holds up to 100,000 calls and lives as long as the job engine does; it is not kept over a restart.

## What it hands on

The items it was given, each with the answer's values, and with **Add local file to list**, the saved answers behind them.

## Things to know

- **A failure is by the code.** A service that answers 201 for "created" fails a task that expects `200,204`. Put in what the service's documentation says.
- **Secrets.** Passwords and keys in the sign-in fields are stored encrypted and are masked in the log. A token that you type into a header or the address is not: keep those in a connection profile.
- **Certificates.** An `https://` address is checked like any other outgoing connection of the server: see [Certificate pinning](Security-Certificate-Pinning.md).
- **Limited admins** may call only the hosts their role allows: see [Who may see, change and run a job](Jobs-Access.md).
- **Being called**, the other way round, is the server's own [API](API.md) and the [webhooks](API-Events-and-Webhooks.md).
