Create a USPS Shipment

HTTP Request

POST /v1/shipments

Summary

This operation creates a shipment and purchases a shipment label using USPS as the carrier. The API returns the label as either a Base64 string or a link to a PDF.

Things to Consider

  1. Address Validation: Addresses are verified for accuracy prior to processing the label request. By default, address validation does the following:

    • Verifies the delivery line (street address) and last line (city/state/postal code) for completeness.
    • Returns an error if the address is incomplete or if current USPS data indicates no delivery to that address.
    • Makes corrections to the delivery line or last line when possible.

    If you set MINIMAL_ADDRESS_VALIDATION to true in the request body, the API changes the behavior of bullet 3: the API makes corrections only to the last line (city/state/postal code). The delivery line (street address) is printed exactly as specified in the request. Keep in mind, the API still checks the whole address for completeness and still returns an error if any part of the address, including the delivery line, is incomplete or marked “Undeliverable” by USPS. If you use minimal address validation, always ensure the delivery line you enter is actually deliverable.

    Note: If MINIMAL_ADDRESS_VALIDATION is set to true, the shipper takes 100% responsibility for any undelivered packages due to violation of carrier-addressing guidelines and is responsible for any surcharge or adjustment fee levied by the carrier for such a violation.

  2. Shipper ID: To print a shipment label, you must specify a SHIPPER_ID in the shipmentOptions array and set its value to the merchant’s postalReportingNumber, which you can retrieve using the Get All Merchants API.

  3. Dimensions: Parcels cannot measure more than 108 inches in length and girth combined, with the exception of those using USPS Parcel Select. Those using Parcel Select can measure up to 130 inches in length and girth combined.

    For all parcels, the PB Complete Shipping APIs configure length as the longest dimension, followed by height, followed by width. The APIs configure girth as twice the sum of the height and width:

    girth = 2 * (height+width)

    In addition to the limit on combined length and girth, other limits also apply. Refer to the USPS rules at https://pe.usps.com/text/qsg300/Q201e.htm.

  4. Soft Packs: For soft packs:

    • the sum of the longest and next-longest dimensions must not exceed 36 inches
    • the longest dimension must not exceed 18 inches
    • the smallest dimension must not exceed 2 inches

    The measurements must be taken prior to placing the item in the envelope.

  5. Services: For available services and special services, see USPS Services, Parcel Types, and Label Sizes.

    To view a service’s compatible special services and to determine any restrictions on a service or special service, use the Carrier Rules API or see the USPS Domestic Mail Manual.

  6. Tracking Requirement: The PB Complete Shipping APIs require that all parcels be trackable. If the parcel uses a service that is not trackable, such as Priority Mail (PM), you must add at least one trackable special service, such as Delivery Confirmation (DelCon). DelCon is a no-charge special service that triggers tracking but does not increase the cost of the shipment.

  7. IMb: To send a letter or flat with an IMb (Intelligent Mail barcode), use the parameters listed in this FAQ when making this API call.

  8. Customs: You must include the customs object for shipments to the following destinations:

    • APO/FPO
    • U.S. territories (except VI & PR)
    • U.S. possessions
    • Freely Associated States
    • Countries outside the U.S.

    You must also set the documents.size field to DOC_4X6 or DOC_8X11.

    The API will automatically provide the correct USPS customs form based on the information supplied in the request. The form is used as both the shipping label and the customs declaration. For shipments to participating countries and to APO/FPO/DPO destinations, the customs form will be a single-ply form. As of this writing, the participating countries are Australia, Canada, and Costa Rica.

  9. USPS SCAN form: To make a shipment eligible for inclusion in a USPS SCAN form, set the ADD_TO_MANIFEST option to true in the shipmentOptions array. To add the shipment to a SCAN form, issue the Create Manifest API call.

    If the shipment is not added to the SCAN form by 6 a.m. UTC/GMT the next calendar day, Pitney Bowes auto-manifests the shipment.

    The following shipments cannot be added to a SCAN form:

    • First-Class Mail (FCM) flats (FLAT)
    • First-Class Mail (FCM) letters (LETTER)
    • Scan-Based Returns. Note: If you are creating an SBR label, do not use this page but instead use the instructions on this page.
  10. Shipment Options: For additional shipment options, see Shipment Options.

  11. Label: The label is returned as either a Base64 string or a URL that links to a PDF. Labels retrieved through URLs are available for 24 hours after label creation. For label options, see USPS Label Sizes & Formats.

    Note: First-Class (FCM) shipments that use the LETTER or FLAT parcel type are supported only for 6X4 labels. You must set the documents.size field DOC_6X4.

  12. Error Handling: If your request returns the HTTP 500 Internal Server Error, do not resubmit the request without first checking whether the label was created. To check whether the label was created, issue the Retry Shipment API.

Request URIs

Sandbox: https://api-sandbox.pitneybowes.com/shippingservices/v1/shipments
Production: https://api.pitneybowes.com/shippingservices/v1/shipments

Query Parameter

The query parameter is optional.

Name Data Type Description
includeDeliveryCommitment Boolean

If set to true, returns estimated transit times in days.

See also:

Request Headers

Name Description
Authorization Required. OAuth token generated using the Generate an OAuth Token API.
Content-Type Required. The media type of the request entity. Set this to application/json.
X-PB-TransactionId

Required. A unique identifier for the transaction, up to 25 characters.

Important: You must ensure this is a unique id.

X-PB-Shipper-Rate-Plan Shipper rate plan, if applicable. For more information, see this FAQ.
X-PB-Integrator-CarrierId Negotiated services rate, if applicable.
X-PB-UnifiedErrorStructure
Recommended. Set this to true to use the standard error object if an error occurs.

Request / Response Elements

The API call sends and receives a shipment object.

IMPORTANT: Some fields might not apply to your operation and are marked as such. This table describes all the possible fields in a shipment object.

Name Data Type Description
fromAddress address object

Required. Origin address.

If you want a different address to appear on the label, see How do I print a return address that is different from the origin address?

toAddress address object Required. Destination address.
altReturnAddress address object USPS International Shipments Only. If you are sending an international shipment through USPS and if you have set the NON_DELIVERY_OPTION shipment option to redirect, then enter the address that a returned parcel should go to.
parcel parcel object Required. Contains physical characteristics of the parcel.
rates Array[rates object]

Required. Specifies carrier, service, parcel type, and other information. In a response, this field specifies the service charges.

Important: In a request, the rates array can contain only one rates object.

documents Array[documents object] The shipment documents, including the label. This field does not apply to Rate a Package requests.
shipmentOptions Array[Object]

Each object in this array defines a shipment option. The required and available options depend on your carrier. Please see the Things to Consider section on your carrier’s Create Shipment page.

Required for all carriers: For all carriers, the Create Shipment request requires the SHIPPER_ID option.

        name String The name of the shipment option. The shipmentOptions array requires this field.
        value String The value of the shipment option. The shipmentOptions array requires this field.
customs customs object

Applies only to USPS shipments to these locations:

  • International
  • APO/FPO/DPO
  • Territories/Possessions
  • FAS

This field contains customs information.

shipmentType String SBR Labels Only. If you are creating a Scan-Based Return (SBR) label, include this field and set the value to RETURN.
references Array[Object]

Newgistics Only. This array maps client-generated identifiers to fields in the Newgistics package record. The information in this array does not appear on the shipping label.

The array takes up to three objects, and each object maps an identifier to a specific Newgistics field. An object’s sequence in the array determines which Newgistics field the object maps to. The first object in the array maps to the Newgistics “ReferenceNumber” field; the second to the “AddlRef1” field; and the third to the “AddlRef2” field.

Use the syntax shown below. Enter the names in the order shown. If you enter different names, the system will change them to the names below. In the value fields, enter the client-generated identifiers. The values must be strings of no more than 50 characters each. For additional information on using references, merchants can contact their Newgistics representatives.

{
    "name": "ReferenceNumber",
    "value": "<client identifier 1>"
}, {
    "name": "AddlRef1",
    "value": "<client identifier 2>"
}, {
    "name": "AddlRef2",
    "value": "<client identifier 3>"
}
shipmentId String Response Only. Unique identifier for the shipment, generated by the system in response to shipment purchase.
parcelTrackingNumber String Response Only. Tracking number assigned to the shipment by the system.

Sample Requests and Responses

See the following examples:

For a sample request for a Doc Tab label, see How do I print a Doc Tab label?

Domestic Shipment Sample Request

The following example includes the includeDeliveryCommitment query parameter.

curl -X POST .../v1/shipments?includeDeliveryCommitment=true \
-H "Authorization: Bearer l8wHkQKaBjC5VEaYldQnFXnzoqNj" \
-H "Content-Type: application/json" \
-H "X-PB-TransactionId: 76e4498e-85fe-43a1-b6d0" \
-H "X-PB-UnifiedErrorStructure: true" \
-d '
{
    "fromAddress" : {
        "company" : "Supplier",
        "name" : "J. Smith",
        "phone" : "303-555-1213",
        "email" : "js@example.com",
        "residential" : false,
        "addressLines" : [ "4750 Walnut Street" ],
        "cityTown" : "Boulder",
        "stateProvince" : "CO",
        "postalCode" : "80301",
        "countryCode" : "US"
    },
    "toAddress": {
        "company": "Shop",
        "name": "J. Jones",
        "phone": "203-000-1234",
        "email": "jjones@example.com",
        "residential": false,
        "addressLines": [ "771 Orange St" ],
        "cityTown": "New Haven",
        "stateProvince": "CT",
        "postalCode": "06511",
        "countryCode": "US"
    },
    "parcel": {
        "weight": {
            "unitOfMeasurement": "OZ",
            "weight": 8
        },
        "dimension": {
            "unitOfMeasurement": "IN",
            "length": 6.0,
            "width": 1.0,
            "height": 4.0
        }
    },
    "rates": [ {
        "carrier": "USPS",
        "serviceId": "PM",
        "parcelType": "PKG",
        "specialServices": [ {
            "specialServiceId": "Ins",
            "inputParameters": [ {
                "name": "INPUT_VALUE",
                "value": "50"
            } ]
        }, {
            "specialServiceId": "DelCon",
            "inputParameters": [ {
                "name": "INPUT_VALUE",
                "value": "0"
            } ]
        } ],
        "inductionPostalCode": "06484"
    } ],
    "documents": [ {
        "type": "SHIPPING_LABEL",
        "contentType": "BASE64",
        "size": "DOC_4X6",
        "fileFormat": "PNG",
        "resolution": "DPI_203",
        "printDialogOption": "EMBED_PRINT_DIALOG"
    } ],
    "shipmentOptions": [ {
        "name": "SHIPPER_ID",
        "value": "9024324564"
    }, {
        "name": "ADD_TO_MANIFEST",
        "value": "true"
    }, {
        "name": "MINIMAL_ADDRESS_VALIDATION",
        "value": "true"
    } ]
}'

Domestic Shipment Sample Response

{
    "fromAddress": {
        "company": "Supplier",
        "name": "J. Smith",
        "phone": "303-555-1213",
        "email": "js@example.com",
        "residential": false,
        "addressLines": [
            "4750 Walnut Street"
        ],
        "cityTown": "Boulder",
        "stateProvince": "CO",
        "postalCode": "80301-2532",
        "countryCode": "US",
        "deliveryPoint": "99",
        "carrierRoute": "C033"
    },
    "toAddress": {
        "company": "Shop",
        "name": "J. Jones",
        "phone": "203-000-1234",
        "email": "jjones@example.com",
        "residential": false,
        "addressLines": [
            "771 Orange St"
        ],
        "cityTown": "New Haven",
        "stateProvince": "CT",
        "postalCode": "06511-2536",
        "countryCode": "US",
        "deliveryPoint": "71",
        "carrierRoute": "C008"
    },
    "parcel": {
        "weight": {
            "unitOfMeasurement": "OZ",
            "weight": 8
        },
        "dimension": {
            "unitOfMeasurement": "IN",
            "length": 6,
            "width": 1,
            "height": 4,
            "irregularParcelGirth": 0
        }
    },
    "rates": [ {
        "carrier": "USPS",
        "parcelType": "PKG",
        "inductionPostalCode": "06484",
        "specialServices": [ {
            "specialServiceId": "Ins",
            "inputParameters": [ {
                "name": "INPUT_VALUE",
                "value": "50"
            } ],
            "fee": 0
        }, {
            "specialServiceId": "DelCon",
            "inputParameters": [ {
                "name": "INPUT_VALUE",
                "value": "0"
            } ],
            "fee": 0
        } ],
        "serviceId": "PM",
        "deliveryCommitment": {
            "minEstimatedNumberOfDays": "1",
            "maxEstimatedNumberOfDays": "1",
            "estimatedDeliveryDateTime": "2018-02-15",
            "guarantee": "NONE",
            "additionalDetails": "By end of Day"
        },
        "dimensionalWeight": {
            "weight": 0,
            "unitOfMeasurement": "OZ"
        },
        "baseCharge": 5.81,
        "totalCarrierCharge": 5.81,
        "currencyCode": "USD",
        "destinationZone": "1"
    } ],
    "documents": [ {
        "size": "DOC_4X6",
        "type": "SHIPPING_LABEL",
        "contentType": "BASE64",
        "fileFormat": "PNG",
        "pages": [ {
            "contents": "iVBORw0KGgoAAAANSUhEUgAABLAAAAcIAQAAAAAEKwXnAAAACXBIWXMAAC..."
        } ]
    } ],
    "shipmentOptions": [ {
        "name": "HIDE_TOTAL_CARRIER_CHARGE",
        "value": "true"
    }, {
        "name": "SHIPPER_ID",
        "value": "9024324564"
    }, {
        "name": "ADD_TO_MANIFEST",
        "value": "true"
    }, {
       "name": "FUTURE_SHIPMENT_DATE",
        "value": "2018-02-14"
    },
    {
        "name": "MINIMAL_ADDRESS_VALIDATION",
        "value": "true"
    },
    {
        "name": "SHIPPING_LABEL_RECEIPT",
        "value": "noOptions"
    } ],
    "shipmentId": "USPS2200145762537624",
    "parcelTrackingNumber": "9405509898642000588417"
}

International Shipment Sample Request

curl -X POST .../v1/shipments?includeDeliveryCommitment=true \
-H "Authorization: Bearer l8wHkQKaBjC5VEaYldQnFXnzoqNj" \
-H "Content-Type: application/json" \
-H "X-PB-TransactionId: 93e30b6f-b6cc-4528-bef0" \
-H "X-PB-UnifiedErrorStructure: true" \
-d '
{
    "fromAddress": {
        ...
    },
    "toAddress": {
        ...
    },
    "parcel": {
        "weight": {
            "unitOfMeasurement": "OZ",
            "weight": 9
        },
        "dimension": {
            "unitOfMeasurement": "IN",
            "length": 8.0,
            "width": 1.0,
            "height": 2.0
        }
    },
    "rates": [ {
        "carrier": "USPS",
        "serviceId": "EMI",
        "parcelType": "FRE",
        "specialServices": [ {
            "specialServiceId": "Ins",
            "inputParameters": [ {
                "name": "INPUT_VALUE",
                "value": "100"
            } ]
        } ],
        "inductionPostalCode": "06510"
    } ],
    "customs": {
        "customsInfo": {
            "reasonForExport": "MERCHANDISE",
            "comments": "Books",
            "invoiceNumber": "001189223",
            "importerCustomsReference": "987654",
            "insuredNumber": "insuredNumber0",
            "insuredAmount": 100.0,
            "sdrValue": 66.87,
            "fromCustomsReference": "11111",
            "currencyCode": "GBP",
            "licenseNumber": "456ABC123",
            "certificateNumber": "987"
        },
        "customsItems": [ {
            "description": "Books",
            "quantity": 3,
            "unitPrice": 33.00,
            "unitWeight": {
                "weight": 3.0,
                "unitOfMeasurement": "OZ"
            },
            "hSTariffCode": "AST559",
            "originCountryCode": "US"
           } ]
       },
    "documents": [ {
        "type": "SHIPPING_LABEL",
        "contentType": "URL",
        "size": "DOC_4X6",
        "fileFormat": "PDF",
        "printDialogOption": "EMBED_PRINT_DIALOG"
    } ],
    "shipmentOptions": [{
        "name": "SHIPPER_ID",
        "value": "9024324564"
    }, {
        "name": "ADD_TO_MANIFEST",
        "value": "true"
    } ]
}

International Shipment Sample Response

{
    "fromAddress": {
        ...
    },
    "toAddress": {
        ...
    },
    "parcel": {
        "weight": {
            "unitOfMeasurement": "OZ",
            "weight": 9
        },
        "dimension": {
            "unitOfMeasurement": "IN",
            "length": 8,
            "width": 1,
            "height": 2,
            "irregularParcelGirth": 0
        }
    },
    "rates": [ {
        "carrier": "USPS",
        "parcelType": "FRE",
        "inductionPostalCode": "06510",
        "specialServices": [ {
            "specialServiceId": "Ins",
            "inputParameters": [ {
                "name": "INPUT_VALUE",
                "value": "100"
            } ],
            "fee": 0
        } ],
        "serviceId": "EMI",
        "dimensionalWeight": {
            "weight": 0,
            "unitOfMeasurement": "OZ"
        },
        "baseCharge": 56.61,
        "totalCarrierCharge": 56.61,
        "currencyCode": "USD",
        "destinationZone": "4"
    } ],
    "documents": [ {
        "type": "SHIPPING_LABEL",
        "contentType": "URL",
        "fileFormat": "PDF",
        "contents": "https://.../usps/198715941/outbound/label/8649470d08564e88b716255f64f6b18d.pdf"
    } ],
    "shipmentOptions": [ {
        "name": "HIDE_TOTAL_CARRIER_CHARGE",
        "value": "false"
    }, {
        "name": "SHIPPER_ID",
        "value": "9024324564"
    }, {
        "name": "ADD_TO_MANIFEST",
        "value": "true"
    }, {
        "name": "FUTURE_SHIPMENT_DATE",
        "value": "2018-02-14"
    }, {
        "name": "MINIMAL_ADDRESS_VALIDATION",
        "value": "false"
    }, {
        "name": "SHIPPING_LABEL_RECEIPT",
        "value": "noOptions"
    } ],
    "shipmentId": "USPS2200146002128591",
    "customs": {
        "customsInfo": {
            "reasonForExport": "MERCHANDISE",
            "comments": "Books",
            "invoiceNumber": "001189223",
            "importerCustomsReference": "987654",
            "insuredNumber": "insuredNumber0",
            "insuredAmount": 100,
            "sdrValue": 66.87,
            "fromCustomsReference": "11111",
            "currencyCode": "GBP",
            "licenseNumber": "456ABC123",
            "certificateNumber": "987",
            "freightCharge": 0,
            "packingCosts": 0,
            "handlingCosts": 0,
            "otherCharge": 0
        },
        "customsItems": [ {
            "description": "Books",
            "quantity": 3,
            "unitPrice": 33,
            "unitWeight": {
                "weight": 3,
                "unitOfMeasurement": "OZ"
            },
            "hSTariffCode": "AST559",
            "originCountryCode": "US"
        } ]
    },
    "parcelTrackingNumber": "EP863272143US"
}

Error Codes

For a list of all PB Complete Shipping APIs error codes, see Error Codes.