---
title: "Generate a ready-to-send ANSI ASC X12 EDI document from..."
method: POST
path: "/api/edi/generate"
tags: ["edi"]
---

# Generate a ready-to-send ANSI ASC X12 EDI document from...

`POST /api/edi/generate`

## Request

- Base URL: `https://2s.io`
- URL: `https://2s.io/api/edi/generate`
- Auth: API key in header `PAYMENT-SIGNATURE`

Generate a ready-to-send ANSI ASC X12 EDI document from structured JSON. POST type ('850' Purchase Order, '810' Invoice, or '856' Ship Notice/ASN) plus senderId, receiverId, documentNumber (PO#/invoice#/shipment id), optional date, parties (N1 loops — role like ST/BT/VN + name), and items (quantity, uom, price, productId). For an 810 you can pass poNumber and total; for an 856 pass poNumber (the PO shipped). Returns the full X12 interchange in meta.edi — correct ISA/GS/ST…SE/GE/IEA envelope, party loops, PO1/IT1 line items (or the 856 HL Shipment→Order→Item hierarchy with LIN/SN1), and CTT/TDS totals (implied 2-decimal). Deterministic, no external calls. The outbound complement to edi.parse and edi.ack: assemble valid EDI envelopes instead of hand-rolling segment terminators and control numbers.

## Query parameters

- `trial` 1

## Request body

- object
  - `type` '850' | '810' | '856', required: Filter results by type.
  - `senderId` string, required: Sender ID.
  - `receiverId` string, required: Receiver ID.
  - `senderQualifier` string: Sender qualifier.
  - `receiverQualifier` string: Receiver qualifier.
  - `documentNumber` string, required: Document number.
  - `poNumber` string: Po number.
  - `date` string: Date in YYYY-MM-DD format.
  - `parties` object[]: Parties.
    - `role` string, required: Entity-id code (ST=ship-to, BT=bill-to, VN=vendor, SF=ship-from, …).
    - `name` string, required: Name to search for.
    - `idQualifier` string: ID qualifier.
    - `id` string: Unique identifier of the record to fetch.
  - `items` object[], required: Items.
    - `quantity` union, required: Quantity.
      - number
      - string
    - `uom` string: Unit of measure (EA, CA, …; default EA).
    - `price` union: Price.
      - number
      - string
    - `productId` string: Product ID.
    - `idQualifier` string: Product id qualifier (VP, UP, BP, …; default VP).
  - `total` number: 810 invoice total in USD.
  - `controlNumber` string: Control number.
  - `usage` 'P' | 'T': Usage.

## Other responses

- `200` (unresolved $ref)
- `400`: Invalid request — not charged. error.code: BAD_REQUEST or INVALID_PARAM (parameter validation; error.details.issues lists each problem), MALFORMED_JSON, or a request-specific code. Other client errors: 405 METHOD_NOT_ALLOWED (wrong verb; see the Allow header), 413 PAYLOAD_TOO_LARGE.
- `402`: Payment required. Body is the x402 PaymentRequirements envelope with a multi-network accepts array; the per-call price is in accepts[].amount (and on the operation as x-2s-price). Sign for whichever rail you hold USDC on (EIP-3009 for Base, partial SPL transfer for Solana) and retry with the PAYMENT-SIGNATURE header (X-PAYMENT also accepted for v1 clients). Also PAYMENT_SETTLE_FAILED (error envelope) when a verified payment failed to settle: error.details.chargeStatus is "not_charged" (retry with a fresh payment) or "unknown" (the authorization may still settle before its deadline — check it before retrying).
- `429`: Too many requests — RATE_LIMITED: our per-IP / per-payer limiter. Not charged; retry after Retry-After.
- `5XX`: Server-side failure. 500 INTERNAL: unexpected error; quote error.errorId (also the X-2s-Error-Id header). 502 UPSTREAM_UNAVAILABLE (or another UPSTREAM_* code): the data provider failed — composite endpoints refuse unbilled when every source fails. 503 SERVICE_PAUSED: endpoint paused by the operator kill switch, retry after Retry-After; 503 SPEND_CAP: daily upstream budget exhausted. 504 UPSTREAM_TIMEOUT. Not charged.

---

[API](https://skmtc.dev/2s-io/apis/2s-the-most-everything-api.md) · [All operations](https://skmtc.dev/2s-io/apis/2s-the-most-everything-api/llms.txt) · [OpenAPI document](https://skmtc.dev/2s-io/apis/2s-the-most-everything-api/revisions/da4c5caf686e?raw)
