Integrations

Developer documentation

Installation guides, connection checks and API reference. Choose the connection that fits your store.

Your first working connection

Create a key in brand Applications, then make a read-only cities request. The tools below give your developer or AI assistant the exact API contract and working starter code.

  1. Applications → API → Manage API keys. Confirm your password, generate a named key and copy it once.
  2. Keep MASSAR_API_KEY in your server environment. Import OpenAPI or Postman, or download a starter.
  3. GET /cities → choose the exact city → POST /quote. No shipment is created by these checks.
  4. Map your order fields, implement safe retries and webhooks, then enable intentional orders.

The pack contains no credentials. Node needs version 20+; Python needs 3.10+. Default starter commands only read cities. Production order creation requires an explicit MASSAR_CREATE_ORDER=YES flag and your completed order file.

Build with your AI coding assistant

Copy this brief into your coding tool along with the OpenAPI link. Keep the actual key on your server, outside the chat.

Integrate my server with Massar using https://massar-eg.co/integration/openapi.json and https://massar-eg.co/integration/ai-guide.md. Ask for my framework and order-field mapping. Read MASSAR_API_KEY from my server environment; never ask me to paste it in chat. Start with GET /cities and POST /quote. Persist a stable externalOrderId and the exact payload before POST /orders. Never create shipments as a connectivity test. Resolve timeouts with lookup or identical retry, not a new ID. Verify webhook raw bytes using HMAC-SHA256 and X-Massar-Timestamp, use timing-safe comparison, reject stale timestamps, and durably deduplicate X-Massar-Delivery before acknowledging. Add local tests. Do not invent sandbox, cancellation, inventory, pickup or label endpoints. Show changes and test results before enabling real orders.

Complete endpoint map

RequestResult
GET /citiesSearch serviceable cities; data array, up to 1,000 results.
POST /quotePrice and final COD. Does not create a shipment.
POST /orders201 new order, 200 identical retry, 409 conflicting payload.
GET /orders/{externalOrderId}Your order, current status and tracking URL.
GET /webhookSubscription details or null; never returns the secret.
PUT /webhookRegister/reactivate endpoint; rotates and returns secret once.
POST /webhook/testSend signed test event; 200 accepted or 502 delivery failure.
DELETE /webhookDisable subscription; 204 with no response body.

Limit: 120 requests/minute per key. Honor Retry-After on 429/503. Keys cover the supported operations for their own brand; selectable key scopes are not available.

This API currently covers cities, pricing, order creation/lookup and webhooks. Cancellation, pickup booking, inventory management, PDF labels and a public sandbox are not exposed here. Use support for anything outside this contract.

Reliable webhooks and go-live checks

  • One public HTTPS endpoint on port 443 per brand. Every PUT rotates the secret, even for the same URL.
  • Verify untouched request bytes before parsing JSON. Use the header timestamp, a five-minute tolerance and timing-safe signature comparison.
  • Durably deduplicate X-Massar-Delivery and save a job before responding 2xx. Failed attempts retry after approximately 1m, 5m, 30m and 2h; timeout is 10 seconds.
  • Order webhooks cover API-created orders. Accept new fields/statuses and handle out-of-order events using updatedAt.
  • Before real orders: verify field/city mapping, quote totals, immutable retry payloads, secret storage and a successful signed webhook test.

Full request/response schemas, error handling and receiver persistence requirements are included in OpenAPI and the complete AI guide above.

Authentication and API keys

  1. Sign in as the brand administrator. Open Applications → API → Manage API keys.
  2. Confirm your current password. Name the key, generate it and copy it immediately. The full key is shown once.
  3. Store it as a secret on your server. Never put it in storefront JavaScript, a mobile app, a public repository or a screenshot.
  4. Each key accesses only its own brand. Revoke unused or exposed keys from the same screen.
Base URL: https://torok-api.onrender.com/api/integrations/v1
Authorization: Bearer YOUR_MASSAR_API_KEY
Content-Type: application/json

These are production endpoints. Creating an order creates a real shipment record; use only an agreed test setup for write tests. No public sandbox is advertised here.

Quick start: city → quote → order

Get a city ID first. Search accepts Arabic or English. Use the returned ID, not the city name.

curl 'https://torok-api.onrender.com/api/integrations/v1/cities?q=Nasr' \
  -H "Authorization: Bearer $MASSAR_API_KEY"

Ask for a quote. productCodAmount is the product amount in EGP, excluding Massar delivery charges. For COD, deliveryCost is added once. PREPAID means no customer cash collection.

POST /quote
{ "cityId": "CITY_ID", "productCodAmount": 1000, "paymentMethod": "COD" }

After checking the quote, create the order from your backend. The values below are illustrative, not a live test order.

{
  "externalOrderId": "YOUR-ORDER-1001",
  "receiverName": "Example customer",
  "receiverAddress": "Example street, building and apartment",
  "cityId": "CITY_ID",
  "receiverMobile1": "CUSTOMER_PHONE",
  "productCodAmount": 1000,
  "paymentMethod": "COD",
  "items": [
    {
      "itemName": "Cotton shirt",
      "sku": "SHIRT-M",
      "quantity": 1
    }
  ]
}

Send this JSON to POST /orders. Save id, externalOrderId, waybillNo, status and trackingUrl from the response. A new order returns 201 with created: true.

Order fields and limits

FieldRule
externalOrderIdRequired; stable and unique per brand, up to 120 characters.
receiverName / receiverAddressRequired; up to 160 / 500 characters.
cityId / receiverMobile1Required; city ID from /cities and recipient phone (6–32 characters).
productCodAmountRequired, from 0 to 30,000 EGP. The quote endpoint also checks the permitted total.
paymentMethodCOD or PREPAID; defaults to COD.
items1–20 items. Each needs itemName (up to 200 characters) and quantity (integer 1–999); sku is optional (up to 128).
weight / openPackage / insurancePlanOptional: weight 0–20; openPackage boolean (default false); insurancePlan NONE, BASIC, SAFETY or SECURED (default NONE).
receiverMobile2 / receiverEmail / customerNoteOptional; up to 32 / 160 / 1000 characters. Email must be valid. Unknown fields are rejected.

Retries and order lookup

After a timeout, retry with the same externalOrderId and the same request body. An identical retry returns 200 and created: false. Reusing the ID with changed data returns 409. Look up the original before deciding whether to create a different order.

GET /orders/YOUR-ORDER-1001

The lookup uses your external order ID, not the Massar waybill. URL-encode the ID when building the URL.

Signed webhooks

Provide a public HTTPS endpoint. Registering it returns a signingSecret shown once. Save that secret separately from the API key. Registering again rotates the secret.

PUT /webhook
{ "url": "https://your-store.example/api/massar/webhook" }

GET /webhook
POST /webhook/test
DELETE /webhook

Verify HMAC-SHA256 over the timestamp, a dot, and the untouched raw body. Compare in constant time with X-Massar-Signature, which starts with sha256=. Reject old timestamps and deduplicate events using X-Massar-Delivery.

HMAC_SHA256(signingSecret, X-Massar-Timestamp + "." + RAW_REQUEST_BODY)

Events include order.status_changed and order.attempt_recorded. Failed deliveries are retried up to five total attempts. Return a successful HTTP response after safely accepting the event. DELETE /webhook disables the subscription.

Errors

  • 400 — Invalid fields or city. Correct the request.
  • 401 — Missing, invalid or revoked key. Check your server secret.
  • 404 — Order not found for this brand.
  • 409 — The external ID was reused with different data.
  • 429 — Rate limited. Retry later with increasing delays.
  • 502 — Webhook test failed. Check your endpoint and logs.

Need help?

Email your store domain and affected order reference. Do not send API keys, passwords or store link codes.

contact@massar-eg.co