# UN/EDIFACT Transaction Quality Gate (`ceddl/unedifact-transaction-quality-gate`) Actor

Validate ORDERS, INVOIC, DESADV, and CONTRL syntax, envelopes, counts, narrow structure, and partner overlays with stable evidence and optional acknowledgements.

- **URL**: https://apify.com/ceddl/unedifact-transaction-quality-gate.md
- **Developed by:** [Cedric Günther](https://apify.com/ceddl) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $10.00 / 1,000 edifact transaction validateds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## UN/EDIFACT Transaction Quality Gate

Validate bounded UN/EDIFACT interchanges before partner transmission, ERP
import, or mapping release. The Actor produces stable syntax, envelope, count,
narrow message-structure, and optional partner-rule evidence—not just JSON
tokenization.

### Typical workflow

1. Pin one compatibility target: `D96A`, `D01B`, or `D20B`.
2. Submit one or more inline interchanges and choose strict/tolerant structure
   handling, hard limits, optional partner overlays, and optional CONTRL output.
3. Route transaction `PASS`, `WARN`, or `FAIL` rows and retain stable finding
   fingerprints for regression evidence.
4. If enabled, deliver the generated acknowledgement through your existing EDI
   transport. This Actor does not transmit it.

```json
{
    "directory": "D01B",
    "mode": "strict",
    "generateContrl": true,
    "interchanges": [
        {
            "sourceId": "supplier-a-order-1001",
            "content": "UNB+UNOC:3+SENDER:14+RECEIVER:14+260916:1200+IREF'UNH+1+ORDERS:D:01B:UN'BGM+220+PO-1001+9'DTM+137:20260916:102'NAD+BY+BUYER::9'LIN+1++SKU-1:EN'QTY+21:5'UNT+7+1'UNZ+1+IREF'"
        }
    ],
    "partnerRules": []
}
```

### Supported scope

- Syntax delimiters from UNA plus release-character handling.
- UNOA, UNOB, UNOC, and UNOY syntax identifiers.
- UNB/UNZ and UNH/UNT nesting, reference, and count validation.
- Narrow original structure profiles for ORDERS, INVOIC, DESADV, and CONTRL
  against compatibility pins D96A, D01B, and D20B.
- Data-driven overlays requiring or forbidding named segments.
- Up to 100 interchanges/run, 10 MB/interchange, 100,000 segments/interchange,
  and 10,000 messages/interchange within configurable lower defaults.

The Actor does not bundle, transform, or redistribute UNECE UN/EDIFACT
directory files. Compatibility pins identify expected UNH versions; the checks
are an original bounded subset and are not full official directory conformance.

### Output contract

Dataset `recordType` is `transaction`, `finding`, or failed `interchange`.
Transaction rows include message type/directory, references, document number,
counts, and final status. Finding rows have a stable code, severity, segment
location, message, and fingerprint. Canonical parsed segments are stored in
`CANONICAL_JSON`; optional acknowledgements are in `CONTRL_ACKNOWLEDGEMENTS`.

No processing timestamp enters canonical evidence. Identical content and
`sourceId` produce identical output.

### Failure behavior

Invalid top-level configuration fails before work. A malformed interchange is
isolated so other batch items continue. Unsafe syntax, missing terminators,
broken nesting, unsupported message/directory, and resource limits fail closed.
Envelope and count mismatches remain visible findings on parsed transactions.

### Privacy and scope boundary

The Actor sends no EDI content to third parties. Use Apify retention settings
appropriate to commercial documents. It does not provide X12, AS2/SFTP,
transport, partner onboarding, custom mapping, ERP connectivity, visual mapping,
business interpretation, compliance certification, or consulting.

### Development

```sh
npm install
npm test
npm run quality
npm run benchmark
```

### Changelog

- `0.1.0` — Original tokenizer, envelope/count checks, four narrow message
  profiles, three directory pins, overlays, stable findings, and CONTRL output.

# Actor input Schema

## `interchanges` (type: `array`):

Inline bounded UN/EDIFACT interchanges processed independently.

## `directory` (type: `string`):

UN/EDIFACT directory identifier used by the narrow original validation profile.

## `mode` (type: `string`):

Strict fails profile errors; tolerant reports them while preserving evidence.

## `generateContrl` (type: `boolean`):

Write deterministic CONTRL acknowledgement text for completed interchanges.

## `partnerRules` (type: `array`):

Optional bounded required/forbidden segment rules for supported message types.

## `maxInterchangeBytes` (type: `integer`):

Fail an interchange when its UTF-8 input exceeds this byte limit.

## `maxSegmentsPerInterchange` (type: `integer`):

Fail an interchange when its parsed segment count exceeds this limit.

## `maxMessagesPerInterchange` (type: `integer`):

Fail an interchange when its parsed message count exceeds this limit.

## Actor input object example

```json
{
  "interchanges": [
    {
      "sourceId": "store-qa-order-1001",
      "content": "UNB+UNOC:3+STORE-QA-SENDER:14+STORE-QA-RECEIVER:14+260916:1200+STORE-QA-1'UNH+1+ORDERS:D:01B:UN'BGM+220+PO-1001+9'DTM+137:20260916:102'NAD+BY+STORE-QA-BUYER::9'LIN+1++STORE-QA-SKU:EN'QTY+21:5'UNT+7+1'UNZ+1+STORE-QA-1'"
    }
  ],
  "directory": "D01B",
  "mode": "strict",
  "generateContrl": true,
  "partnerRules": [],
  "maxInterchangeBytes": 2000000,
  "maxSegmentsPerInterchange": 20000,
  "maxMessagesPerInterchange": 1000
}
```

# Actor output Schema

## `transactions` (type: `string`):

No description

## `summary` (type: `string`):

No description

## `canonicalJson` (type: `string`):

No description

## `contrl` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "interchanges": [
        {
            "sourceId": "store-qa-order-1001",
            "content": "UNB+UNOC:3+STORE-QA-SENDER:14+STORE-QA-RECEIVER:14+260916:1200+STORE-QA-1'UNH+1+ORDERS:D:01B:UN'BGM+220+PO-1001+9'DTM+137:20260916:102'NAD+BY+STORE-QA-BUYER::9'LIN+1++STORE-QA-SKU:EN'QTY+21:5'UNT+7+1'UNZ+1+STORE-QA-1'"
        }
    ],
    "directory": "D01B",
    "generateContrl": true,
    "partnerRules": []
};

// Run the Actor and wait for it to finish
const run = await client.actor("ceddl/unedifact-transaction-quality-gate").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "interchanges": [{
            "sourceId": "store-qa-order-1001",
            "content": "UNB+UNOC:3+STORE-QA-SENDER:14+STORE-QA-RECEIVER:14+260916:1200+STORE-QA-1'UNH+1+ORDERS:D:01B:UN'BGM+220+PO-1001+9'DTM+137:20260916:102'NAD+BY+STORE-QA-BUYER::9'LIN+1++STORE-QA-SKU:EN'QTY+21:5'UNT+7+1'UNZ+1+STORE-QA-1'",
        }],
    "directory": "D01B",
    "generateContrl": True,
    "partnerRules": [],
}

# Run the Actor and wait for it to finish
run = client.actor("ceddl/unedifact-transaction-quality-gate").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "interchanges": [
    {
      "sourceId": "store-qa-order-1001",
      "content": "UNB+UNOC:3+STORE-QA-SENDER:14+STORE-QA-RECEIVER:14+260916:1200+STORE-QA-1'\''UNH+1+ORDERS:D:01B:UN'\''BGM+220+PO-1001+9'\''DTM+137:20260916:102'\''NAD+BY+STORE-QA-BUYER::9'\''LIN+1++STORE-QA-SKU:EN'\''QTY+21:5'\''UNT+7+1'\''UNZ+1+STORE-QA-1'\''"
    }
  ],
  "directory": "D01B",
  "generateContrl": true,
  "partnerRules": []
}' |
apify call ceddl/unedifact-transaction-quality-gate --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,ceddl/unedifact-transaction-quality-gate"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/ihJKv8eD5rS3cjzM6/builds/UF8a1WbnAZWimWVgT/openapi.json
