Create a U.S. Postal Service (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: Pitney Bowes verifies addresses for accuracy against current USPS data and makes corrections to delivery lines and last lines when possible. You can optionally limit the extent of corrections by enabling minimal address validation (described below) through the MINIMAL_ADDRESS_VALIDATION shipment option.

    IMPORTANT: If you enable minimal address validation, 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.

    The following table describes describes both complete address validation, which is the default, and minimal address validation:

    Complete Address Validation
    Minimal Address Validation
    Evaluates the entire address against the current USPS address information. Evaluates the entire address against the current USPS address information.
    If current USPS address information indicates no delivery to the address, the API returns an error. If current USPS address information indicates no delivery to the address, the API returns an error.
    If the address cannot be validated against current USPS address information, the API returns an error.

    If the entire address cannot be validated against current USPS address information, the API checks whether just the last line (city/state/postal code) can be validated:

    • If the last line cannot be validated, the API returns an error.

    • If the last line can be validated, the API checks whether the delivery line (street address) has the correct format (e.g., a street number and street name). If it does, the API returns the address with any corrections only to the last line.

      The API does not verify or change the delivery line. The API returns the delivery line exactly as it is specified in the request.

      The API does not provide a ZIP+4 or 2-digit delivery point.

      If you use minimal address validation, ensure the delivery line you enter is actually deliverable.

    If the API determines the address is a match or close match, the API returns the address with any corrections. The API also returns the ZIP+4 and the 2-digit delivery point. If the API determines the address is a match or close match, the API returns the address with any corrections only to the last line. The API also returns the ZIP+4 and the 2-digit delivery point.
  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 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.

    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. Priority Mail Express shipments (a.k.a. Express Mail shipments): If using Priority Mail Express (EM), you must set a value for the phone field in in the fromAddress object.

  7. Tracking Requirement: The PB Shipping APIs require that all USPS 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. Before adding a special service, check its compatibility with the service.

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

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

  10. SCAN form: To make the shipment eligible for inclusion in a USPS SCAN form, set the ADD_TO_MANIFEST option to true in the shipmentOptions array. To include the shipment in a SCAN form, either issue the Create Manifest API or let Pitney Bowes auto-manifest the shipment at 6 a.m. UTC/GMT the next calendar day.

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

  12. Label: The label is returned as either a:

    • Base64 string that converts to a PNG.
    • Base64 string that converts to ZPL2.
    • URL that links to a PDF. Labels retrieved through URLs are available for 24 hours after label creation.

    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.

    USPS Label Sizes & Formats describes additional label considerations.

  13. Error Handling: If your request returns the HTTP 500 Internal Server Error, see Troubleshoot the 500 Internal Server Error.

    For other errors, 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 Description
includeDeliveryCommitment

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

Valid values:

  • true
  • false

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.
Accept-Language Language and country code. Default: en-US
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 USPS Only. Shipper rate plan, if applicable. For more information, see this FAQ.
X-PB-Integrator-CarrierId USPS Only. 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

Important

The API call sends and receives a Shipment Object. The table below describes all possible fields in a Shipment Object. Some fields might not apply to your operation.

Name Data Type Description
fromAddress Address Object

Required. Origin address.

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

toAddress Address Object

Required. Destination address.

Note for UPS: If you are shipping with United Parcel Service (UPS) to Puerto Rico or an international destination, and if the importer is different from the final recipient, this is the address of the importer. Enter the recipient’s address in the soldToAddress object. If importer’s address is the same as the final recipient, the toAddress and soldToAddress must match.

altReturnAddress Address Object

Applies only to the following:

  • USPS: 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.
  • PB Cross-Border: For a Create Shipment request, this is the address used to return a parcel from the Pitney Bowes consolidation center. If omitted, the fromAddress is used.
parcel Parcel Object Required. Contains physical characteristics of the parcel.
rates Array[Rates Object]

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

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

documents Array[Documents Object]

Conditional. Defines the label, manifest, or other shipment document. Applies as follows:

  • Required for Create Shipment requests except as noted in the next bullet.
  • Does not apply to a Cross-Border Create Shipment request.
  • Does not apply to Rate Parcel requests.
shipmentOptions Array[Object] Conditional. Each object in this array defines a shipment option. Required for Create Shipment requests. Does not apply to Rate Parcel requests. All Create Shipment requests require the SHIPPER_ID option. Please see the Things to Consider section on the carrier’s Create Shipment page for any additional requirements.
        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 Object

Conditional. For shipments that use customs forms, this object contains the customs information. This field is required for:

  • USPS shipments to international destinations and to APO/FPO/DPO, Territories/Possessions, and FAS
  • PB Cross-Border
  • UPS shipments to international destinations and Puerto Rico
        customsInfo Customs Info Object Customs clearance information used to fill out a commercial invoice.
        customsItems Array[Customs Items Object]

Information about each commodity in the shipment, used for customs clearance.

The maximum number of objects in this array is 30.

domesticShipmentDetails Domestic Shipment Details Object PB Cross-Border Only. Required in Create Shipment requests; does not apply to Rate Parcel requests. Contains information about the domestic leg of the PB Cross-Border shipment.
soldToAddress Address Object

UPS Only. The final recipient of a United Parcel Service shipment. Required for a shipment from the U.S. to Puerto Rico or to an international destination. Otherwise optional.

This address must match the toAddress.countryCode, with the exception of shipments to Canada and to U.S. satellite countries.

If the final recipient’s address is the same as the importer’s address, the entries in the soldToAddress object must match the entries in the toAddress object.

shipmentType String USPS Return Labels Only. Required for USPS Return Labels. If you are creating a Pure Post Return label or Scan-Based Return label, include this field and set the value to RETURN.
references Array[Object]

Applies only to the following:

  • PB Cross-Border: Required in a Create Shipment request; does not apply to a Rate Parcel request. Contains the buyer order ID. The array takes an object with two String elements. Set name to ORDER_NUMBER, and set value to the order ID:

    {
        "name": "ORDER_NUMBER",
        "value": "<order_ID>"
    }
    
  • Newgistics: Optional. 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

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": "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": "Jones",
        "phone": "203-000-1234",
        "email": "jones@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": "NO_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": "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": "Jones",
        "phone": "203-000-1234",
        "email": "jones@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": 60
        },
        "dimension": {
            "unitOfMeasurement": "IN",
            "length": 10.0,
            "width": 4.0,
            "height": 7.0
        }
    },
    "rates": [ {
        "carrier": "USPS",
        "serviceId": "EMI",
        "parcelType": "FRE",
        "specialServices": [ {
            "specialServiceId": "Ins",
            "inputParameters": [ {
                "name": "INPUT_VALUE",
                "value": "100"
            } ]
        } ],
        "inductionPostalCode": "94105"
    } ],
    "customs": {
        "customsInfo": {
            "certificateNumber": "987",
            "comments": "Books",
            "currencyCode": "CAD",
            "fromCustomsReference": "11111",
            "importerCustomsReference": "987654",
            "insuredAmount": 100.0,
            "insuredNumber": "insuredNumber0",
            "invoiceNumber": "001189223",
            "licenseNumber": "456ABC123",
            "reasonForExport": "MERCHANDISE",
            "sdrValue": 66.87
        },
        "customsItems": [ {
            "description": "Books",
            "hSTariffCode": "4901.99.0070",
            "originCountryCode": "US",
            "quantity": 3,
            "unitPrice": 32.00,
            "unitWeight": {
                "unitOfMeasurement": "OZ",
                "weight": 20.0
            }
        } ]
    },
    "documents": [ {
        "type": "SHIPPING_LABEL",
        "contentType": "URL",
        "size": "DOC_8X11",
        "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": 60.0
        },
        "dimension": {
            "length": 10.0,
            "width": 4.0,
            "height": 7.0,
            "unitOfMeasurement": "IN"
        }
    },
    "rates": [ {
        "carrier": "USPS",
        "parcelType": "FRE",
        "inductionPostalCode": "94105",
        "specialServices": [ {
            "fee": 0.0,
            "inputParameters": [ {
                "name": "INPUT_VALUE",
                "value": "100"
            } ],
            "specialServiceId": "Ins"
        } ],
        "dimensionalWeight": {
            "unitOfMeasurement": "OZ",
            "weight": 0.0
        },
        "deliveryCommitment": {
            "additionalDetails": "3 - 5 business days to many major markets",
            "estimatedDeliveryDateTime": "",
            "guarantee": "NONE",
            "maxEstimatedNumberOfDays": "5",
            "minEstimatedNumberOfDays": "3"
        },
        "serviceId": "EMI",
        "baseCharge": 42.3,
        "currencyCode": "USD",
        "destinationZone": "1",
        "totalCarrierCharge": 42.3
    } ],
    "documents": [ {
        "contentType": "URL",
        "contents": "https://.../usps/872060188/outbound/label/facb9d96c1b74f4089ebd7d788c4eb4a.pdf",
        "fileFormat": "PDF",
        "size": "DOC_8X11",
        "type": "SHIPPING_LABEL"
    } ],
    "shipmentOptions": [ {
        "name": "HIDE_TOTAL_CARRIER_CHARGE",
        "value": "false"
    }, {
        "name": "SHIPPER_ID",
        "value": "9024324564"
    }, {
        "name": "ADD_TO_MANIFEST",
        "value": "true"
    }, {
        "name": "FUTURE_SHIPMENT_DATE",
        "value": "2019-09-24 11:49:53.000"
    }, {
        "name": "MINIMAL_ADDRESS_VALIDATION",
        "value": "false"
    }, {
        "name": "SHIPPING_LABEL_RECEIPT",
        "value": "noOptions"
    } ],
    "customs": {
        "customsInfo": {
            "certificateNumber": "987",
            "comments": "Books",
            "currencyCode": "CAD",
            "freightCharge": 0.0,
            "fromCustomsReference": "11111",
            "handlingCosts": 0.0,
            "importerCustomsReference": "987654",
            "insuredAmount": 100.0,
            "insuredNumber": "insuredNumber0",
            "invoiceNumber": "001189223",
            "licenseNumber": "456ABC123",
            "otherCharge": 0.0,
            "packingCosts": 0.0,
            "reasonForExport": "MERCHANDISE",
            "sdrValue": 66.87
        },
        "customsItems": [ {
            "description": "Books",
            "hSTariffCode": "4901.99.0070",
            "originCountryCode": "US",
            "quantity": 3,
            "unitPrice": 32.0,
            "unitWeight": {
                "unitOfMeasurement": "OZ",
                "weight": 20.0
            }
        } ]
    },
    "parcelTrackingNumber": "EP862168011US",
    "shipmentId": "USPS2200205085792904"
}


Error Codes

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