Messages API
The Messages API handles all AS2 message operations including sending, receiving, tracking, and payload management.
Table of Contents
Send Message
Send an AS2 message to a trading partner.
POST /v1/messages
Request Parameters
Required Parameters
Parameter | Type | Constraints | Description |
---|
partner_id | string | Valid partner ID | Target trading partner |
payload.content | string | Non-empty | Message content (base64 for binary) |
content_type | string | Valid MIME type | Content type of the payload |
Optional Parameters
Parameter | Type | Default | Constraints | Description |
---|
subject | string | null | 1-255 characters | Message subject line |
payload.filename | string | null | 1-255 characters | Original filename |
payload.encoding | enum | utf-8 | utf-8 , base64 | Payload encoding |
headers | object | {} | Key-value pairs | Custom AS2 headers |
priority | enum | normal | low , normal , high | Processing priority |
compress | boolean | Partner default | - | Override compression setting |
encrypt | boolean | Partner default | - | Override encryption setting |
sign | boolean | Partner default | - | Override signing setting |
mdn_mode | enum | Partner default | sync , async , none | MDN delivery mode |
scheduled_at | datetime | null | Future timestamp | Schedule message delivery |
Request Examples
JSON Payload
{
"partner_id": "prt_000001",
"subject": "Purchase Order #PO-2024-001",
"payload": {
"content": "ISA*00* *00* *ZZ*SENDER *ZZ*RECEIVER *240115*1030*U*00401*000000001*0*T*>~",
"filename": "po-2024-001.edi"
},
"content_type": "application/edi-x12",
"headers": {
"Document-Type": "PurchaseOrder",
"Document-ID": "PO-2024-001"
},
"priority": "high",
"compress": true
}
curl -X POST https://api.as2aas.com/v1/messages \
-H "Authorization: Bearer pk_live_your_api_key" \
-F "partner_id=prt_000001" \
-F "subject=Invoice #INV-2024-001" \
-F "[email protected]" \
-F "content_type=application/edi-x12" \
-F "priority=normal"
Response
Success Response (202 Accepted)
Field | Type | Description |
---|
message | string | Success message |
data | object | Message object |
data.id | string | Unique message identifier |
data.message_id | string | AS2 message ID |
data.partner | object | Partner information |
data.status | enum | Current message status |
data.direction | enum | Message direction |
data.subject | string | Message subject |
data.content_type | string | Payload content type |
data.bytes | integer | Payload size in bytes |
data.mdn_mode | enum | MDN delivery mode |
data.created_at | datetime | Message creation timestamp |
{
"message": "Message queued for delivery",
"data": {
"id": "msg_000001",
"message_id": "MSG_20240115_103000_ABC123",
"partner": {
"id": "prt_000001",
"name": "Acme Corporation",
"as2_id": "ACME-CORP-AS2"
},
"status": "queued",
"direction": "outbound",
"subject": "Purchase Order #PO-2024-001",
"content_type": "application/edi-x12",
"bytes": 1024,
"compressed": true,
"encrypted": true,
"signed": true,
"mdn_mode": "async",
"created_at": "2024-01-15T10:30:00.000000Z"
}
}
List Messages
Retrieve paginated list of messages with optional filtering.
GET /v1/messages
Query Parameters
Parameter | Type | Default | Constraints | Description |
---|
partner_id | string | null | Valid partner ID | Filter by trading partner |
status | enum | null | Valid status code | Filter by message status |
direction | enum | null | inbound , outbound | Filter by message direction |
from_date | datetime | null | ISO 8601 format | Start date filter |
to_date | datetime | null | ISO 8601 format | End date filter |
search | string | null | 1-255 characters | Search subjects and message IDs |
content_type | string | null | Valid MIME type | Filter by content type |
page | integer | 1 | Minimum 1 | Page number |
per_page | integer | 20 | 1-100 | Items per page |
Response Schema
Field | Type | Description |
---|
data | array | Array of message objects |
pagination | object | Pagination metadata |
Message Object Fields
Field | Type | Description |
---|
id | string | Message identifier |
message_id | string | AS2 message ID |
partner | object | Partner information |
status | enum | Message status |
direction | enum | inbound or outbound |
from_as2_id | string | Sender AS2 ID |
to_as2_id | string | Recipient AS2 ID |
subject | string | Message subject |
content_type | string | Payload MIME type |
bytes | integer | Payload size |
compressed | boolean | Compression applied |
encrypted | boolean | Encryption applied |
signed | boolean | Digital signature applied |
mdn_mode | enum | MDN delivery mode |
mdn_status | enum | MDN status |
attempts | integer | Transmission attempts |
sent_at | datetime | Transmission timestamp |
delivered_at | datetime | Delivery confirmation timestamp |
created_at | datetime | Creation timestamp |
updated_at | datetime | Last update timestamp |
Get Message Details
Retrieve detailed information about a specific message.
GET /v1/messages/{message_id}
Path Parameters
Parameter | Type | Required | Description |
---|
message_id | string | Yes | Message identifier |
Response
Success Response (200 OK)
{
"data": {
"id": "msg_000001",
"message_id": "MSG_20240115_103000_ABC123",
"partner": {
"id": "prt_000001",
"name": "Acme Corporation",
"as2_id": "ACME-CORP-AS2",
"url": "https://acme.example.com/as2"
},
"status": "delivered",
"direction": "outbound",
"from_as2_id": "YOUR-AS2-ID",
"to_as2_id": "ACME-CORP-AS2",
"subject": "Purchase Order #PO-2024-001",
"content_type": "application/edi-x12",
"bytes": 1024,
"compressed": true,
"encrypted": true,
"signed": true,
"mdn_mode": "async",
"mdn_status": "received",
"mdn_data": {
"disposition": "automatic-action/MDN-sent-automatically; processed",
"received_content_mic": "abc123def456ghi789jkl012mno345",
"reporting_ua": "Acme AS2 Server/1.0",
"original_message_id": "MSG_20240115_103000_ABC123"
},
"attempts": 1,
"last_attempt_at": "2024-01-15T10:30:15.000000Z",
"sent_at": "2024-01-15T10:30:15.000000Z",
"delivered_at": "2024-01-15T10:30:45.000000Z",
"created_at": "2024-01-15T10:30:00.000000Z",
"updated_at": "2024-01-15T10:30:45.000000Z"
}
}
Download Message Payload
Download the original message payload content.
GET /v1/messages/{message_id}/payload
Path Parameters
Parameter | Type | Required | Description |
---|
message_id | string | Yes | Message identifier |
Response
Success Response (200 OK)
Returns the original payload content with appropriate Content-Type header.
Response Headers:
Header | Description |
---|
Content-Type | Original payload MIME type |
Content-Length | Payload size in bytes |
Content-Disposition | attachment; filename="original_filename" |
X-Payload-Compressed | true if payload was compressed |
X-Payload-Encrypted | true if payload was encrypted |
Message Status Codes
Status Progression
Status | Description | Next Possible Status |
---|
queued | Message accepted and queued for processing | processing , failed |
processing | Message preparation and transmission in progress | sent , failed |
sent | Message successfully transmitted to partner | delivered , failed |
delivered | MDN received confirming successful delivery | Final state |
failed | Message transmission or processing failed | Final state |
received | Inbound message received from partner | Final state |
MDN Status Codes
MDN Status | Description |
---|
none | No MDN requested |
pending | MDN requested but not yet received |
received | MDN successfully received |
failed | MDN delivery failed |
timeout | MDN not received within timeout period |
Error Codes
Message-Specific Error Codes
Error Code | HTTP Status | Description | Resolution |
---|
PARTNER_NOT_FOUND | 404 | Specified partner does not exist | Verify partner ID or create partner |
PARTNER_INACTIVE | 400 | Partner is deactivated | Activate partner before sending |
PAYLOAD_TOO_LARGE | 413 | Message exceeds size limit | Reduce payload size or enable compression |
INVALID_CONTENT_TYPE | 400 | Unsupported content type | Use supported MIME type |
ENCRYPTION_FAILED | 400 | Cannot encrypt message | Check partner encryption certificate |
SIGNING_FAILED | 400 | Cannot sign message | Check identity signing certificate |
PARTNER_UNREACHABLE | 400 | Cannot connect to partner endpoint | Verify partner URL and connectivity |
INVALID_AS2_HEADERS | 400 | AS2 headers validation failed | Check AS2 ID configuration |
MDN_TIMEOUT | 408 | MDN not received within timeout | Check partner MDN configuration |
CERTIFICATE_EXPIRED | 400 | Required certificate has expired | Renew expired certificates |
Transmission Error Details
{
"error": {
"type": "transmission_error",
"code": "PARTNER_UNREACHABLE",
"message": "Cannot establish connection to partner endpoint",
"details": {
"partner_id": "prt_000001",
"endpoint_url": "https://partner.example.com/as2",
"timeout_seconds": 60,
"last_attempt": "2024-01-15T10:30:00.000000Z",
"error_details": "Connection timeout after 60 seconds"
}
}
}
Message Filtering
Advanced Filtering Options
Filter | Type | Format | Description |
---|
status | enum | Single value | Filter by message status |
direction | enum | Single value | Filter by message direction |
partner_id | string | Partner ID | Filter by specific partner |
from_date | datetime | ISO 8601 | Messages created after date |
to_date | datetime | ISO 8601 | Messages created before date |
content_type | string | MIME type | Filter by content type |
has_errors | boolean | true/false | Messages with transmission errors |
mdn_status | enum | MDN status | Filter by MDN status |
encrypted | boolean | true/false | Filter encrypted messages |
signed | boolean | true/false | Filter signed messages |
Complex Query Example
GET /v1/messages?partner_id=prt_000001&status=delivered&from_date=2024-01-01T00:00:00Z&to_date=2024-01-31T23:59:59Z&encrypted=true&per_page=50
Payload Handling
Content Encoding
Encoding | Usage | Description |
---|
utf-8 | Text content | Default for text-based formats |
base64 | Binary content | Required for binary files |
Content Type Mapping
Content Type | File Extensions | Encoding | Description |
---|
application/edi-x12 | .edi , .x12 | utf-8 | X12 EDI documents |
application/edifact | .edi | utf-8 | EDIFACT documents |
application/xml | .xml | utf-8 | XML business documents |
application/json | .json | utf-8 | JSON structured data |
text/plain | .txt | utf-8 | Plain text files |
text/csv | .csv | utf-8 | Comma-separated values |
application/pdf | .pdf | base64 | PDF documents |
application/zip | .zip | base64 | ZIP archives |
image/png | .png | base64 | PNG images |
image/jpeg | .jpg , .jpeg | base64 | JPEG images |
Size Limitations
Plan | Maximum Size | Compression | Notes |
---|
Free | 50 MB | Available | Suitable for standard EDI documents |
Starter | 100 MB | Available | Handles larger business documents |
Professional | 500 MB | Available | Supports high-volume transactions |
Enterprise | 2 GB | Available | Custom limits available |
Message Security
Encryption Configuration
Algorithm | Key Size | Security Level | Compatibility |
---|
3DES | 168-bit | Low | Legacy systems |
AES128_CBC | 128-bit | Standard | Most systems |
AES192_CBC | 192-bit | Enhanced | Modern systems |
AES256_CBC | 256-bit | High | Security-focused systems |
Signing Configuration
Algorithm | Key Size | Security Level | Compatibility |
---|
SHA1withRSA | 1024+ bit | Low | Legacy compatibility |
SHA256withRSA | 2048+ bit | Standard | Recommended |
SHA384withRSA | 2048+ bit | Enhanced | High security |
SHA512withRSA | 2048+ bit | High | Maximum security |
AS2 Protocol Details
Header | Type | Required | Description |
---|
AS2-From | string | Yes | Sender AS2 identifier |
AS2-To | string | Yes | Recipient AS2 identifier |
Message-ID | string | Yes | Unique message identifier |
AS2-Version | string | Yes | AS2 protocol version (1.0) |
Content-Type | string | Yes | Message content type |
Content-Disposition | string | No | Filename information |
Disposition-Notification-To | string | Conditional | MDN delivery address |
Disposition-Notification-Options | string | Conditional | MDN options |
MDN (Message Disposition Notification)
MDN Modes
Mode | Description | Response Time | Use Case |
---|
sync | Synchronous MDN | Immediate | Real-time confirmation needed |
async | Asynchronous MDN | Delayed | Standard business messaging |
none | No MDN | N/A | Fire-and-forget messaging |
MDN Data Structure
Field | Type | Description |
---|
disposition | string | MDN disposition value |
received_content_mic | string | Message integrity check value |
reporting_ua | string | Reporting user agent |
original_message_id | string | Original message identifier |
final_recipient | string | Final recipient AS2 ID |
Webhook Integration
Message Events
Event | Trigger Condition | Data Included |
---|
message.queued | Message accepted for processing | Message object |
message.sent | Message transmitted to partner | Message object with transmission details |
message.delivered | MDN received confirming delivery | Message object with MDN data |
message.failed | Message transmission failed | Message object with error details |
message.received | Inbound message received | Message object with sender details |
Webhook Payload Structure
{
"event": "message.delivered",
"data": {
"id": "msg_000001",
"message_id": "MSG_20240115_103000_ABC123",
"partner": {
"id": "prt_000001",
"name": "Acme Corporation",
"as2_id": "ACME-CORP-AS2"
},
"status": "delivered",
"direction": "outbound",
"mdn_data": {
"disposition": "automatic-action/MDN-sent-automatically; processed",
"received_content_mic": "abc123def456ghi789",
"reporting_ua": "Partner AS2 Server/2.1"
},
"delivered_at": "2024-01-15T10:30:45.000000Z"
},
"timestamp": "2024-01-15T10:30:45.000000Z",
"api_version": "v1"
}
Request Optimization
Optimization | Implementation | Benefit |
---|
Pagination | Use appropriate per_page values | Reduces response size |
Filtering | Apply specific filters | Reduces data transfer |
Field Selection | Request only needed fields | Faster responses |
Compression | Enable gzip compression | Reduces bandwidth |
Concurrent Requests
Plan | Maximum Concurrent | Recommended | Notes |
---|
Free | 5 | 3 | Basic concurrent operations |
Starter | 10 | 7 | Standard business usage |
Professional | 25 | 20 | High-volume operations |
Enterprise | Custom | Custom | Tailored to requirements |
Integration Patterns
Synchronous Processing
// Direct message sending with immediate response
const response = await fetch('https://api.as2aas.com/v1/messages', {
method: 'POST',
headers: {
'Authorization': 'Bearer pk_live_your_api_key',
'Content-Type': 'application/json',
'Idempotency-Key': generateUUID()
},
body: JSON.stringify({
partner_id: 'prt_000001',
subject: 'Business Document',
payload: { content: documentContent },
content_type: 'application/edi-x12'
})
});
const result = await response.json();
Asynchronous Processing
// Queue messages for processing with webhook notifications
async function queueMessage(messageData) {
const response = await sendMessage(messageData);
// Store message ID for tracking
await storeMessageReference(response.data.id, messageData.reference);
// Webhook will notify when delivered
return response.data.id;
}
// Webhook handler for delivery notifications
app.post('/webhooks/as2', (req, res) => {
const { event, data } = req.body;
if (event === 'message.delivered') {
updateOrderStatus(data.id, 'delivered');
}
res.status(200).send('OK');
});