Creating a Shipment

Generate a shipping label and track it — all in one step.

Overview

Use the rate_and_ship mutation to create a shipment, generate a label, and assign it to a batch.
This operation returns structured pricing, carrier service info, label file links, and payment handling (if required).

Mutation Format

mutation rate_and_ship($request: [RateAndShipInput!]!, $service_spec: RateAndShipServiceSpecs!) {
    rate_and_ship(request: $request, service_spec: $service_spec) {
        batch_id
        batch {
            id
            created_at
            batch_pdf_url
            payment_details {
                total_billed
                total_collected
                paid
            }
        }
        shipments {
            ... on Shipment {
                id
                tracking_number
                label {
                    png {
                        url
                    }
                }
            }
            ... on ShipmentPaymentRequired {
                payment_link
                expires_at
            }
            ... on ShipmentError {
                code
                message
            }
        }
    }
}

Required Input

The rate_and_ship mutation requires two inputs:

  1. request: [[RateAndShipInput!]!](/developer/api-reference/type/RateAndShipInput) – one or more full shipment definitions
  2. service_spec: [RateAndShipServiceSpecs](/developer/api-reference/type/RateAndShipServiceSpecs) – how to rate and select a carrier

RateAndShipInput

Each object in the request array must include:

FieldTypeRequiredDescription
transaction_idUUID!YesUnique ID for tracking this shipment request
packagePackageShipmentInput!YesFull shipment details (addresses, packaging, weight, contents)
override_service_specRateAndShipServiceSpecsNoRate and Ship Service Specs Defines which carrier services to rate, how to prioritize the results, and any filters to apply. This overrides the root service_spec for the specified package
additionalAdditionalInfoInputNoShip Date, and any other metadata for the shipment will be added here
carrier_specificShipmentCarrierInputNoCarrier specific information, used for information not all carriers accept
order_infoOrderInfoNoTracking subscriptions, order references, custom metadata

PackageShipmentInput

Defines the physical package and routing info for the shipment.

FieldTypeRequiredDescription
packagingPackaging!YesType of package: custom box, softpack, or carrier packaging
weightWeightInput!YesTotal weight of the shipment
content_descriptionString!YesShort description of the package contents
ship_toAddressInput!YesRecipient address
ship_fromAddressInput!YesOrigin address
return_addressAddressInputNoOptional return address
extra_servicesExtraServiceNoInsurance, signature, etc.
hazmatHazmatInfoNoRequired for lithium batteries, dry ice, etc.
customsCustomsInputNoRequired for international shipments

Packaging

Specifies the type of container used for the shipment.
This is a @oneOf input — only one of the following fields can be set:

FieldTypeDescription
custom_boxBoxDimensionsRigid box with length, width, height
custom_bagBagDimensionsSoftpack/bag with length, girth, width, height
carrier_specificCarrierSpecificPackagingPredefined packaging code from a carrier (e.g. USPS Flat Rate Envelope or FedEx Envelope)

The available carrier-provided packaging codes are listed in Carrier-Provided Packaging and can be queried with shipping.carrier_packaging.

RateAndShipServiceSpecs

Defines which carrier services to consider and how to choose the best one.

FieldTypeRequiredDescription
services[RateAndShipService!]!YesList of carriers and services to rate
priorityRateAndShipPriority!YesHow to select the final rate (CHEAPEST or FASTEST)
filtersRateAndShipFiltersNoOptional rules (e.g. max price, guaranteed delivery)

RateAndShipService

FieldTypeRequiredDescription
carrierCarrierCode!YesCarrier to use (e.g. UPS, USPS, FedEx)
service_codeString!YesSpecific carrier service (e.g. GND, PRIORITY_MAIL)
account_numberStringNoShipper account to use for rating. Omit to use platform default (if allowed)

RateAndShipFilters

Optional filters to restrict which services can be selected.

FieldTypeDescription
max_costDecimalExclude any rates above this value
shipping_timeShippingTimeFilterSpecify a max number of days or deadline date
shipping_time_guaranteeShippingTimeGuaranteeLevelRequire either estimated or guaranteed delivery

OrderInfo

Optional metadata to associate with the shipment.

FieldTypeDescription
tracking_subscriptionsTrackingSubscriptionEmail addresses to notify of shipment status
reference_numbersReferenceNumberOrder numbers, invoice IDs, etc. (earlier values take priority)
carrier_specificCarrierSpecificOrderInfoExtra metadata supported by specific carriers
carrier_dependentCarrierDependentOrderInfoMay be ignored by some carriers (e.g. delivery notes)

AdditionalInfoInput

Additional information about the Shipment

FieldTypeDescription
ship_dateDateTimeThe DateTime you expect to ship the package

ShipmentCarrierInput

Carrier-specific options that affect how the shipment is processed.
Each field is an optional nested input tailored to a specific carrier.

FieldTypeDescription
uspsUspsShipmentInputUSPS-specific settings like container type or entry facility
fedexFedExShipmentInputFedEx-specific preferences like drop-off type or special services
dhl_expDhlExpShipmentInputDHL Express options such as duties payment or label format

What You Get Back

The response includes a batch, which contains one or more shipments.
Each shipment will be one of the following:

  • Shipment: fully purchased with label and tracking
  • ShipmentPaymentRequired: label is ready, but payment must be completed first
  • ShipmentError: something went wrong, like an invalid address or unsupported service

Successful Shipment

{
    "data": {
        "rate_and_ship": {
            "batch_id": "5e7a131e-a21e-47f8-a09b-7abb92a2bca7",
            "batch": {
                "id": "5e7a131e-a21e-47f8-a09b-7abb92a2bca7",
                "created_at": "2025-06-24T16:00:00Z",
                "batch_pdf_url": "https://ENV_URL/api/media/label/44a22efd-2440-4758-a7ac-9a2927a67d64.png",
                "payment_details": {
                    "total_billed": 9.21,
                    "total_collected": 9.21,
                    "paid": true
                }
            },
            "shipments": [
                {
                    "__typename": "Shipment",
                    "id": "b23e9f16-4a75-4d92-8c60-3e18b7a05d24",
                    "tracking_number": "1Z12345E0205271688",
                    "label": {
                        "png": {
                            "url": "https://ENV_URL/api/media/label/44a22efd-2440-4758-a7ac-9a2927a67d64.png"
                        }
                    }
                }
            ]
        }
    }
}

Payment Required

WARNING

This response only applies to individual (retail) accounts.
Platform or prepaid accounts will never receive this response.

{
    "__typename": "ShipmentPaymentRequired",
    "id": "f80c47d3-1e69-4b52-9a37-6c05e2b81f9d",
    "payment_link": {
        "url": "PAYMENT_LINK"
    },
    "expires_at": "2025-06-24T17:00:00Z"
}

Shipment Error

Returned when the shipment could not be created due to invalid input, rate failure, or carrier restrictions.

{
    "__typename": "ShipmentError",
    "code": "INVALID_ADDRESS",
    "message": "Postal code is required."
}

Batch Overview

A batch groups multiple shipments into a single label download and payment group.

FieldDescription
idUnique ID of the batch
batch_pdf_urlDownload link for the combined label PDF
created_atWhen the batch was created
payment_detailsAmounts and status of batch billing
shipmentsList of all attempted shipments in the batch

Shipment Object (on success)

A Shipment object represents a fully purchased label, complete with carrier info, pricing, and file access.

FieldDescription
idUnique shipment ID
carrierCarrier
carrier_serviceCarrierService
tracking_numberCarrier-assigned tracking number
labelLabel download links (PNG, ZPL)
billing_weightFinal billed weight (actual or dimensional)
total_priceFinal total cost
base_priceCost before surcharges and extras
labelgenius_chargeCharge owed to ShipGenius
itemized_chargesFull charge breakdown (carrier + platform fees)
warningsOptional carrier-level warnings
disclaimersLegal or carrier advisories
estimated_deliveryEstimated delivery date
guaranteed_deliveryWhether delivery date is guaranteed

Tips

  • You can submit multiple shipments at once using request: [RateAndShipInput!]!
  • Use batch.payment_details to track billing, refunds, and total invoiced
  • Use batch.batch_pdf_url to download all generated labels in one PDF
  • ShipmentError responses are non-blocking — other shipments in the same batch may still succeed
  • Always validate addresses beforehand using the address_validation query to avoid rejections