Create a FedEx Shipment¶
HTTP Request¶
POST /v1/shipments
Summary¶
This operation creates a post-paid shipping label using FedEx® as the carrier. Shipments can originate from the U.S. and Canada.
Prerequisites¶
The merchant must have an existing FedEx account and must register the account with Pitney Bowes. See Onboard a Merchant to Print FedEx Labels.
Considerations¶
Addresses: The following address fields are required in the
fromAddress
andtoAddress
objects:addressLines
postalCode
countryCode
Services: For the available services and special services, see Services and Special Services on the FedEx reference page.
Labels: For information on label options, see Labels on the FedEx reference page.
Shipper ID: You must specify a SHIPPER_ID in the
shipmentOptions
array and set its value to the merchant’spostalReportingNumber
. To retrieve a merchant’s postalReportingNumber, use the Get Merchant Accounts API.Reference IDs: You can print a merchant-defined reference field on the shipping label by specifying the PRINT_CUSTOM_MESSAGE_1 shipment option in the
shipmentOptions
array.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 URLs¶
Sandbox: https://shipping-api-sandbox.pitneybowes.com/shippingservices/v1/shipments
Production: https://shipping-api.pitneybowes.com/shippingservices/v1/shipments
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 |
Accept-Language |
Language and country code. Default: |
X-PB-TransactionId |
Required. A unique identifier for the transaction, up to 25 characters. The following characters are allowed: letters, numbers, hyphens ( Important: Ensure this is a unique ID. |
X-PB-Shipper-Carrier-AccountId |
Conditional. The unique identifier for the carrier account. To retrieve the identifier, see this FAQ. This header is required if the merchant has registered multiple accounts for the same carrier. For more information, see Add Carrier Accounts. |
X-PB-UnifiedErrorStructure |
Recommended. Set this to |
Request / Response Elements¶
The API call sends and receives a Shipment Object. The following table describes all possible fields in a Shipment Object.
Important
Some fields in the Shipment Object do not apply to this operation and are marked accordingly.
Name |
Data Type |
Description |
---|---|---|
fromAddress |
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 |
Required. Destination address. FedEx, UPS: If you are shipping with FedEx or 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 |
|
altReturnAddress |
PB Expedited, CBDS Only. Sets the address for parcel returns. Use this in the following situations:
|
|
parcel |
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 |
documents |
Array[Documents Object] |
Conditional. Defines the label, manifest, or other shipping document created by the API call. In a response, this array provides the URL or Base64 string for a document and in some cases can contain multiple objects. This field is required, except in the following cases:
|
shipmentOptions |
Array[Object] |
Required. Each object in this array defines a shipment option. Specify each option as a name-value pair in the array. The |
shipmentOptions.name |
String |
The name of the shipment option. |
shipmentOptions.value |
String |
The value of the shipment option. |
customs |
Object |
Conditional. For shipments that use customs forms, this object contains the customs information. This field is required for the following carriers in the following situations:
|
customs.customsInfo |
Customs clearance information for the commercial invoice. When using the Customs Info Object, make sure to include the fields marked Required. |
|
customs.customsItems |
Array[Customs Items Object] |
Customs clearance information for each commodity. When using the Customs Items Object, make sure to include the fields marked Required. The maximum number of objects in this array is 30. |
domesticShipmentDetails |
CBDS Only. Required if the merchant prints the first-mile label prior to invoking the Create CBDS Shipment API. This object contains information about the first-mile leg of the shipment. |
|
soldToAddress |
FedEx, UPS Only. The final recipient of a the shipment. Required for a shipment from the U.S. to Puerto Rico or to an international destination. Otherwise optional. This address must match the If the final recipient’s address is the same as the importer’s address, the entries in the |
|
shipmentType |
String |
Return Labels Only. Set this to |
references |
Array[Object] |
PB Standard, CBDS Only. Conditional. The merchant’s reference fields. Each object in the array includes a name-value pair that defines a reference field. This array applies only to the following two carriers:
To pass references for carriers other than the above, see Reference Fields. |
references.name |
String |
PB Standard, CBDS Only. The name of the reference field. |
references.value |
String |
PB Standard, CBDS Only. The value for the reference field. |
hazmatDetails |
PB Standard Only. If shipping hazardous materials with PB Standard, use this object. |
|
carrierPayments |
FedEx, UPS Only. Indicates that one or more of the shipment costs should be charged to a third-party account. |
|
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 Request¶
curl -X POST .../v1/shipments \
-H "Authorization: Bearer <oauth_token>" \
-H "Content-Type: application/json" \
-H "Accept-Language: en-US" \
-H "X-PB-TransactionId: <unique_transaction_id>" \
-H "X-PB-Shipper-Carrier-AccountId: <unique_carrier_account_id>" \
-H "X-PB-UnifiedErrorStructure: true" \
-d '
{
"fromAddress": {
"company": "Emporium",
"name": "Kathryn Smith",
"phone": "334-555-0000",
"email": "kathryn@example.com",
"residential": false,
"addressLines": [
"2352 Bent Creek Rd"
],
"cityTown": "Auburn",
"stateProvince": "AL",
"postalCode": "36830",
"countryCode": "US"
},
"toAddress": {
"company": "Shop",
"name": "Mary Jones",
"phone": "620-555-0000",
"email": "mary@example.com",
"residential": false,
"addressLines": [
"284 W Fulton St"
],
"cityTown": "Garden City",
"stateProvince": "KS",
"postalCode": "67846",
"countryCode": "US"
},
"parcel": {
"weight": {
"unitOfMeasurement": "OZ",
"weight": 20
}
},
"rates": [ {
"carrier": "FEDEX",
"serviceId": "2DA",
"parcelType": "PKG",
"specialServices": [ {
"specialServiceId": "INS",
"inputParameters": [ {
"name": "INPUT_VALUE",
"value": "50"
} ]
} ]
} ],
"documents": [ {
"size": "DOC_4X6",
"printDialogOption": "NO_PRINT_DIALOG",
"type": "SHIPPING_LABEL",
"contentType": "URL",
"fileFormat": "PDF"
} ],
"shipmentOptions": [ {
"name": "SHIPPER_ID",
"value": "9024324564"
} ]
}'
Sample Response¶
{
"fromAddress": {
"company": "Emporium",
"name": "Kathryn Smith",
"phone": "334-555-0000",
"email": "kathryn@example.com",
"residential": false,
"addressLines": [
"2352 Bent Creek Rd"
],
"cityTown": "Auburn",
"stateProvince": "AL",
"postalCode": "36830-6433",
"countryCode": "US",
"carrierRoute": "C010",
"deliveryPoint": "52"
},
"toAddress": {
"company": "Shop",
"name": "Mary Jones",
"phone": "620-555-0000",
"email": "mary@example.com",
"residential": false,
"addressLines": [
"284 W Fulton St"
],
"cityTown": "Garden City",
"stateProvince": "KS",
"postalCode": "67846-5352",
"countryCode": "US",
"carrierRoute": "C007",
"deliveryPoint": "84"
},
"parcel": {
"weight": {
"unitOfMeasurement": "OZ",
"weight": 20.0
}
},
"rates": [ {
"carrier": "FEDEX",
"parcelType": "PKG",
"inductionPostalCode": "36830",
"specialServices": [ {
"fee": 0.0,
"inputParameters": [ {
"name": "INPUT_VALUE",
"value": "50"
} ],
"specialServiceId": "INS"
} ],
"deliveryCommitment": {
"estimatedDeliveryDateTime": "2020-12-18 16:30:00",
"guarantee": "FULL"
},
"serviceId": "2DA",
"baseCharge": 24.38,
"currencyCode": "USD",
"surcharges": [ {
"fee": 2.85,
"name": "DELIVERY_AREA"
},{
"fee": 2.04,
"name": "FUEL"
} ],
"totalCarrierCharge": 29.27,
"totalTaxAmount": 0.0
} ],
"documents": [ {
"contentType": "URL",
"contents": "https://.../d7efae383834ed19a6b733a3818a4.pdf",
"fileFormat": "PDF",
"size": "DOC_4X6",
"type": "SHIPPING_LABEL"
} ],
"shipmentOptions": [ {
"name": "SHIPPER_ID",
"value": "9024324564"
} ],
"parcelTrackingNumber": "79487353815",
"shipmentId": "FEDEX220012345678182"
}
Error Codes¶
For a list of all error codes returned by the Ecommerce APIs, please see Error Codes.