Creating a Shipment

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

Overview

Use the shipping.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!) {
    shipping {
        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 shipping.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! (opens in new tab)YesFull shipment details (addresses, packaging, weight, contents)
override_service_specRateAndShipServiceSpecs (opens in new tab)NoRate 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
additionalAdditionalInfoInput (opens in new tab)NoShip Date, and any other metadata for the shipment will be added here
carrier_specificShipmentCarrierInput (opens in new tab)NoCarrier specific information, used for information not all carriers accept
order_infoOrderInfo (opens in new tab)NoTracking subscriptions, order references, custom metadata

PackageShipmentInput

Defines the physical package and routing info for the shipment.

FieldTypeRequiredDescription
packagingPackaging! (opens in new tab)YesType of package: custom box, softpack, or carrier packaging
weightWeightInput! (opens in new tab)YesTotal weight of the shipment
content_descriptionString!YesShort description of the package contents
ship_toAddressInput! (opens in new tab)YesRecipient address
ship_fromAddressInput! (opens in new tab)YesOrigin address
return_addressAddressInput (opens in new tab)NoOptional return address
extra_servicesExtraService (opens in new tab)NoInsurance, signature, etc.
hazmatHazmatInfo (opens in new tab)NoRequired for lithium batteries, dry ice, etc.
customsCustomsInput (opens in new tab)NoRequired 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_boxBoxDimensions (opens in new tab)Rigid box with length, width, height
custom_bagBagDimensions (opens in new tab)Softpack/bag with length, girth, width, height
carrier_specificCarrierSpecificPackaging (opens in new tab)Predefined 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 (opens in new tab) and can be queried with shipping.carrier_packaging (opens in new tab).

RateAndShipServiceSpecs

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

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

RateAndShipService

FieldTypeRequiredDescription
carrierCarrierCode! (opens in new tab)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_timeShippingTimeFilter (opens in new tab)Specify a max number of days or deadline date
shipping_time_guaranteeShippingTimeGuaranteeLevel (opens in new tab)Require either estimated or guaranteed delivery

OrderInfo

Optional metadata to associate with the shipment.

FieldTypeDescription
tracking_subscriptionsTrackingSubscription (opens in new tab)Email addresses to notify of shipment status
reference_numbersReferenceNumber (opens in new tab)Order numbers, invoice IDs, etc. (earlier values take priority)
carrier_specificCarrierSpecificOrderInfo (opens in new tab)Extra metadata supported by specific carriers
carrier_dependentCarrierDependentOrderInfo (opens in new tab)May 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
uspsUspsShipmentInput (opens in new tab)USPS-specific settings like container type or entry facility
fedexFedExShipmentInput (opens in new tab)FedEx-specific preferences like drop-off type or special services
dhl_expDhlExpShipmentInput (opens in new tab)DHL 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": {
        "shipping": {
            "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 (opens in new tab)
carrier_serviceCarrierService (opens in new tab)
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 addresses.validation.check (opens in new tab) query to avoid rejections