Create multiple shipments asynchronously (NDJSON)
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 field | Required | Description |
|---|---|---|
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
| Field | Type | Validation | Description |
|---|---|---|---|
consigneeName | string | max 255 | Full name of the recipient / consignee. |
consigneePhone | string | E.164 — +[1-9]\d{6,14} | Primary phone of the recipient. Example: +201001234567 |
districtId | integer | ≥ 1 | Required. 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 parts | string / 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
| Field | Type | Default | Description |
|---|---|---|---|
weight | number | 0 | Gross weight in kg. Chargeable = max(weight, W×H×L / 5000). |
length | number | 0 | Length in cm. |
width | number | 0 | Width in cm. |
height | number | 0 | Height in cm. |
noOfPcs | integer | 1 | Total pieces (≥ 1). |
👤 Consignee contact details
| Field | Type | Description |
|---|---|---|
attentionTo | string (max 255) | Attention-to / care-of name. |
consigneePhoneAlt | string (E.164) | Alternate phone. |
consigneePhoneAlt2 | string (E.164) | Second alternate phone. |
consigneeEmail | string (max 255) | Consignee email address. |
nationalId | string (max 50) | National ID for identity-verified delivery. |
districtId | integer | Already listed above as required — repeated here for completeness. |
consigneeNotes | string | Delivery notes shown to the courier. |
latitude | number (max 6dp) | GPS latitude. |
longitude | number (max 6dp) | GPS longitude. |
🏠 Structured address components
Address resolution pyramid:
- If
streetNameorbuildingNumberis present → the server buildsaddressTextfrom the structured parts (auto-detects Arabic vs English) and ignores anyaddressTextyou sent. - Otherwise → the provided
addressTextis used as-is.
newAddressText is independent — stored as a secondary address on the consignee and does not affect the pyramid.
| Field | Type | Description |
|---|---|---|
streetName | string (max 255) | Street name — triggers pyramid when present. |
buildingNumber | string (max 255) | Building/house number — triggers pyramid when present. |
floor | string (max 255) | Floor number. |
apartment | string (max 255) | Apartment / unit number. |
landmarkNearby | string (max 255) | Nearby landmark for courier guidance. |
newAddressText | string | Optional secondary address. Stored independently on the consignee. |
📋 Shipment metadata
| Field | Type | Description |
|---|---|---|
ref | string (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. |
packageType | PARCEL | DOCUMENTS | BULKY | Packaging type — drives handling rules. |
contents | string (max 500) | Description of the shipment contents. |
itemValue | number (≥ 0) | Declared value in EGP — used for insurance. |
cash | number (≥ 0) | Cash-on-delivery (COD) amount in EGP. Zero = no COD. |
specialInstructions | string (max 500) | Special handling instructions. |
productId | integer (≥ 1) | Product type ID. |
shipmentServiceIds | integer[] | 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
| Endpoint | Returns |
|---|---|
GET /create-shipment/all-services | Every 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 intototalAbsFees/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_servicesfor 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
| Condition | Message | Where you see it |
|---|---|---|
| Non-numeric value | Row 3: shipmentServiceIds must be a number | 400 on the upload request itself |
| ID does not exist | Unknown shipmentServiceIds: 99 | Job failure — error field of GET /create-shipment/bulk/status/{jobId} |
| Service exists but is deactivated | These shipment services are no longer active: 4 | Job 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-feeswithservicePricesbeforehand if you want to preview the total including add-ons before uploading the batch.
🔑 AWB and backdating
| Field | Type | Description |
|---|---|---|
awb | string | Manual AWB override. Auto-generated when omitted. Duplicate AWBs are skipped and reported in the skipped array. |
↩️ Return location
| Field | Type | Description |
|---|---|---|
returnLocationId | integer (≥ 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
| Field | Derived from |
|---|---|
businessLocationId | Sub-account warehouse (or locationId form field). |
returnBranchId | Branch of the resolved returnLocationId. |
deliveryBranchId | Branch of the district's city (DELIVERY) or warehouse branch (REVERSE). |
currentBranchId | Always null at creation. |
fromBranchId | Always 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.