Skip to main content

Quick Start — REST API

This guide walks you through the most common ECGrid workflow — checking your inbox, downloading a file, and confirming delivery — using the REST API. Examples are shown in cURL, C#, Java, Node.js, and Python.

Prerequisites

Step 1 — Verify Connectivity

The version endpoint requires no authentication and confirms you can reach the API.

curl https://rest.ecgrid.io/v2/auth/version

Expected response:

{
"success": true,
"data": { "version": "2.6.x", "build": "..." }
}

Step 2 — Authenticate

Add your API key to every request using the X-API-Key header.

# Set once; all subsequent curl commands include it
export ECGRID_API_KEY="your-api-key-here"

curl https://rest.ecgrid.io/v2/auth/version \
-H "X-API-Key: $ECGRID_API_KEY"

:::tip Bearer JWT You can also authenticate with a short-lived JWT via POST /v2/auth/login. API Key auth is simpler for server-to-server workflows. See Authentication & API Keys for details. :::

Step 3 — Check Your Inbox

POST /v2/parcels/pending-inbox-list returns all parcels that have not yet been downloaded.

curl -X POST https://rest.ecgrid.io/v2/parcels/pending-inbox-list \
-H "X-API-Key: $ECGRID_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'

Response — a list of ParcelIDInfo records:

{
"success": true,
"data": [
{
"parcelId": 123456,
"fileName": "invoice_850.edi",
"bytes": 4096,
"status": "InBoxReady",
".....":"......"
}
]
}

Step 4 — Download a Parcel

POST /v2/parcels/download returns the raw EDI file as a base64-encoded string in the content field.

curl -X POST https://rest.ecgrid.io/v2/parcels/download \
-H "X-API-Key: $ECGRID_API_KEY" \
-H "Content-Type: application/json" \
-d '{"parcelId": 123456}'

Step 5 — Confirm the Download

POST /v2/parcels/confirm marks the parcel as transferred so it no longer appears in inbox polls. Always confirm after saving the file. Un-confirmed parcels remain on the next poll cycle.

curl -X POST https://rest.ecgrid.io/v2/parcels/confirm \
-H "X-API-Key: $ECGRID_API_KEY" \
-H "Content-Type: application/json" \
-d '{"parcelId": 123456}'

Complete Example

A full poll → download → confirm workflow in each language.

#!/usr/bin/env bash
# Requires: curl, jq
set -euo pipefail

BASE="https://rest.ecgrid.io"

# Poll for pending parcels
INBOX=$(curl -s -X POST "$BASE/v2/parcels/pending-inbox-list" \
-H "X-API-Key: $ECGRID_API_KEY" \
-H "Content-Type: application/json" \
-d '{}')

COUNT=$(echo "$INBOX" | jq '.data | length')
echo "Found $COUNT parcel(s) waiting."

echo "$INBOX" | jq -c '.data[]' | while read -r PARCEL; do
ID=$(echo "$PARCEL" | jq '.parcelId')
NAME=$(echo "$PARCEL" | jq -r '.fileName')
echo "Downloading parcel $ID: $NAME"

DOWNLOAD=$(curl -s -X POST "$BASE/v2/parcels/download" \
-H "X-API-Key: $ECGRID_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"parcelId\": $ID}")

OUT=$(echo "$DOWNLOAD" | jq -r '.data.fileName')
echo "$DOWNLOAD" | jq -r '.data.content' | base64 -d > "$OUT"
echo " Saved $OUT"

curl -s -X POST "$BASE/v2/parcels/confirm" \
-H "X-API-Key: $ECGRID_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"parcelId\": $ID}" > /dev/null

echo " Confirmed parcel $ID"
done

Next Steps