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

ParameterTypeConstraintsDescription
partner_idstringValid partner IDTarget trading partner
payload.contentstringNon-emptyMessage content (base64 for binary)
content_typestringValid MIME typeContent type of the payload

Optional Parameters

ParameterTypeDefaultConstraintsDescription
subjectstringnull1-255 charactersMessage subject line
payload.filenamestringnull1-255 charactersOriginal filename
payload.encodingenumutf-8utf-8, base64Payload encoding
headersobject{}Key-value pairsCustom AS2 headers
priorityenumnormallow, normal, highProcessing priority
compressbooleanPartner default-Override compression setting
encryptbooleanPartner default-Override encryption setting
signbooleanPartner default-Override signing setting
mdn_modeenumPartner defaultsync, async, noneMDN delivery mode
scheduled_atdatetimenullFuture timestampSchedule 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
}

File Upload (multipart/form-data)

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)

FieldTypeDescription
messagestringSuccess message
dataobjectMessage object
data.idstringUnique message identifier
data.message_idstringAS2 message ID
data.partnerobjectPartner information
data.statusenumCurrent message status
data.directionenumMessage direction
data.subjectstringMessage subject
data.content_typestringPayload content type
data.bytesintegerPayload size in bytes
data.mdn_modeenumMDN delivery mode
data.created_atdatetimeMessage 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

ParameterTypeDefaultConstraintsDescription
partner_idstringnullValid partner IDFilter by trading partner
statusenumnullValid status codeFilter by message status
directionenumnullinbound, outboundFilter by message direction
from_datedatetimenullISO 8601 formatStart date filter
to_datedatetimenullISO 8601 formatEnd date filter
searchstringnull1-255 charactersSearch subjects and message IDs
content_typestringnullValid MIME typeFilter by content type
pageinteger1Minimum 1Page number
per_pageinteger201-100Items per page

Response Schema

FieldTypeDescription
dataarrayArray of message objects
paginationobjectPagination metadata

Message Object Fields

FieldTypeDescription
idstringMessage identifier
message_idstringAS2 message ID
partnerobjectPartner information
statusenumMessage status
directionenuminbound or outbound
from_as2_idstringSender AS2 ID
to_as2_idstringRecipient AS2 ID
subjectstringMessage subject
content_typestringPayload MIME type
bytesintegerPayload size
compressedbooleanCompression applied
encryptedbooleanEncryption applied
signedbooleanDigital signature applied
mdn_modeenumMDN delivery mode
mdn_statusenumMDN status
attemptsintegerTransmission attempts
sent_atdatetimeTransmission timestamp
delivered_atdatetimeDelivery confirmation timestamp
created_atdatetimeCreation timestamp
updated_atdatetimeLast update timestamp

Get Message Details

Retrieve detailed information about a specific message.

GET /v1/messages/{message_id}

Path Parameters

ParameterTypeRequiredDescription
message_idstringYesMessage 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

ParameterTypeRequiredDescription
message_idstringYesMessage identifier

Response

Success Response (200 OK)

Returns the original payload content with appropriate Content-Type header.

Response Headers:

HeaderDescription
Content-TypeOriginal payload MIME type
Content-LengthPayload size in bytes
Content-Dispositionattachment; filename="original_filename"
X-Payload-Compressedtrue if payload was compressed
X-Payload-Encryptedtrue if payload was encrypted

Message Status Codes

Status Progression

Loading diagram...
StatusDescriptionNext Possible Status
queuedMessage accepted and queued for processingprocessing, failed
processingMessage preparation and transmission in progresssent, failed
sentMessage successfully transmitted to partnerdelivered, failed
deliveredMDN received confirming successful deliveryFinal state
failedMessage transmission or processing failedFinal state
receivedInbound message received from partnerFinal state

MDN Status Codes

MDN StatusDescription
noneNo MDN requested
pendingMDN requested but not yet received
receivedMDN successfully received
failedMDN delivery failed
timeoutMDN not received within timeout period

Error Codes

Message-Specific Error Codes

Error CodeHTTP StatusDescriptionResolution
PARTNER_NOT_FOUND404Specified partner does not existVerify partner ID or create partner
PARTNER_INACTIVE400Partner is deactivatedActivate partner before sending
PAYLOAD_TOO_LARGE413Message exceeds size limitReduce payload size or enable compression
INVALID_CONTENT_TYPE400Unsupported content typeUse supported MIME type
ENCRYPTION_FAILED400Cannot encrypt messageCheck partner encryption certificate
SIGNING_FAILED400Cannot sign messageCheck identity signing certificate
PARTNER_UNREACHABLE400Cannot connect to partner endpointVerify partner URL and connectivity
INVALID_AS2_HEADERS400AS2 headers validation failedCheck AS2 ID configuration
MDN_TIMEOUT408MDN not received within timeoutCheck partner MDN configuration
CERTIFICATE_EXPIRED400Required certificate has expiredRenew 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

FilterTypeFormatDescription
statusenumSingle valueFilter by message status
directionenumSingle valueFilter by message direction
partner_idstringPartner IDFilter by specific partner
from_datedatetimeISO 8601Messages created after date
to_datedatetimeISO 8601Messages created before date
content_typestringMIME typeFilter by content type
has_errorsbooleantrue/falseMessages with transmission errors
mdn_statusenumMDN statusFilter by MDN status
encryptedbooleantrue/falseFilter encrypted messages
signedbooleantrue/falseFilter 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

EncodingUsageDescription
utf-8Text contentDefault for text-based formats
base64Binary contentRequired for binary files

Content Type Mapping

Content TypeFile ExtensionsEncodingDescription
application/edi-x12.edi, .x12utf-8X12 EDI documents
application/edifact.ediutf-8EDIFACT documents
application/xml.xmlutf-8XML business documents
application/json.jsonutf-8JSON structured data
text/plain.txtutf-8Plain text files
text/csv.csvutf-8Comma-separated values
application/pdf.pdfbase64PDF documents
application/zip.zipbase64ZIP archives
image/png.pngbase64PNG images
image/jpeg.jpg, .jpegbase64JPEG images

Size Limitations

PlanMaximum SizeCompressionNotes
Free50 MBAvailableSuitable for standard EDI documents
Starter100 MBAvailableHandles larger business documents
Professional500 MBAvailableSupports high-volume transactions
Enterprise2 GBAvailableCustom limits available

Message Security

Encryption Configuration

AlgorithmKey SizeSecurity LevelCompatibility
3DES168-bitLowLegacy systems
AES128_CBC128-bitStandardMost systems
AES192_CBC192-bitEnhancedModern systems
AES256_CBC256-bitHighSecurity-focused systems

Signing Configuration

AlgorithmKey SizeSecurity LevelCompatibility
SHA1withRSA1024+ bitLowLegacy compatibility
SHA256withRSA2048+ bitStandardRecommended
SHA384withRSA2048+ bitEnhancedHigh security
SHA512withRSA2048+ bitHighMaximum security

AS2 Protocol Details

AS2 Headers

HeaderTypeRequiredDescription
AS2-FromstringYesSender AS2 identifier
AS2-TostringYesRecipient AS2 identifier
Message-IDstringYesUnique message identifier
AS2-VersionstringYesAS2 protocol version (1.0)
Content-TypestringYesMessage content type
Content-DispositionstringNoFilename information
Disposition-Notification-TostringConditionalMDN delivery address
Disposition-Notification-OptionsstringConditionalMDN options

MDN (Message Disposition Notification)

MDN Modes

ModeDescriptionResponse TimeUse Case
syncSynchronous MDNImmediateReal-time confirmation needed
asyncAsynchronous MDNDelayedStandard business messaging
noneNo MDNN/AFire-and-forget messaging

MDN Data Structure

FieldTypeDescription
dispositionstringMDN disposition value
received_content_micstringMessage integrity check value
reporting_uastringReporting user agent
original_message_idstringOriginal message identifier
final_recipientstringFinal recipient AS2 ID

Webhook Integration

Message Events

EventTrigger ConditionData Included
message.queuedMessage accepted for processingMessage object
message.sentMessage transmitted to partnerMessage object with transmission details
message.deliveredMDN received confirming deliveryMessage object with MDN data
message.failedMessage transmission failedMessage object with error details
message.receivedInbound message receivedMessage 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"
}

Performance Considerations

Request Optimization

OptimizationImplementationBenefit
PaginationUse appropriate per_page valuesReduces response size
FilteringApply specific filtersReduces data transfer
Field SelectionRequest only needed fieldsFaster responses
CompressionEnable gzip compressionReduces bandwidth

Concurrent Requests

PlanMaximum ConcurrentRecommendedNotes
Free53Basic concurrent operations
Starter107Standard business usage
Professional2520High-volume operations
EnterpriseCustomCustomTailored 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');
});