# As4 task

An As4 task exchanges files with an AS4 partner through one of the server's partner agreements: it sends them now, queues them for the partner to collect, or collects what the partner holds for you. Everything about the partner, the keys, the certificates and the profile is in the agreement (Preferences › AS4); the task only names it. The keys never leave the server.

This page is about the task. AS4 on the server, the station, the agreements and receiving, is in [AS4](AS4.md).

AS4 is an add-on (Business with the AS4 add-on, and Enterprise). The task is not offered on a CrushMFT Orchestrator.

## Fields

| Field | What it does | On a new task |
|---|---|---|
| **Partner agreement** | the id of an agreement in Preferences › AS4 › Partners. Variables are allowed. | |
| **Mode** | **Send**, **Queue for the partner to pull** or **Pull from the partner** (below) | Send |
| **All files in one message** | on: the task's files travel as the parts of one message. Off: one message per file. | off |
| **MIME type** | the type each part is labelled with | empty: from the file name |
| **ConversationId** | ties messages together for the partner. Variables are allowed. | empty: a new one per message |
| **At most this many messages a pull** | Pull only: stops after this many even when the partner holds more | 100 |

## The modes

### Send

The files go to the partner's address now, signed and encrypted as the agreement says. The task waits for the receipt and resends until it comes (5 resends, a minute apart and doubling, at most an hour). A file sent goes on to the next task with these variables:

| Variable | Holds |
|---|---|
| `as4_status` | `DONE` |
| `as4_message_id` | the message's id |
| `as4_receipt_message_id` | the id of the partner's receipt |
| `as4_detail` | the receipt check's words |

A refusal, or no receipt after every resend, ends the task in error with the partner's error code (such as `EBMS:0101`), so the job's failure path runs.

### Queue for the partner to pull

The files are packaged now, signed and encrypted for the partner, and wait on the server until the partner asks for them with a signed pull request. The agreement must have **They may pull what an As4 task queues for them** on; the message waits on the agreement's MPC. The file goes on with `as4_status` `QUEUED` and its `as4_message_id`. What happened later, pulled and receipted or not, is in Preferences › AS4 › Messages.

### Pull from the partner

The task asks the partner's address for what it holds for you on the agreement's MPC, one message after another until there is nothing more. Each message is checked, receipted and delivered as a received one (into the agreement's delivery user and folder), and each file goes on to the next task as a new item with its `url`, `as4_message_id` and `as4_partner`. The task's own items pass through unchanged. Put the task in a job with a schedule to collect regularly.

## Where the task runs

The server packages and sends the message, so it must be able to read the files. A file on another kind of storage (S3, SFTP ...) is copied to a temporary file first. A job that runs on a remote job engine on another machine cannot hand over its local files.
