api icon

Send (Enqueue) AS2 Message

Request

Sending a Single File

POST /:v/message/:as2_station_id/:as2_partner_id
Authorization: <token_string>
Content-Type: <mime_type_of_file>
Content-Length: <size_of_file>
Name: <name_of_file>

<content_of_file> goes in the request body

Sending Multiple Files

POST /:v/message/:as2_station_id/:as2_partner_id
Authorization: <token_string>
Content-Type: multipart/form-data; boundary=<multipart_boundary>

--<multipart_boundary>
Content-Disposition: form-data; name="file"; filename=<name_of_file_1>
Content-Type: <mime_type_of_file_1>

<content_of_file_1>
--<multipart_boundary>
Content-Disposition: form-data; name="file"; filename=<name_of_file_2>
Content-Type: <mime_type_of_file_2>

<content_of_file_2>
--<multipart_boundary>--

Path Parameters

  • :as2_station_id: AS2 identifier of the AS2 Station from which you want to send the AS2 message out

  • :as2_partner_id: AS2 identifier of the AS2 Partner to which you want to send the AS2 message out

Query Parameters (Optional)

  • partnerType: Possible values: production and test. If unspecified, defaults to production.

  • subject: Any subject string can be used

Request Payload

Single File

Include the raw content of the file as the payload (similar to how curl --data-binary @path/to/file works).

Also specify the following request headers, which provide mandatory metadata about the file:

  • Name: name of the file that you are sending (e.g. invoice-12345.edi); what you provide here will be the name of the file received on the partner’s side.

  • Content-Type: MIME type of the file (e.g. text/xml for XML, application/edi-consent for EDI, etc. If you do not know the MIME type and are not interested in including that information in the message, you may use the generic type application/octet-stream.

  • Content-Length: The size (number of bytes) of the file that you are sending (e.g. 94813)

Many common tools and programming libraries will automatically compute and include the last two headers on your behalf, if you use their "upload file" functionality. In such cases you would only need to include the Name header explicitly.
In some cases, AS2 Gateway may decide to override the MIME type (Content-Type) that you specify, if it detects that the content of the uploaded file is of a different MIME type.

Multiple Files: multipart/form-data

A multipart payload containing one or more "file" parts (attachment payloads to be sent). Each attachment must have a unique filename.

You can add up to 10 files per message, adding up to a total size of 10 MB.

Response

202 Accepted
Content-Type: application/json
Link: https://api.as2gateway.com/v1/message/sent/<90766548.41.1573209810390@as2gateway.com>

{
    "message": "Successfully added a new outbound entry"
}

Response Headers

Link: An absolute URL to the AS2 message which will be created after the outgoing message entry is processed. Therefore the resource in this URL may not be available immediately after the response for this API call is returned. It would be better to wait around 5 to 10 seconds before querying for the resource represented in the Link header value.

Note that the header includes the AS2 message ID for this outgoing message entry.

Examples

Sending a Single File

If you are generating the content (i.e. there is no actual local file):

curl -XPOST https://api.as2gateway.com/v1/message/RJ_Station/RJ_Partner \
    -H "Authorization: <token_string>" \
    -H "Name: invoice_20200101.xml" \
    -H "Content-Type: text/xml" \
    -H "Content-Length: 132" \
    --data-binary \
'<?xml version="1.0" encoding="UTF-8"?>
<invoice>
<items total="1000">
<item sku="10344" qty="10" total="1000"/>
</items>
</invoice>
'

If you are sending an already generated/existing file:

curl -XPOST https://api.as2gateway.com/v1/message/RJ_Station/RJ_Partner \
    -H "Authorization: <token_string>" \
    -H "Name: invoice_20200101.xml" \
    -H "Content-Type: text/xml" \
    --data-binary @invoice_20200101.xml

Sending Two (or More) Files

curl -XPOST https://api.as2gateway.com/v1/message/RJ_Station/RJ_Partner \
    -H "Authorization: <token_string>" \
    -H "Content-Type: multipart/form-data; boundary=----foobarbaz" \
    --data-binary \
'------foobarbaz
Content-Disposition: form-data; name="file"; filename="file1.txt"
Content-Type: text/plain

one
------foobarbaz
Content-Disposition: form-data; name="file"; filename="file2.txt"
Content-Type: text/plain

two
------foobarbaz--'

Queueing (asynchronous) nature

Please note that, similar to the AS2 Gateway web dashboard, this simply places the newly submitted message into a queue, in a to-be-sent state; it may take several seconds before the message actually gets sent out.

Additionally, if the actual send action fails, the message will not appear under the sent messages category; and the URL previously returned in the Link header would no longer be valid. In such cases it is advised to check failed and queued categories to find out the current status of the message.

In this topic
In this topic