X12 850 Purchase Order Last updated: 2026-11-10
The 850 is the X12 purchase order. A buyer - a retailer, distributor or manufacturer - sends it to a supplier to order goods or services, and it is the transaction most trading relationships start with.
BEG identifies the order, N1 loops name the buyer, ship-to and bill-to parties, and each PO1 loop is a line item with quantity, unit price and product identifiers. CTT closes the order with the line count.
At a glance
- Standard
- X12
- Version
004010- Functional group
PO(GS01)- Sent by
- Buyer to supplier
- Responses
- 997, 855, 856, 810
- ediFabric .NET template
TS850inEdiFabric.Templates.X12004010- OpenEDI definition
- View 850 in the spec library
850 structure
The full X12 850 layout from its OpenEDI definition, the same model ediFabric uses to parse, validate and generate it: 31 loops and 196 segment positions, in file order. Loops are shaded and their segments indented; Max use is how many times a segment or loop may repeat.
| Segment / loop | Name | Usage | Max use |
|---|---|---|---|
ST | Transaction Set Header | Mandatory | 1 |
BEG | Beginning Segment for Purchase Order | Mandatory | 1 |
CUR | Currency | Optional | 1 |
REF | Reference Identification | Optional | >1 |
PER | Administrative Communications Contact | Optional | 3 |
TAX | Tax Reference | Optional | >1 |
FOB | F.O.B. Related Instructions | Optional | >1 |
CTP | Pricing Information | Optional | >1 |
PAM | Period Amount | Optional | 10 |
CSH | Sales Requirements | Optional | 5 |
TC2 | Commodity | Optional | >1 |
| SAC loop | Service, Promotion, Allowance, or Charge Information | Optional | 25 |
SAC | Service, Promotion, Allowance, or Charge Information | Mandatory | 1 |
CUR | Currency | Optional | 1 |
ITD | Terms of Sale/Deferred Terms of Sale | Optional | >1 |
DIS | Discount Detail | Optional | 20 |
INC | Installment Information | Optional | 1 |
DTM | Date/Time Reference | Optional | 10 |
LDT | Lead Time | Optional | 12 |
LIN | Item Identification | Optional | 5 |
SI | Service Characteristic Identification | Optional | >1 |
PID | Product/Item Description | Optional | 200 |
MEA | Measurements | Optional | 40 |
PWK | Paperwork | Optional | 25 |
PKG | Marking, Packaging, Loading | Optional | 200 |
TD1 | Carrier Details (Quantity and Weight) | Optional | 2 |
TD5 | Carrier Details (Routing Sequence/Transit Time) | Optional | 12 |
TD3 | Carrier Details (Equipment) | Optional | 12 |
TD4 | Carrier Details (Special Handling, or Hazardous Materials, or Both) | Optional | 5 |
MAN | Marks and Numbers | Optional | 10 |
PCT | Percent Amounts | Optional | >1 |
CTB | Restrictions/Conditions | Optional | 5 |
TXI | Tax Information | Optional | >1 |
| AMT loop | Monetary Amount | Optional | >1 |
AMT | Monetary Amount | Mandatory | 1 |
REF | Reference Identification | Optional | >1 |
DTM | Date/Time Reference | Optional | 1 |
PCT | Percent Amounts | Optional | >1 |
| FA1 loop | Type of Financial Accounting Data | Optional | >1 |
FA1 | Type of Financial Accounting Data | Mandatory | 1 |
FA2 | Accounting Data | Mandatory | >1 |
| N9 loop | Reference Identification | Optional | 1000 |
N9 | Reference Identification | Mandatory | 1 |
DTM | Date/Time Reference | Optional | >1 |
MSG | Message Text | Optional | 1000 |
| N1 loop | Name | Optional | 200 |
N1 | Name | Mandatory | 1 |
N2 | Additional Name Information | Optional | 2 |
N3 | Address Information | Optional | 2 |
N4 | Geographic Location | Optional | >1 |
NX2 | Location ID Component | Optional | >1 |
REF | Reference Identification | Optional | 12 |
PER | Administrative Communications Contact | Optional | >1 |
SI | Service Characteristic Identification | Optional | >1 |
FOB | F.O.B. Related Instructions | Optional | 1 |
TD1 | Carrier Details (Quantity and Weight) | Optional | 2 |
TD5 | Carrier Details (Routing Sequence/Transit Time) | Optional | 12 |
TD3 | Carrier Details (Equipment) | Optional | 12 |
TD4 | Carrier Details (Special Handling, or Hazardous Materials, or Both) | Optional | 5 |
PKG | Marking, Packaging, Loading | Optional | 200 |
| LM loop | Code Source Information | Optional | >1 |
LM | Code Source Information | Mandatory | 1 |
LQ | Industry Code | Mandatory | >1 |
| SPI loop | Specification Identifier | Optional | >1 |
SPI | Specification Identifier | Mandatory | 1 |
REF | Reference Identification | Optional | 5 |
DTM | Date/Time Reference | Optional | 5 |
MSG | Message Text | Optional | 50 |
| N1 loop | Name | Optional | 20 |
N1 | Name | Mandatory | 1 |
N2 | Additional Name Information | Optional | 2 |
N3 | Address Information | Optional | 2 |
N4 | Geographic Location | Optional | 1 |
REF | Reference Identification | Optional | 20 |
G61 | Contact | Optional | 1 |
MSG | Message Text | Optional | 50 |
| CB1 loop | Contract and Cost Accounting Standards Data | Optional | >1 |
CB1 | Contract and Cost Accounting Standards Data | Mandatory | 1 |
REF | Reference Identification | Optional | 20 |
DTM | Date/Time Reference | Optional | 5 |
LDT | Lead Time | Optional | 1 |
MSG | Message Text | Optional | 50 |
| ADV loop | Advertising Demographic Information | Optional | >1 |
ADV | Advertising Demographic Information | Mandatory | 1 |
DTM | Date/Time Reference | Optional | >1 |
MTX | Text | Optional | >1 |
| PO1 loop | Baseline Item Data | Mandatory | 100000 |
PO1 | Baseline Item Data | Mandatory | 1 |
LIN | Item Identification | Optional | >1 |
SI | Service Characteristic Identification | Optional | >1 |
CUR | Currency | Optional | 1 |
CN1 | Contract Information | Optional | 1 |
PO3 | Additional Item Detail | Optional | 25 |
| CTP loop | Pricing Information | Optional | >1 |
CTP | Pricing Information | Mandatory | 1 |
CUR | Currency | Optional | 1 |
PAM | Period Amount | Optional | 10 |
MEA | Measurements | Optional | 40 |
| PID loop | Product/Item Description | Optional | 1000 |
PID | Product/Item Description | Mandatory | 1 |
MEA | Measurements | Optional | 10 |
PWK | Paperwork | Optional | 25 |
PO4 | Item Physical Details | Optional | >1 |
REF | Reference Identification | Optional | >1 |
PER | Administrative Communications Contact | Optional | 3 |
| SAC loop | Service, Promotion, Allowance, or Charge Information | Optional | 25 |
SAC | Service, Promotion, Allowance, or Charge Information | Mandatory | 1 |
CUR | Currency | Optional | 1 |
CTP | Pricing Information | Optional | 1 |
IT8 | Conditions of Sale | Optional | 1 |
CSH | Sales Requirements | Optional | >1 |
ITD | Terms of Sale/Deferred Terms of Sale | Optional | 2 |
DIS | Discount Detail | Optional | 20 |
INC | Installment Information | Optional | 1 |
TAX | Tax Reference | Optional | >1 |
FOB | F.O.B. Related Instructions | Optional | >1 |
SDQ | Destination Quantity | Optional | 500 |
IT3 | Additional Item Data | Optional | 5 |
DTM | Date/Time Reference | Optional | 10 |
TC2 | Commodity | Optional | >1 |
TD1 | Carrier Details (Quantity and Weight) | Optional | 1 |
TD5 | Carrier Details (Routing Sequence/Transit Time) | Optional | 12 |
TD3 | Carrier Details (Equipment) | Optional | 12 |
TD4 | Carrier Details (Special Handling, or Hazardous Materials, or Both) | Optional | 5 |
PCT | Percent Amounts | Optional | >1 |
MAN | Marks and Numbers | Optional | 10 |
MSG | Message Text | Optional | >1 |
SPI | Specification Identifier | Optional | >1 |
TXI | Tax Information | Optional | >1 |
CTB | Restrictions/Conditions | Optional | >1 |
| QTY loop | Quantity | Optional | >1 |
QTY | Quantity | Mandatory | 1 |
SI | Service Characteristic Identification | Optional | >1 |
| SCH loop | Line Item Schedule | Optional | 200 |
SCH | Line Item Schedule | Mandatory | 1 |
TD1 | Carrier Details (Quantity and Weight) | Optional | 2 |
TD5 | Carrier Details (Routing Sequence/Transit Time) | Optional | 12 |
TD3 | Carrier Details (Equipment) | Optional | 12 |
TD4 | Carrier Details (Special Handling, or Hazardous Materials, or Both) | Optional | 5 |
REF | Reference Identification | Optional | >1 |
| PKG loop | Marking, Packaging, Loading | Optional | 200 |
PKG | Marking, Packaging, Loading | Mandatory | 1 |
MEA | Measurements | Optional | >1 |
| LS loop | Loop Header | Optional | 1 |
LS | Loop Header | Mandatory | 1 |
| LDT loop | Lead Time | Optional | >1 |
LDT | Lead Time | Mandatory | 1 |
QTY | Quantity | Optional | >1 |
MSG | Message Text | Optional | 1 |
REF | Reference Identification | Optional | 3 |
| LM loop | Code Source Information | Optional | >1 |
LM | Code Source Information | Mandatory | 1 |
LQ | Industry Code | Mandatory | >1 |
LE | Loop Trailer | Mandatory | 1 |
| N9 loop | Reference Identification | Optional | 1000 |
N9 | Reference Identification | Mandatory | 1 |
DTM | Date/Time Reference | Optional | >1 |
MEA | Measurements | Optional | 40 |
MSG | Message Text | Optional | 1000 |
| N1 loop | Name | Optional | 200 |
N1 | Name | Mandatory | 1 |
N2 | Additional Name Information | Optional | 2 |
N3 | Address Information | Optional | 2 |
N4 | Geographic Location | Optional | 1 |
QTY | Quantity | Optional | >1 |
NX2 | Location ID Component | Optional | >1 |
REF | Reference Identification | Optional | 12 |
PER | Administrative Communications Contact | Optional | 3 |
SI | Service Characteristic Identification | Optional | >1 |
DTM | Date/Time Reference | Optional | 1 |
FOB | F.O.B. Related Instructions | Optional | 1 |
SCH | Line Item Schedule | Optional | 200 |
TD1 | Carrier Details (Quantity and Weight) | Optional | 2 |
TD5 | Carrier Details (Routing Sequence/Transit Time) | Optional | 12 |
TD3 | Carrier Details (Equipment) | Optional | 12 |
TD4 | Carrier Details (Special Handling, or Hazardous Materials, or Both) | Optional | 5 |
PKG | Marking, Packaging, Loading | Optional | 200 |
| LDT loop | Lead Time | Optional | >1 |
LDT | Lead Time | Mandatory | 1 |
MAN | Marks and Numbers | Optional | 10 |
QTY | Quantity | Optional | 5 |
MSG | Message Text | Optional | 1 |
REF | Reference Identification | Optional | 3 |
| SLN loop | Subline Item Detail | Optional | 1000 |
SLN | Subline Item Detail | Mandatory | 1 |
MSG | Message Text | Optional | >1 |
SI | Service Characteristic Identification | Optional | >1 |
PID | Product/Item Description | Optional | 1000 |
PO3 | Additional Item Detail | Optional | 104 |
TC2 | Commodity | Optional | >1 |
ADV | Advertising Demographic Information | Optional | >1 |
DTM | Date/Time Reference | Optional | 10 |
CTP | Pricing Information | Optional | 25 |
PAM | Period Amount | Optional | 10 |
PO4 | Item Physical Details | Optional | 1 |
TAX | Tax Reference | Optional | 3 |
| N9 loop | Reference Identification | Optional | >1 |
N9 | Reference Identification | Mandatory | 1 |
DTM | Date/Time Reference | Optional | >1 |
MSG | Message Text | Optional | >1 |
| SAC loop | Service, Promotion, Allowance, or Charge Information | Optional | 25 |
SAC | Service, Promotion, Allowance, or Charge Information | Mandatory | 1 |
CUR | Currency | Optional | 1 |
CTP | Pricing Information | Optional | 1 |
| QTY loop | Quantity | Optional | >1 |
QTY | Quantity | Mandatory | 1 |
SI | Service Characteristic Identification | Optional | >1 |
| N1 loop | Name | Optional | 10 |
N1 | Name | Mandatory | 1 |
N2 | Additional Name Information | Optional | 2 |
N3 | Address Information | Optional | 2 |
N4 | Geographic Location | Optional | 1 |
NX2 | Location ID Component | Optional | >1 |
REF | Reference Identification | Optional | 12 |
PER | Administrative Communications Contact | Optional | 3 |
SI | Service Characteristic Identification | Optional | >1 |
| AMT loop | Monetary Amount | Optional | >1 |
AMT | Monetary Amount | Mandatory | 1 |
REF | Reference Identification | Optional | 1 |
PCT | Percent Amounts | Optional | >1 |
| LM loop | Code Source Information | Optional | >1 |
LM | Code Source Information | Mandatory | 1 |
LQ | Industry Code | Mandatory | >1 |
| CTT loop | Transaction Totals | Optional | 1 |
CTT | Transaction Totals | Mandatory | 1 |
AMT | Monetary Amount | Optional | 1 |
SE | Transaction Set Trailer | Mandatory | 1 |
Sample 850 file
A tax-exempt purchase order for one line item, from the X12 examples. Paste it into EdiNation to see every element named and validated.
ISA*00* *00* *16*SENDER1 *1B*RECEIVER1 *071216*1406*U*00204*000000263*1*T*>~ GS*IN*SENDER1*RECEIVER1*20071216*1406*000000001*X*004010~ ST*850*0001~ BEG*00*SA*XW-7847**20250301**NA~ PER*BD*FELIX HARPER*TE*7205557180~ TAX*42565784*SP*CA*********9~ N1*BY*COPPERLINE MANUFACTURING*9*3790178823833~ N2*KESTREL AEROSTRUCTURES~ N3*88 FOUNDRY ROW~ N4*ASHLAND*CA*98710~ PO1*1*25*EA*36*PE*MG*SKC-0726~ MEA*WT*WT*10*OZ~ IT8*******B0~ SCH*25*EA***106*20250615~ CTT*1~ AMT*TT*900~ SE*15*0001~ GE*1*000000001~ IEA*1*000000263~
The same 850 as JSON
ediFabric turns every loop, segment and element into a named field. This is the transaction from the sample, in the JSON that ediFabric Native and Cloud return and accept.
{
"ST": {
"TransactionSetIdentifierCode_01": "850",
"TransactionSetControlNumber_02": "0001"
},
"BEG": {
"TransactionSetPurposeCode_01": "00",
"PurchaseOrderTypeCode_02": "SA",
"PurchaseOrderNumber_03": "XW-7847",
"Date_05": "20250301",
"AcknowledgmentType_07": "NA"
},
"PER": [
{
"ContactFunctionCode_01": "BD",
"Name_02": "FELIX HARPER",
"CommunicationNumberQualifier_03": "TE",
"CommunicationNumber_04": "7205557180"
}
],
"TAX": [
{
"TaxIdentificationNumber_01": "42565784",
"LocationQualifier_02": "SP",
"LocationIdentifier_03": "CA",
"TaxExemptCode_12": "9"
}
],
"N1Loop": [
{
"N1": {
"EntityIdentifierCode_01": "BY",
"Name_02": "COPPERLINE MANUFACTURING",
"IdentificationCodeQualifier_03": "9",
"IdentificationCode_04": "3790178823833"
},
"N2": [
{
"Name_01": "KESTREL AEROSTRUCTURES"
}
],
"N3": [
{
"AddressInformation_01": "88 FOUNDRY ROW"
}
],
"N4": [
{
"CityName_01": "ASHLAND",
"StateorProvinceCode_02": "CA",
"PostalCode_03": "98710"
}
]
}
],
"PO1Loop": [
{
"PO1": {
"AssignedIdentification_01": "1",
"QuantityOrdered_02": "25",
"UnitorBasisforMeasurementCode_03": "EA",
"UnitPrice_04": "36",
"BasisofUnitPriceCode_05": "PE",
"ProductServiceIDQualifier_06": "MG",
"ProductServiceID_07": "SKC-0726"
},
"MEA": [
{
"MeasurementReferenceIDCode_01": "WT",
"MeasurementQualifier_02": "WT",
"MeasurementValue_03": "10",
"CompositeUnitofMeasure_04": {
"UnitorBasisforMeasurementCode_01": "OZ"
}
}
],
"IT8": {
"ProductServiceSubstitutionCode_07": "B0"
},
"SCHLoop": [
{
"SCH": {
"Quantity_01": "25",
"UnitorBasisforMeasurementCode_02": "EA",
"DateTimeQualifier_05": "106",
"Date_06": "20250615"
}
}
]
}
],
"CTTLoop": {
"CTT": {
"NumberofLineItems_01": "1"
},
"AMT": {
"AmountQualifierCode_01": "TT",
"MonetaryAmount_02": "900"
}
},
"SE": {
"NumberofIncludedSegments_01": "15",
"TransactionSetControlNumber_02": "0001"
}
}Parse and validate an 850 file
Read the file into typed objects with ediFabric .NET, convert it to JSON in process with the ediFabric Native bindings for Python, Java, Node.js, Go, Rust and C, or post it to the ediFabric Cloud REST API from any language. The online models need the serial key of a free ediFabric account on the Community plan or a paid plan.
using EdiFabric.Templates.X12004010; License.EnsureToken("YOUR_SERIAL_KEY", 3600); using (var stream = File.OpenRead(@"C:\edi\PurchaseOrder.txt")) using (var reader = new X12Reader(stream, "EdiFabric.Examples.X12.Templates")) { var items = await reader.ReadToEndAsync(); foreach (var transaction in items.OfType<TS850>()) { if (transaction.IsValid(out MessageErrorContext errors)) Console.WriteLine($"{transaction.ST.TransactionSetControlNumber_02} is valid"); else Console.WriteLine(string.Join(Environment.NewLine, errors.Flatten())); } }
import json import edifabric_x12 as ef serial = "YOUR_SERIAL_KEY" ef.load_library() ef.ensure_token(serial, 3600) ef.set_map(json.dumps({"default": serial, "maps": {}})) edi = open("PurchaseOrder.txt", "rb").read() output, offset = ef.parse(edi, ef.ParseMode.JSON_VALIDATE) transactions = output[:offset] report = json.loads(output[offset:]) print(report["errors_count"])
import com.edifabric.nativex12.EdiFabricX12; import com.edifabric.nativex12.ParseMode; import com.edifabric.nativex12.ParseResult; String serial = "YOUR_SERIAL_KEY"; EdiFabricX12.loadLibrary(); EdiFabricX12.ensureToken(serial, 3600); EdiFabricX12.setMap("{\"default\":\"" + serial + "\",\"maps\":{}}"); String edi = Files.readString(Path.of("PurchaseOrder.txt")); ParseResult result = EdiFabricX12.parse(edi, ParseMode.JSON_VALIDATE); System.out.println(result.getTransactions()); System.out.println(result.getReport());
const fs = require("fs"); const ef = require("edifabric-x12"); const serial = "YOUR_SERIAL_KEY"; ef.loadLibrary(); ef.ensureToken(serial, 3600); ef.setMap(JSON.stringify({ default: serial, maps: {} })); const edi = fs.readFileSync("PurchaseOrder.txt"); const { output, offset } = ef.parse(edi, ef.ParseMode.JSON_VALIDATE); const transactions = output.slice(0, offset); const report = JSON.parse(output.slice(offset)); console.log(report.errors_count);
import ( "encoding/json" "fmt" "log" "os" ef "github.com/EdiFabric/edifabric-go-bindings" _ "github.com/EdiFabric/edifabric-go-bindings/native" ) serial := "YOUR_SERIAL_KEY" ef.LoadLibrary("") ef.EnsureToken(serial, 3600) ef.SetMap([]byte(`{"default": "` + serial + `", "maps": {}}`)) edi, _ := os.ReadFile("PurchaseOrder.txt") output, offset, err := ef.Parse(edi, ef.ParseJSONValidate, nil) if err != nil { log.Fatal(err) } transactions := output[:offset] var report struct { ErrorsCount int `json:"errors_count"` } json.Unmarshal(output[offset:], &report) fmt.Println(string(transactions), report.ErrorsCount)
use edifabric_x12 as ef; let serial = "YOUR_SERIAL_KEY"; ef::load_library(None)?; ef::ensure_token(serial, 3600)?; ef::set_map(&format!(r#"{{"default": "{serial}", "maps": {{}}}}"#))?; let edi = std::fs::read("PurchaseOrder.txt")?; let (output, offset) = ef::parse(&edi, ef::ParseMode::JsonValidate, None)?; let transactions = &output[..offset]; let report = &output[offset..]; println!("{transactions}"); println!("{report}");
#include "edifabric_x12.h" const char *serial = "YOUR_SERIAL_KEY"; ef_parse_result result; if (ef_load_library(NULL) != 0) return 1; ef_ensure_token(serial, 3600); ef_set_map("{\"default\":\"YOUR_SERIAL_KEY\",\"maps\":{}}"); char *edi = read_file("PurchaseOrder.txt", NULL); /* helper in example_all_functions.c */ if (ef_parse(edi, EF_PARSE_JSON_VALIDATE, NULL, &result) == 0) { /* transactions = output[0 .. offset), report = output[offset .. length) */ fwrite(result.output.data, 1, (size_t)result.output.length, stdout); ef_free(result.output.data); }
# mode=2 returns the JSON, then the validation report. Split it at the X-EdiFabric-Offset header. curl -X POST 'https://api.edination.com/v3/x12/parse?mode=2' \ -H 'Ocp-Apim-Subscription-Key: YOUR_SERIAL_KEY' \ -H 'Content-Type: application/octet-stream' \ -D 'headers.txt' -o 'response.bin' \ --data-binary '@PurchaseOrder.txt'
Generate an 850 file
Populate a TS850 object in .NET, or pass JSON in the shape shown above to ediFabric Native or ediFabric Cloud, and get a valid 850 file back.
using EdiFabric.Templates.X12004010; License.EnsureToken("YOUR_SERIAL_KEY", 3600); var transaction = new TS850(); transaction.ST = new ST(); transaction.ST.TransactionSetIdentifierCode_01 = "850"; transaction.ST.TransactionSetControlNumber_02 = "0001"; transaction.BEG = new BEG(); transaction.BEG.TransactionSetPurposeCode_01 = "00"; transaction.BEG.PurchaseOrderTypeCode_02 = "SA"; transaction.BEG.PurchaseOrderNumber_03 = "XW-7847"; transaction.BEG.Date_05 = "20250301"; transaction.BEG.AcknowledgmentType_07 = "NA"; // Repeating PER transaction.PER = new List<PER>(); // ... set the remaining loops and segments the same way // SegmentBuilders is in the Common project of the example repository using (var stream = new MemoryStream()) { using (var writer = new X12Writer(stream)) { writer.Write(SegmentBuilders.BuildIsa("1")); writer.Write(SegmentBuilders.BuildGs("1")); writer.Write(transaction); } Console.WriteLine(Encoding.UTF8.GetString(stream.ToArray())); }
import json import edifabric_x12 as ef serial = "YOUR_SERIAL_KEY" ef.load_library() ef.ensure_token(serial, 3600) ef.set_map(json.dumps({"default": serial, "maps": {}})) # the transactions JSON returned by ef.parse, edited or produced by your application transactions = open("PurchaseOrder.json", "rb").read() edi = ef.build(transactions, postfix="\r\n") print(edi)
import com.edifabric.nativex12.EdiFabricX12; String serial = "YOUR_SERIAL_KEY"; EdiFabricX12.loadLibrary(); EdiFabricX12.ensureToken(serial, 3600); EdiFabricX12.setMap("{\"default\":\"" + serial + "\",\"maps\":{}}"); // the transactions JSON returned by parse, edited or produced by your application String transactions = Files.readString(Path.of("PurchaseOrder.json")); String edi = EdiFabricX12.build(transactions, "\r\n"); System.out.println(edi);
const fs = require("fs"); const ef = require("edifabric-x12"); const serial = "YOUR_SERIAL_KEY"; ef.loadLibrary(); ef.ensureToken(serial, 3600); ef.setMap(JSON.stringify({ default: serial, maps: {} })); // the transactions JSON returned by ef.parse, edited or produced by your application const transactions = fs.readFileSync("PurchaseOrder.json"); const edi = ef.build(transactions, "\r\n"); console.log(edi);
import ( "fmt" "log" "os" ef "github.com/EdiFabric/edifabric-go-bindings" _ "github.com/EdiFabric/edifabric-go-bindings/native" ) serial := "YOUR_SERIAL_KEY" ef.LoadLibrary("") ef.EnsureToken(serial, 3600) ef.SetMap([]byte(`{"default": "` + serial + `", "maps": {}}`)) // the transactions JSON returned by ef.Parse, edited or produced by your application transactions, _ := os.ReadFile("PurchaseOrder.json") edi, err := ef.Build(transactions, "\r\n") if err != nil { log.Fatal(err) } fmt.Println(string(edi))
use edifabric_x12 as ef; let serial = "YOUR_SERIAL_KEY"; ef::load_library(None)?; ef::ensure_token(serial, 3600)?; ef::set_map(&format!(r#"{{"default": "{serial}", "maps": {{}}}}"#))?; // the transactions JSON returned by ef::parse, edited or produced by your application let transactions = std::fs::read("PurchaseOrder.json")?; let edi = ef::build(&transactions, Some("\r\n"))?; println!("{edi}");
#include "edifabric_x12.h" ef_buffer edi; if (ef_load_library(NULL) != 0) return 1; ef_ensure_token("YOUR_SERIAL_KEY", 3600); ef_set_map("{\"default\":\"YOUR_SERIAL_KEY\",\"maps\":{}}"); /* the transactions JSON returned by ef_parse, edited or produced by your application */ char *transactions = read_file("PurchaseOrder.json", NULL); if (ef_build(transactions, "\r\n", &edi) == 0) { fwrite(edi.data, 1, (size_t)edi.length, stdout); ef_free(edi.data); }
# the JSON returned by /x12/parse, edited or produced by your application. # Build writes the segments as they are, so include SE, GE and IEA with the correct counts. curl -X POST 'https://api.edination.com/v3/x12/build' \ -H 'Ocp-Apim-Subscription-Key: YOUR_SERIAL_KEY' \ -H 'Content-Type: application/json' \ --data-binary '@PurchaseOrder.json' \ -o 'PurchaseOrder.txt'
Complete ediFabric .NET example
A complete C# program for the X12 850, built on the C# template TS850 in EdiFabric.Templates.X12004010. The same code is in the ediFabric .NET examples on GitHub.
using EdiFabric.Core.Model.Edi;
using EdiFabric.Core.Model.Edi.X12;
using EdiFabric.Examples.X12.Common;
using EdiFabric.Framework.Readers;
using EdiFabric.Framework.Writers;
using EdiFabric.Templates.X12004010;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace EdiFabric.Examples.X12.T850
{
class Program
{
static void Main(string[] args)
{
License.EnsureToken(Config.TrialSerialKey, 3600);
Read();
Write();
}
///
/// Read Purchase Order
///
static void Read()
{
var ediStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\X12\PurchaseOrder.txt");
List ediItems;
using (var ediReader = new X12Reader(ediStream, "EdiFabric.Examples.X12.Templates"))
ediItems = ediReader.ReadToEnd().ToList();
var transactions = ediItems.OfType();
foreach (var transaction in transactions)
{
if (transaction.HasErrors)
{
// partially parsed
var errors = transaction.ErrorContext.Flatten();
}
}
}
///
/// Write Purchase Order
///
static void Write()
{
var transaction = BuildPurchaseOrder("1");
using (var stream = new MemoryStream())
{
using (var writer = new X12Writer(stream))
{
writer.Write(SegmentBuilders.BuildIsa("1"));
writer.Write(SegmentBuilders.BuildGs("1"));
writer.Write(transaction);
}
var ediString = stream.LoadToString();
}
}
///
/// Build purchase order.
///
public static TS850 BuildPurchaseOrder(string controlNumber)
{
var result = new TS850();
result.ST = new ST();
result.ST.TransactionSetIdentifierCode_01 = "850";
result.ST.TransactionSetControlNumber_02 = controlNumber.PadLeft(9, '0');
result.BEG = new BEG();
result.BEG.TransactionSetPurposeCode_01 = "00";
result.BEG.PurchaseOrderTypeCode_02 = "SA";
result.BEG.PurchaseOrderNumber_03 = "XW-7847";
result.BEG.Date_05 = "20250301";
result.BEG.AcknowledgmentType_07 = "NA";
// Repeating PER
result.PER = new List();
var per = new PER();
per.ContactFunctionCode_01 = "BD";
per.Name_02 = "FELIX HARPER";
per.CommunicationNumberQualifier_03 = "TE";
per.CommunicationNumber_04 = "7205557180";
result.PER.Add(per);
// Repeating TAX
result.TAX = new List();
var tax = new TAX();
tax.TaxIdentificationNumber_01 = "42565784";
tax.LocationQualifier_02 = "SP";
tax.LocationIdentifier_03 = "CA";
tax.TaxExemptCode_12 = "9";
result.TAX.Add(tax);
// Repeating N1 Loops
result.N1Loop = new List();
// Begin N1 Loop
var n1Loop = new Loop_N1_850();
n1Loop.N1 = new N1();
n1Loop.N1.EntityIdentifierCode_01 = "BY";
n1Loop.N1.Name_02 = "COPPERLINE MANUFACTURING";
n1Loop.N1.IdentificationCodeQualifier_03 = "9";
n1Loop.N1.IdentificationCode_04 = "3790178823833";
// Repeating N2
n1Loop.N2 = new List();
var n2 = new N2();
n2.Name_01 = "KESTREL AEROSTRUCTURES";
n1Loop.N2.Add(n2);
// Repeating N3
n1Loop.N3 = new List();
var n3 = new N3();
n3.AddressInformation_01 = "88 FOUNDRY ROW";
n1Loop.N3.Add(n3);
// Repeating N4
n1Loop.N4 = new List();
var n4 = new N4();
n4.CityName_01 = "ASHLAND";
n4.StateorProvinceCode_02 = "CA";
n4.PostalCode_03 = "98710";
n1Loop.N4.Add(n4);
// End N1 Loop
result.N1Loop.Add(n1Loop);
// Repeating PO1 Loops
result.PO1Loop = new List();
// Begin PO1 Loop
var pO1Loop = new Loop_PO1_850();
pO1Loop.PO1 = new PO1();
pO1Loop.PO1.AssignedIdentification_01 = "1";
pO1Loop.PO1.QuantityOrdered_02 = "25";
pO1Loop.PO1.UnitorBasisforMeasurementCode_03 = "EA";
pO1Loop.PO1.UnitPrice_04 = "36";
pO1Loop.PO1.BasisofUnitPriceCode_05 = "PE";
pO1Loop.PO1.ProductServiceIDQualifier_06 = "MG";
pO1Loop.PO1.ProductServiceID_07 = "SKC-0726";
// Repeating MEA
pO1Loop.MEA = new List();
var mea = new MEA();
mea.MeasurementReferenceIDCode_01 = "WT";
mea.MeasurementQualifier_02 = "WT";
mea.MeasurementValue_03 = "10";
mea.CompositeUnitofMeasure_04 = new C001();
mea.CompositeUnitofMeasure_04.UnitorBasisforMeasurementCode_01 = "OZ";
pO1Loop.MEA.Add(mea);
pO1Loop.IT8 = new IT8();
pO1Loop.IT8.ProductServiceSubstitutionCode_07 = "B0";
// Repeating SCH Loops
pO1Loop.SCHLoop = new List();
// Begin SCH Loop
var schLoop = new Loop_SCH_850();
schLoop.SCH = new SCH();
schLoop.SCH.Quantity_01 = "25";
schLoop.SCH.UnitorBasisforMeasurementCode_02 = "EA";
schLoop.SCH.DateTimeQualifier_05 = "106";
schLoop.SCH.Date_06 = "20250615";
// End SCH Loop
pO1Loop.SCHLoop.Add(schLoop);
// End PO1 Loop
result.PO1Loop.Add(pO1Loop);
// Begin CTT Loop
result.CTTLoop = new Loop_CTT_850();
result.CTTLoop.CTT = new CTT();
result.CTTLoop.CTT.NumberofLineItems_01 = "1";
result.CTTLoop.AMT = new AMT();
result.CTTLoop.AMT.AmountQualifierCode_01 = "TT";
result.CTTLoop.AMT.MonetaryAmount_02 = "900";
// End CTT Loop
return result;
}
}
}More operations in ediFabric .NET
- Parse X12 files
- Generate X12 files
- Validate X12 messages
- Generate X12 acknowledgments
- Save X12 files to DB
- Convert between X12 and JSON
- Convert between X12 and XML
Template and sample downloads
ediFabric .NET parses, validates and generates the X12 850 with the C# template TS850 in EdiFabric.Templates.X12004010. Download the template files below, add them to a class library in your solution, and edit them to match a trading partner's implementation guide.
- X12-850-PurchaseOrder.txt 547 bytes
- EF_X12_004010_850.cs 39.6 KB
- EF_X12_004010_Codes.cs 82.5 KB
- EF_X12_004010_Segments.cs 160.5 KB
- EF_X12_004010_ComplexElements.cs 6.6 KB
850 questions
What documents follow an 850?
The supplier returns a 997 functional acknowledgment, often an 855 purchase order acknowledgment, then an 856 ship notice when the goods ship and an 810 invoice.
How do I change or cancel an 850?
With an 860 purchase order change request, or by resending the 850 with BEG01 set to 01 (cancellation) or 05 (replace) when the trading partner allows it.
Why do retailers have their own 850 specifications?
The X12 standard is broad, so each trading partner publishes an implementation guide with the segments, qualifiers and codes it uses. ediFabric templates can be adjusted to match.
How do I parse and generate X12 850 files in .NET, Python, Java, Node.js, Go, Rust and C?
In .NET, install EdiFabric, download the C# template from the EDI spec library, read the file with X12Reader into TS850 objects and write them back with X12Writer. From Python, Java, Node.js, Go, Rust or C, use ediFabric Native, which converts 850 files to JSON and JSON back to X12 inside your process. From any other language, post the file to the ediFabric Cloud REST API.
Resources
Parse your first X12 850 in five minutes
The Community plan is free forever and needs no credit card. It includes ediFabric .NET, Native and Cloud with one serial key, and unlimited operations for the first 14 days under a fair usage policy.
Sign up free Validate EDI files free