Skip to main content

Create multiple shipments asynchronously (NDJSON)

POST
/api/v1/create-shipment/bulk

Queues a background job that creates shipments from a Newline-Delimited JSON (NDJSON) file. Each line in the file is a single shipment object — blank lines are ignored.

The endpoint returns immediately with a jobId. Poll GET /api/v1/create-shipment/bulk/status/{jobId} (the trackingUrl in the response) to track progress. Maximum 500 shipments per request.


How to upload​

Send a multipart/form-data request containing:

Form fieldRequiredDescription
shipments✅The .ndjson file. The server identifies it by field name shipments or by .ndjson file extension.
cmpService✅Service type: DELIVERY or REVERSE. Applied to all rows in the batch.
subAccountId❌UUID of the sub-account. Optional when authenticating via API key.
locationId❌Pickup location ID. When provided every shipment starts as AWAITING_PICKUP and a pickup request is auto-created. When absent shipments start as NEW.

NDJSON Row Schema — one JSON object per line​

Each line in the uploaded .ndjson file represents a single shipment. Blank lines and BOM-prefixed first lines are silently skipped. The file must be UTF-8 encoded.


✅ Required fields​

FieldTypeValidationDescription
consigneeNamestringmax 255Full name of the recipient / consignee.
consigneePhonestringE.164 — +[1-9]\d{6,14}Primary phone of the recipient. Example: +201001234567
districtIdinteger≥ 1Required. The only destination input — the server derives the city (branch routing + pricing zone) and the governorate (SLA/TAT) from it. Do NOT send cityId or governorateId.
addressText or structured partsstring / parts—Free-text delivery address. Optional when streetName or buildingNumber is present — the server builds addressText from the parts automatically.

🔑 District auto-resolution​

The server always resolves the destination from districtId; it resolves both values from the district record before validation, so no extra round-trip is needed from the client.


📐 Shipment dimensions​

FieldTypeDefaultDescription
weightnumber0Gross weight in kg. Chargeable = max(weight, W×H×L / 5000).
lengthnumber0Length in cm.
widthnumber0Width in cm.
heightnumber0Height in cm.
noOfPcsinteger1Total pieces (≥ 1).

👤 Consignee contact details​

FieldTypeDescription
attentionTostring (max 255)Attention-to / care-of name.
consigneePhoneAltstring (E.164)Alternate phone.
consigneePhoneAlt2string (E.164)Second alternate phone.
consigneeEmailstring (max 255)Consignee email address.
nationalIdstring (max 50)National ID for identity-verified delivery.
districtIdintegerAlready listed above as required — repeated here for completeness.
consigneeNotesstringDelivery notes shown to the courier.
latitudenumber (max 6dp)GPS latitude.
longitudenumber (max 6dp)GPS longitude.

🏠 Structured address components​

Address resolution pyramid:

  1. If streetName or buildingNumber is present → the server builds addressText from the structured parts (auto-detects Arabic vs English) and ignores any addressText you sent.
  2. Otherwise → the provided addressText is used as-is.

newAddressText is independent — stored as a secondary address on the consignee and does not affect the pyramid.

FieldTypeDescription
streetNamestring (max 255)Street name — triggers pyramid when present.
buildingNumberstring (max 255)Building/house number — triggers pyramid when present.
floorstring (max 255)Floor number.
apartmentstring (max 255)Apartment / unit number.
landmarkNearbystring (max 255)Nearby landmark for courier guidance.
newAddressTextstringOptional secondary address. Stored independently on the consignee.

📋 Shipment metadata​

FieldTypeDescription
refstring (max 255)Your internal order or reference number. Must be unused by your other shipments on this sub-account (matched ignoring case and surrounding spaces). Rows carrying a duplicate are skipped and reported in the skipped array; blank references never clash.
packageTypePARCEL | DOCUMENTS | BULKYPackaging type — drives handling rules.
contentsstring (max 500)Description of the shipment contents.
itemValuenumber (≥ 0)Declared value in EGP — used for insurance.
cashnumber (≥ 0)Cash-on-delivery (COD) amount in EGP. Zero = no COD.
specialInstructionsstring (max 500)Special handling instructions.
productIdinteger (≥ 1)Product type ID.
shipmentServiceIdsinteger[]Add-on (extra) service IDs — see the dedicated section below.

🧩 Extra (add-on) services​

Extra services are fully supported in bulk, exactly as in the single-create endpoint, and are set per row — not per batch — so every shipment in the same file can carry a different set.

1. Fetch the available IDs

EndpointReturns
GET /create-shipment/all-servicesEvery active service in the system: [{ "id": 1, "value": "Cash on Delivery" }, ...]
GET /create-shipment/default-service?subAccountId=…The services pre-configured as defaults for the sub-account.

2. Send the IDs on the row

{"consigneeName":"Ahmed Hassan","consigneePhone":"+201001234567","districtId":1,"addressText":"15 شارع النصر","weight":2.5,"cash":250,"ref":"ORD-001","productId":1,"shipmentServiceIds":[1,2]}
{"consigneeName":"Mariam Tarek","consigneePhone":"+201223334445","districtId":210,"weight":0.5,"ref":"ORD-002","productId":1,"shipmentServiceIds":[3]}
{"consigneeName":"Khaled Mohamed","consigneePhone":"+201501112233","districtId":87,"weight":1.5,"ref":"ORD-003","productId":1}

Row 1 gets services 1 + 2, row 2 gets service 3, row 3 gets none — omit the field (or send []) when a shipment has no add-ons.

3. What the server does with them

  • Pricing — each service's price is added to the shipment's serviceFees, which flows into totalAbsFees / totalFees. Prices are resolved once per batch, not per row, so a large file with the same services costs a single lookup.
  • Linking — a row is written into shp_shipments_shipment_services for every (AWB, service) pair, so the services come back on the shipment details response.
  • Duplicates — repeated IDs on the same row are de-duplicated; the service is charged once.

4. Validation — a bad ID fails the whole batch; nothing is created

ConditionMessageWhere you see it
Non-numeric valueRow 3: shipmentServiceIds must be a number400 on the upload request itself
ID does not existUnknown shipmentServiceIds: 99Job failure — error field of GET /create-shipment/bulk/status/{jobId}
Service exists but is deactivatedThese shipment services are no longer active: 4Job failure — same as above

The last two are raised inside the background job, so the upload still returns 201 with a jobId; the batch is rolled back in full and the failure reason appears on the status endpoint.

💡 Use POST /create-shipment/calculate-abs-fees with servicePrices beforehand if you want to preview the total including add-ons before uploading the batch.


🔑 AWB and backdating​

FieldTypeDescription
awbstringManual AWB override. Auto-generated when omitted. Duplicate AWBs are skipped and reported in the skipped array.

↩️ Return location​

FieldTypeDescription
returnLocationIdinteger (≥ 1)Location to which the shipment is returned on delivery failure. Defaults to the sub-account warehouse. The server derives returnBranchId from this location automatically.

📦 Sub-packages breakdown​

Use packages when a single shipment contains multiple pieces with different dimensions:

"packages": [
{ "quantity": 2, "weight": 3.5, "length": 30, "width": 20, "height": 15 },
{ "quantity": 1, "weight": 0.8, "length": 20, "width": 10, "height": 10 }
]

🌍 International shipment data​

"createInternationalData": {
"purposeOfShipment": "COMMERCIAL_SAMPLE",
"hsCode": "6109.10",
"madeInId": 1
}

🚫 Server-derived fields — do NOT include in the NDJSON​

FieldDerived from
businessLocationIdSub-account warehouse (or locationId form field).
returnBranchIdBranch of the resolved returnLocationId.
deliveryBranchIdBranch of the district's city (DELIVERY) or warehouse branch (REVERSE).
currentBranchIdAlways null at creation.
fromBranchIdAlways null at creation.

⚠️ REVERSE shipment notes​

When cmpService = REVERSE (the form field — not per-row):

  • The customer's flat address data (streetName, buildingNumber, addressText, etc.) becomes an ad-hoc pickup origin (fromLocationId).
  • Consignee = the merchant — the sub-account name + warehouse address is stored as the consignee.
  • returnLocationId — should be the merchant warehouse (or omit to default to it).

📄 Minimal valid NDJSON examples​

DELIVERY — minimal row:

{"consigneeName":"Ahmed Hassan","consigneePhone":"+201001234567","districtId":1,"addressText":"15 شارع النصر، شقة 4، مدينة نصر","weight":2.5,"length":30,"width":20,"height":15,"cash":250,"ref":"ORD-001","packageType":"PARCEL","contents":"ملابس","productId":1}

DELIVERY — cityId + structured address:

{"consigneeName":"Mariam Tarek","consigneePhone":"+201223334445","districtId":210,"streetName":"شارع الجلاء","buildingNumber":"18","floor":"3","apartment":"12","landmarkNearby":"أمام مسجد النور","weight":0.5,"cash":0,"ref":"ORD-002","packageType":"DOCUMENTS","productId":1}

DELIVERY — with extra (add-on) services:

{"consigneeName":"Nour Adel","consigneePhone":"+201009998877","districtId":134,"addressText":"22 شارع مصطفى النحاس، مدينة نصر","weight":3,"length":30,"width":20,"height":15,"cash":500,"ref":"ORD-004","packageType":"PARCEL","productId":1,"shipmentServiceIds":[1,2]}

REVERSE — with explicit return location:

{"consigneeName":"Khaled Mohamed","consigneePhone":"+201501112233","districtId":87,"addressText":"45 شارع الهرم، الجيزة","weight":1.5,"length":25,"width":15,"height":10,"cash":0,"ref":"RTN-001","packageType":"PARCEL","returnLocationId":7,"productId":1}

Request​

Responses​

201 Created

Job enqueued. Poll trackingUrl for progress.

400 Bad Request

Validation error — malformed JSON, missing required fields, invalid enum, or > 500 rows. message lists the per-row errors, separated by ; .

401 Unauthorized

Unauthorized.

404 Not Found

Sub-account or pickup location not found.

500 Internal Server Error

Internal Server Error.