curl --request PATCH \
--url https://{defaultHost}/v1/shipments/{id}/purchase \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"shipment": {
"rate_id": "rate_1",
"label_file_type": "PDF"
}
}
'import requests
url = "https://{defaultHost}/v1/shipments/{id}/purchase"
payload = { "shipment": {
"rate_id": "rate_1",
"label_file_type": "PDF"
} }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({shipment: {rate_id: 'rate_1', label_file_type: 'PDF'}})
};
fetch('https://{defaultHost}/v1/shipments/{id}/purchase', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{defaultHost}/v1/shipments/{id}/purchase",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'shipment' => [
'rate_id' => 'rate_1',
'label_file_type' => 'PDF'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{defaultHost}/v1/shipments/{id}/purchase"
payload := strings.NewReader("{\n \"shipment\": {\n \"rate_id\": \"rate_1\",\n \"label_file_type\": \"PDF\"\n }\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.patch("https://{defaultHost}/v1/shipments/{id}/purchase")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"shipment\": {\n \"rate_id\": \"rate_1\",\n \"label_file_type\": \"PDF\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{defaultHost}/v1/shipments/{id}/purchase")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"shipment\": {\n \"rate_id\": \"rate_1\",\n \"label_file_type\": \"PDF\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "14850935-8ec7-4c43-b87e-c967bde0ea30",
"object": "shipment",
"carrier": "USPS",
"carrier_messages": [],
"contact_validations": null,
"dimensions": {
"length": 10,
"width": 8,
"height": 5,
"unit": "in"
},
"customs_declaration": null,
"international": false,
"customs_required": false,
"eta": null,
"inherit_weight": false,
"label_file_type": "PDF",
"label_url": "https://deliver.goshippo.com/1e3adda1934443079737edb336067106.pdf?Expires=1806494587&Signature=YcAo0uG7lvxdwCmD8KPOui7O~u7KGPKWQszBtrLcdfQg5hdRZlfabsM4zSa69zRVgpEH8Omon0ktgRETyPPoIP9WOyW4CvKa7tEKyoOMi04YQ7JLCNZJXybHoJ9Z31gYqfd5RYfn1SoFTaFUDjQ17Id9RMTGG-JICM7a8fbsKFBoaGEE6zme~POyX~KX2rhlv2XiQFfmXhoJn1tF1yeh0gTJ4Ayefno4u34AeiS2XipX1anBqYyrtsxIXa7gG8NC-QufLNSgBUMcnkDLT04aa8-XXvI7IsVAkml1QqzAHq2Ur-2HVYaxYhA1V3VUjkwv8E6LwkyS~23jEysytNbdNw__&Key-Pair-Id=APKAJRICFXQ2S4YUQRSQ",
"live_mode": true,
"rates": [
{
"id": "rate_1",
"amount": 550,
"currency": "usd",
"provider": "USPS",
"service_name": "Priority",
"estimated_days": 3,
"tags": [
"bestvalue"
],
"duration_terms": null,
"provider_logo_url": "https://example.com/usps.png"
}
],
"selected_rate": {
"id": "rate_1",
"amount": 550,
"currency": "usd",
"provider": "USPS",
"service_name": "Priority",
"estimated_days": 3,
"tags": [
"bestvalue"
],
"duration_terms": null,
"provider_logo_url": "https://example.com/usps.png"
},
"shipping_date": 1793750400,
"status": "purchased",
"tracking_number": "9234690396055702568186",
"tracking_status": null,
"tracking_url": "https://tools.usps.com/go/TrackConfirmAction_input?origTrackNum=9234690396055702568186",
"weight": "2.0",
"weight_unit": "lb",
"carrier_parcel_template_token": null,
"from_contact": "9042482f-0f01-49a3-b155-70104a422c82",
"fulfillment": "eeaf1a6b-8882-4088-ac85-99e5d992e728",
"parcel_template": null,
"shipping_provider": "8dec4bfc-6116-4f96-81aa-ad9b237f9608",
"to_contact": "91d7141c-770c-4c42-9e6b-8cd577bfe585",
"created_at": 1793796994,
"updated_at": 1793796995
}Purchase
Purchases a shipping label for a specific shipment using the selected rate.
curl --request PATCH \
--url https://{defaultHost}/v1/shipments/{id}/purchase \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"shipment": {
"rate_id": "rate_1",
"label_file_type": "PDF"
}
}
'import requests
url = "https://{defaultHost}/v1/shipments/{id}/purchase"
payload = { "shipment": {
"rate_id": "rate_1",
"label_file_type": "PDF"
} }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({shipment: {rate_id: 'rate_1', label_file_type: 'PDF'}})
};
fetch('https://{defaultHost}/v1/shipments/{id}/purchase', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{defaultHost}/v1/shipments/{id}/purchase",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'shipment' => [
'rate_id' => 'rate_1',
'label_file_type' => 'PDF'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{defaultHost}/v1/shipments/{id}/purchase"
payload := strings.NewReader("{\n \"shipment\": {\n \"rate_id\": \"rate_1\",\n \"label_file_type\": \"PDF\"\n }\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.patch("https://{defaultHost}/v1/shipments/{id}/purchase")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"shipment\": {\n \"rate_id\": \"rate_1\",\n \"label_file_type\": \"PDF\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{defaultHost}/v1/shipments/{id}/purchase")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"shipment\": {\n \"rate_id\": \"rate_1\",\n \"label_file_type\": \"PDF\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "14850935-8ec7-4c43-b87e-c967bde0ea30",
"object": "shipment",
"carrier": "USPS",
"carrier_messages": [],
"contact_validations": null,
"dimensions": {
"length": 10,
"width": 8,
"height": 5,
"unit": "in"
},
"customs_declaration": null,
"international": false,
"customs_required": false,
"eta": null,
"inherit_weight": false,
"label_file_type": "PDF",
"label_url": "https://deliver.goshippo.com/1e3adda1934443079737edb336067106.pdf?Expires=1806494587&Signature=YcAo0uG7lvxdwCmD8KPOui7O~u7KGPKWQszBtrLcdfQg5hdRZlfabsM4zSa69zRVgpEH8Omon0ktgRETyPPoIP9WOyW4CvKa7tEKyoOMi04YQ7JLCNZJXybHoJ9Z31gYqfd5RYfn1SoFTaFUDjQ17Id9RMTGG-JICM7a8fbsKFBoaGEE6zme~POyX~KX2rhlv2XiQFfmXhoJn1tF1yeh0gTJ4Ayefno4u34AeiS2XipX1anBqYyrtsxIXa7gG8NC-QufLNSgBUMcnkDLT04aa8-XXvI7IsVAkml1QqzAHq2Ur-2HVYaxYhA1V3VUjkwv8E6LwkyS~23jEysytNbdNw__&Key-Pair-Id=APKAJRICFXQ2S4YUQRSQ",
"live_mode": true,
"rates": [
{
"id": "rate_1",
"amount": 550,
"currency": "usd",
"provider": "USPS",
"service_name": "Priority",
"estimated_days": 3,
"tags": [
"bestvalue"
],
"duration_terms": null,
"provider_logo_url": "https://example.com/usps.png"
}
],
"selected_rate": {
"id": "rate_1",
"amount": 550,
"currency": "usd",
"provider": "USPS",
"service_name": "Priority",
"estimated_days": 3,
"tags": [
"bestvalue"
],
"duration_terms": null,
"provider_logo_url": "https://example.com/usps.png"
},
"shipping_date": 1793750400,
"status": "purchased",
"tracking_number": "9234690396055702568186",
"tracking_status": null,
"tracking_url": "https://tools.usps.com/go/TrackConfirmAction_input?origTrackNum=9234690396055702568186",
"weight": "2.0",
"weight_unit": "lb",
"carrier_parcel_template_token": null,
"from_contact": "9042482f-0f01-49a3-b155-70104a422c82",
"fulfillment": "eeaf1a6b-8882-4088-ac85-99e5d992e728",
"parcel_template": null,
"shipping_provider": "8dec4bfc-6116-4f96-81aa-ad9b237f9608",
"to_contact": "91d7141c-770c-4c42-9e6b-8cd577bfe585",
"created_at": 1793796994,
"updated_at": 1793796995
}Authorizations
Response
Success
Expandable – The associated parcel template ID.
The token of a carrier parcel template (e.g. USPS_SmallFlatRateBox), resolved against this shipment's own shipping provider. Defaults to the parcel template's token when parcel_template is set, and can be cleared or overridden by passing it explicitly. When it resolves to a fixed-size package its dimensions are used, and quoted rates cover only that carrier — read the carrier itself from the parcel template, or from the selected rate once one is chosen. Cannot be changed after the label is purchased.
Expandable – The associated fulfillment ID.
Expandable – The associated shipping provider ID.
Expandable – The associated contact ID.
Expandable – The associated contact ID.
Was this page helpful?