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 validated for accuracy prior to processing the label request. An error is returned if validation fails. By default, the complete address (the address lines and the city/state/zip) is validated. You can modify this behavior in the request body’s shipmentOptions array:

    • If you set MINIMAL_ADDRESS_VALIDATION to true, only the city/state/zip is checked for validity. The address lines are not validated and are printed on the label exactly as specified in the request.

      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.

    • If you set MINIMAL_ADDRESS_VALIDATION to false, which is the default, the complete address (the address lines and the city/state/zip) is included in the validation check.

  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 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 maximum total of length plus height cannot exceed 36 inches. The smallest dimension, or width, cannot exceed 2 inches. The measurement must be taken prior to placing items in the envelope.

  5. Services: For available services and special services, see Supported Services & Parcel Types.

    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 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 in the request for shipments headed to the following destinations:

    • APO/FPO
    • U.S. territories (except VI & PR)
    • U.S. possessions
    • Freely Associated States
    • Countries outside the U.S.
  9. Customs Forms: The POST /shipments API call generates single-ply customs declaration forms (PS Form 2976-A and PS Form 2976-B) for APO/FPO/DPO destinations and for participating countries. As of this writing, the participating countries are Australia, Canada, and Costa Rica. For more information on customs forms, see this FAQ.

  10. Manifest: In order to include a shipment in a manifest, you must include the ADD_TO_MANIFEST option set to true in the shipmentOptions array.

    The following shipments cannot be added to a manifest:

    • 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.
  11. Shipment Options: For additional shipment options, see Shipment Options.

  12. 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 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.

  13. 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 Data Type Description
Authorization String Required. OAuth token generated using the Generate an OAuth Token API.
Content-Type String Required. The media type of the request entity. Set this to application/json.
X-PB-TransactionId String

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 String Shipper rate plan, if applicable. For more information, see this FAQ.
X-PB-Integrator-CarrierId String Negotiated services rate, if applicable.

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 International Shipments Only. If you are sending an international shipment 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] A list of shipment documents pertaining to a shipment, 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 available options depend on the carrier, origin country, and destination country.

Required if you are creating a shipment. For shipments the array must contain the SHIPPER_ID option. Other requirements might also apply, depending on the type of shipment.

        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 these shipments:

  • 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.

Examples

This section provides the following examples:

See also:

Example: Create Shipment

Sample Request — Create Shipment

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" \
-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" : "80305",
        "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": "9024998978"
    }, {
        "name": "ADD_TO_MANIFEST",
        "value": "true"
    }, {
        "name": "MINIMAL_ADDRESS_VALIDATION",
        "value": "true"
    } ]
}'

Sample Response — Create Shipment

{
    "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": "22851762"
    }, {
        "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"
}

Example: Create International Shipment

Sample Request — International Shipment

curl -X POST .../v1/shipments?includeDeliveryCommitment=true \
-H "Authorization: Bearer l8wHkQKaBjC5VEaYldQnFXnzoqNj" \
-H "Content-Type: application/json" \
-H "X-PB-TransactionId: 93e30b6f-b6cc-4528-bef0" \
-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": "9024998978"
    }, {
        "name": "ADD_TO_MANIFEST",
        "value": "true"
    } ]
}

Sample Response — International Shipment

{
    "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": "9024998978"
    }, {
        "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 Shipping APIs error codes, see Error Codes.