# EDI Parser (EDIFACT, X12) API

> Parse EDIFACT and ANSI X12 interchanges to JSON, check envelopes and counts, build EDI from JSON and generate 997 / CONTRL acknowledgements.

- Endpoint: `POST https://apibox.io.vn/v1/edi-parse`
- Category: Data & JSON
- HTML docs: https://apibox.io.vn/docs/edi-parse/ (Vietnamese: https://apibox.io.vn/vi/docs/edi-parse/)
- Online tool: https://apibox.io.vn/tools/edi-parse/
- Authentication: `Authorization: Bearer <API key>` or `X-API-Key: <API key>` (free key: https://apibox.io.vn/dashboard/#signup)

Send an interchange as `edi`, a file or a raw body. The standard is detected: UN/EDIFACT (UNA service string advice with custom separators and release character, UNB / UNG / UNH envelopes) or ANSI X12 (separators read from the fixed-width ISA, ISA / GS / ST envelopes, repetition separator). Each EDIFACT segment comes with its elements and components (release characters removed) and the segment name for common segments; each message gets its type (ORDERS, INVOIC, DESADV, IFTMIN, COPARN, CUSCAR…), version and BGM document number. X12 transaction sets get their type title (850, 810, 856, 997…) and positional element ids (BEG01, BEG02…).

Envelope checks: UNT / SE segment counts and references, UNZ / UNE / GE / IEA counts and control numbers, missing trailers. `action=validate` returns only the checks.

`action=ack` builds the acknowledgement for the received interchange: an X12 997 (AK1 / AK2 / AK5 / AK9 with accepted, partially accepted or rejected status and error codes) or an EDIFACT CONTRL (UCI / UCM with action codes 7 / 4 and syntax error codes 28 / 29). `action=generate` turns JSON into EDI: `messages` (EDIFACT) or `transactions` (X12) are wrapped with UNB / UNH / UNT / UNZ or ISA / GS / ST / SE / GE / IEA with correct counts and control numbers, or `segments` are serialised as given (with release-character escaping).

## Parameters

| Name | In | Type | Required | Default | Description |
|---|---|---|---|---|---|
| `edi` | body | string | no |  | EDI interchange text (or a file / raw body). |
| `file` | body | file | no |  | EDI file. |
| `action` | body|query | string | no | `parse` | `parse`, `validate`, `ack` or `generate`. Also as a path: /v1/edi-parse/ack. |
| `standard` | body|query | string | no |  | `edifact` or `x12` (auto-detected when parsing). |
| `messages` | body | array | no |  | generate (EDIFACT): `[{type, version, release, agency, association, segments: [["BGM","220","PO1","9"], …]}]`, with `sender`, `recipient`, `control_reference`. |
| `transactions` | body | array | no |  | generate (X12): `[{type: "810", segments: [["BIG", …], …]}]`, with `sender`, `receiver`, `control_number`, `version`, `usage`. |
| `segments` | body | array | no |  | generate: complete segment list serialised as is. |
| `format` | body|query | string | no |  | `edi` returns the raw EDI text (generate / ack). |

## Example request

```bash
curl -X POST "https://apibox.io.vn/v1/edi-parse" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"edi":"UNA:+.? '\''\nUNB+UNOC:3+5412345000013:14+4012345000016:14+261111:1200+00000001++ORDERS'\''\nUNH+1+ORDERS:D:96A:UN:EAN008'\''\nBGM+220+PO-2026-778+9'\''\nDTM+137:20261111:102'\''\nDTM+2:20261120:102'\''\nFTX+AAI+++Please deliver to dock 3?: before 10?+00'\''\nNAD+BY+5412345000013::9'\''\nNAD+SU+4012345000016::9'\''\nLIN+1++4000862141404:SRS'\''\nQTY+21:48'\''\nPRI+AAA:12.50'\''\nLIN+2++4000862141411:SRS'\''\nQTY+21:12'\''\nUNS+S'\''\nCNT+2:2'\''\nUNT+15+1'\''\nUNZ+1+00000001'\''\n"}'
```

## Example response

```json
{
  "standard": "edifact",
  "valid": true,
  "message_types": [
    "ORDERS Purchase order"
  ],
  "segment_count": 17,
  "separators": {
    "component": ":",
    "element": "+",
    "decimal": ".",
    "release": "?",
    "repetition": "*",
    "segment": "'"
  },
  "errors": [],
  "warnings": [],
  "interchanges": [
    {
      "una": true,
      "syntax": {
        "identifier": "UNOC",
        "version": "3"
      },
      "sender": {
        "id": "5412345000013",
        "qualifier": "14"
      },
      "recipient": {
        "id": "4012345000016",
        "qualifier": "14"
      },
      "prepared": {
        "date": "261111",
        "time": "1200"
      },
      "control_reference": "00000001",
      "application_reference": "ORDERS",
      "ack_requested": false,
      "test": false,
      "groups": [],
      "messages": [
        {
          "reference": "1",
          "type": "ORDERS",
          "version": "D",
          "release": "96A",
          "agency": "UN",
          "association": "EAN008",
          "name": "Purchase order",
          "segments": [
            {
              "tag": "UNH",
              "name": "Message header",
              "elements": [
                "1",
                [
                  "ORDERS",
                  "D",
                  "96A",
                  "UN",
                  "EAN008"
                ]
              ]
            },
            {
              "tag": "BGM",
              "name": "Beginning of message",
              "elements": [
                "220",
                "PO-2026-778",
                "9"
              ]
            },
            {
              "tag": "DTM",
              "name": "Date/time/period",
              "elements": [
                [
                  "137",
                  "20261111",
                  "102"
                ]
              ]
            },
            {
              "tag": "DTM",
              "name": "Date/time/period",
              "elements": [
                [
                  "2",
                  "20261120",
                  "102"
                ]
              ]
            },
            {
              "tag": "FTX",
              "name": "Free text",
              "elements": [
                "AAI",
                "",
                "",
                "Please deliver to dock 3: before 10+00"
              ]
            },
            "…"
          ],
          "trailer": {
            "segment_count": 15,
            "reference": "1"
          },
          "segment_count": 15,
          "document": {
            "code": "220",
            "number": "PO-2026-778",
            "function": "9"
          }
        }
      ],
      "trailer": {
        "count": 1,
        "reference": "00000001"
      }
    }
  ]
}
```

## Use cases

- Vietnamese garment, footwear and furniture exporters exchanging orders with US / EU retailers
- Read EDI files from a forwarder or shipping line (IFTMIN, COPARN, CUSCAR) as JSON
- Send 997 / CONTRL acknowledgements automatically from a small integration
- Generate invoices or ship notices as EDI from your order system

## FAQ

### Why are X12 elements named BEG01, BEG02…?

The X12 dictionary (element names and code lists) is licensed by X12. We give the positional ids; names come from your trading partner’s implementation guide.

### Does it validate against a partner implementation guide?

No. It checks syntax and envelopes (counts, control numbers, trailers), not partner-specific segment requirements.

### How large can a file be?

Up to your plan’s file size limit (max 20 MB of EDI text).
