{
  "openapi": "3.1.0",
  "info": {
    "title": "ShippingToGo USA Merchant API",
    "version": "2026-11-06",
    "description": "US-origin shipment quotes and merchant-scoped order requests. Merchant onboarding is required. Demo credentials can request rates only. A payment link is not a carrier label, customs clearance or pickup confirmation. Customer confirmation is required before a shipment request or checkout."
  },
  "servers": [
    {
      "url": "https://shippingtogousai.com/api/us/b2b/v1"
    }
  ],
  "security": [
    {
      "merchantBearer": []
    }
  ],
  "paths": {
    "/me": {
      "get": {
        "operationId": "getMerchantContext",
        "summary": "Read the authenticated merchant and mode",
        "responses": {
          "200": {
            "description": "Merchant identifier and live or demo_rates_only mode"
          },
          "401": {
            "description": "Merchant authentication required"
          }
        }
      }
    },
    "/rates": {
      "post": {
        "operationId": "requestShipmentQuote",
        "summary": "Request available rates for actual shipment facts",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Shipment"
              },
              "examples": {
                "package": {
                  "value": {
                    "origin": {
                      "street": "350 5th Ave",
                      "city": "New York",
                      "state": "NY",
                      "zip": "10118",
                      "country": "US"
                    },
                    "destination": {
                      "street": "10 Downing St",
                      "city": "London",
                      "zip": "SW1A 2AA",
                      "country": "GB"
                    },
                    "kind": "package",
                    "packages": [
                      {
                        "weight": 2,
                        "weightUnit": "lb",
                        "length": 12,
                        "width": 10,
                        "height": 6,
                        "dimUnit": "in"
                      }
                    ],
                    "contents": {
                      "description": "Cotton shirts",
                      "valueUsd": 50,
                      "purpose": "SOLD"
                    }
                  }
                },
                "document": {
                  "value": {
                    "origin": {
                      "street": "350 5th Ave",
                      "city": "New York",
                      "state": "NY",
                      "zip": "10118",
                      "country": "US"
                    },
                    "destination": {
                      "street": "10 Downing St",
                      "city": "London",
                      "zip": "SW1A 2AA",
                      "country": "GB"
                    },
                    "kind": "document",
                    "packages": [
                      {
                        "weight": 0.5,
                        "weightUnit": "lb"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved quoteId, public priced lines and expiry; only returned services are available"
          },
          "400": {
            "description": "Shipment details invalid or incomplete"
          },
          "401": {
            "description": "Merchant authentication required"
          },
          "503": {
            "description": "Quoting is unavailable; do not invent a price"
          }
        }
      }
    },
    "/shipments": {
      "post": {
        "operationId": "requestMerchantShipment",
        "summary": "Create or resume a merchant order request with a unique store reference",
        "description": "Use the same reference to retry the same order. Requires customer confirmation and a non-demo merchant. Fulfillment is a separate reviewed process.",
        "x-human-confirmation-required": true,
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "reference",
                  "quoteId",
                  "lineIndex",
                  "shipper",
                  "recipient"
                ],
                "properties": {
                  "reference": {
                    "type": "string",
                    "maxLength": 80
                  },
                  "quoteId": {
                    "type": "string"
                  },
                  "lineIndex": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "shipper": {
                    "$ref": "#/components/schemas/Shipper"
                  },
                  "recipient": {
                    "$ref": "#/components/schemas/Recipient"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Shipment request created; paymentUrl may require customer checkout"
          },
          "200": {
            "description": "Existing request for this merchant reference"
          },
          "400": {
            "description": "Invalid reference, quote or contacts"
          },
          "401": {
            "description": "Merchant authentication required"
          },
          "403": {
            "description": "Rates-only demo cannot create shipments"
          },
          "409": {
            "description": "Existing order or quote cannot resume checkout"
          },
          "503": {
            "description": "Checkout provider is unavailable"
          }
        }
      }
    },
    "/shipments/{id}": {
      "get": {
        "operationId": "getMerchantShipment",
        "summary": "Read a shipment request belonging to this merchant",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Stored merchant shipment state and available tracking reference"
          },
          "401": {
            "description": "Merchant authentication required"
          },
          "404": {
            "description": "Shipment not found for this merchant"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "merchantBearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Store only on your server. Do not expose merchant keys in browser code or chat."
      }
    },
    "schemas": {
      "Address": {
        "type": "object",
        "required": [
          "street",
          "city",
          "country"
        ],
        "properties": {
          "street": {
            "type": "string"
          },
          "city": {
            "type": "string"
          },
          "state": {
            "type": "string"
          },
          "zip": {
            "type": "string"
          },
          "country": {
            "type": "string",
            "pattern": "^[A-Z]{2}$"
          },
          "residential": {
            "type": "boolean"
          }
        },
        "description": "US addresses require two-letter state and five-digit ZIP. Use the destination postal code and country requirements for the actual route."
      },
      "Package": {
        "type": "object",
        "required": [
          "weight",
          "weightUnit",
          "length",
          "width",
          "height",
          "dimUnit"
        ],
        "properties": {
          "weight": {
            "type": "number",
            "exclusiveMinimum": 0
          },
          "weightUnit": {
            "enum": [
              "lb",
              "kg"
            ]
          },
          "length": {
            "type": "number",
            "exclusiveMinimum": 0
          },
          "width": {
            "type": "number",
            "exclusiveMinimum": 0
          },
          "height": {
            "type": "number",
            "exclusiveMinimum": 0
          },
          "dimUnit": {
            "enum": [
              "in",
              "cm"
            ]
          }
        }
      },
      "Shipment": {
        "type": "object",
        "required": [
          "origin",
          "destination",
          "packages"
        ],
        "properties": {
          "origin": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Address"
              },
              {
                "properties": {
                  "country": {
                    "const": "US"
                  }
                }
              }
            ]
          },
          "destination": {
            "$ref": "#/components/schemas/Address"
          },
          "kind": {
            "enum": [
              "package",
              "document"
            ]
          },
          "packages": {
            "type": "array",
            "minItems": 1,
            "maxItems": 10,
            "items": {
              "anyOf": [
                {
                  "$ref": "#/components/schemas/Package"
                },
                {
                  "$ref": "#/components/schemas/DocumentPackage"
                }
              ]
            }
          },
          "contents": {
            "type": "object",
            "required": [
              "description",
              "valueUsd"
            ],
            "properties": {
              "description": {
                "type": "string",
                "minLength": 3,
                "maxLength": 100
              },
              "valueUsd": {
                "type": "number",
                "exclusiveMinimum": 0,
                "maximum": 50000
              },
              "purpose": {
                "enum": [
                  "SOLD",
                  "GIFT",
                  "PERSONAL_EFFECTS",
                  "SAMPLE"
                ]
              }
            }
          }
        },
        "description": "International goods require contents. Documents are limited to one carrier envelope, at most 1 lb. Quote facts do not replace reviewed customs declarations.",
        "allOf": [
          {
            "if": {
              "required": [
                "kind"
              ],
              "properties": {
                "kind": {
                  "const": "document"
                }
              }
            },
            "then": {
              "properties": {
                "packages": {
                  "maxItems": 1,
                  "items": {
                    "$ref": "#/components/schemas/DocumentPackage"
                  }
                }
              }
            },
            "else": {
              "properties": {
                "packages": {
                  "items": {
                    "$ref": "#/components/schemas/Package"
                  }
                }
              }
            }
          }
        ]
      },
      "Shipper": {
        "type": "object",
        "required": [
          "name",
          "email",
          "phone"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "phone": {
            "type": "string"
          }
        }
      },
      "Recipient": {
        "type": "object",
        "required": [
          "name",
          "phone"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "phone": {
            "type": "string"
          }
        }
      },
      "DocumentPackage": {
        "type": "object",
        "required": [
          "weight",
          "weightUnit"
        ],
        "properties": {
          "weight": {
            "type": "number",
            "exclusiveMinimum": 0
          },
          "weightUnit": {
            "enum": [
              "lb",
              "kg"
            ]
          }
        },
        "description": "One carrier document envelope. Maximum actual weight is 1 lb. The server sets its envelope dimensions."
      }
    }
  }
}
