#!/bin/bash
# CreateShipment (Final Mile) -- REST curl example
# Pre-configured for the DM Web Services test environment.
# Replace YOUR_TOKEN below with your Bearer token.
#
# Final Mile (recordLayout=3): OMIT the shipper block -- the last-mile carrier
# assigns the origin terminal and the system writes it back to the shipper fields.
# Set carrierReferenceCode to your last-mile carrier code (provided by DM).
#
# The three ASN elements below are REQUIRED for a Final Mile shipment. If any is
# missing the shipment is still created, but carrier registration is skipped and a
# warning is returned in the response errors array (no carrier PRO number):
#   date       "Expected at Terminal"
#   reference  "1st Leg - Carrier Name"
#   reference  "1st Leg - CarrierPro"

BASE_URL="https://webservices.nebulasuite.net"
TOKEN="YOUR_TOKEN"

curl -X POST "${BASE_URL}/api/public/v1/shipping/CreateShipment" \
  -H "Authorization: Bearer ${TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
    "clientReferenceCode": "YOUR-CLIENT-CODE",
    "carrierReferenceCode": "CARRIER-CODE",
    "serviceLevelCode": "OHN",
    "recordLayout": 3,
    "consignee": {
      "name": "John Smith",
      "address1": "123 Main Street",
      "city": "Austin",
      "state": "TX",
      "zip": "78701",
      "phone": "5125551234"
    },
    "lineItems": [
      {
        "pieces": 1,
        "weight": 65,
        "length": 24,
        "width": 12,
        "height": 10,
        "description": "Furniture piece"
      }
    ],
    "dates": [
      { "dateType": "Expected at Terminal", "dateValue": "2026-04-20T00:00:00Z" }
    ],
    "references": [
      { "referenceType": "1st Leg - Carrier Name", "data": "Acme LTL Freight" },
      { "referenceType": "1st Leg - CarrierPro", "data": "BOL-987654" }
    ]
  }'
