Updated
Shipping API quickstart: your first label in five languages
A first label through the GoatLabels API takes four calls: quote the parcel, create a draft shipment, buy the label and download the PDF. With a Sandbox key the same calls run on test data and nothing is charged. The create call is shown in curl, Python, Node.js, PHP and C#.
Rates from one quote call
One quote call returns rates from USPS, UPS and FedEx for a domestic parcel, and DHL on international lanes. A Sandbox key gets the live prices.
A Sandbox key charges nothing
A sandbox purchase draws on a sandbox balance and books no carrier. A Live key debits the prepaid wallet, which you fund by card in the dashboard.
Free account. No card needed.
What do you need before the first call?
Three things: an account, a key and a base URL. Create a GoatLabels account, open the Developers page in the dashboard and make a Sandbox key. Sandbox keys start sk_sandbox_ and the full key is shown once, so copy it into your secrets store as soon as it appears. The base URL is https://goatlabels.io/api/v1, and a Sandbox key uses the same base URL and the same endpoints as a Live key.
Every call carries one header: Authorization: Bearer sk_sandbox_YOUR_KEY. Request bodies are JSON, request fields are snake_case and country codes are two-letter ISO codes.
There is no official SDK. Call REST directly, as every sample on this page does, or generate a client from the OpenAPI 3.1 description at /api/v1/openapi.json, which is served without a key. Generating a shipping API client from OpenAPI walks through that route, and the API docs hold the full reference.
What are the four calls, in order?
Quote, draft, buy, download. The table lists what each call takes and what your code reads from the answer.
| Step | Call | You send | You read back |
|---|---|---|---|
| 1 Quote | POST /v1/rates/quote | postal_code and country for each end, and the parcel | rates[] with id, carrier, serviceName, displayPrice, deliveryDays |
| 2 Draft | POST /v1/shipments | full from and to addresses, the parcel, a reference, optionally a rate_id | id (shp_) and rates[] |
| 3 Buy | POST /v1/shipments/{id}/purchase | the acknowledgements block and an Idempotency-Key header | trackingNumber and labelUrl |
| 4 Download | GET /v1/shipments/{id}/label | the same Bearer header | the label file, normally a PDF |
The quote needs only a postal code and a country for each end, plus the parcel. It creates nothing and does not touch the wallet, so it is the safe call to start with:
curl -X POST https://goatlabels.io/api/v1/rates/quote \
-H "Authorization: Bearer $GOATLABELS_KEY" \
-H "Content-Type: application/json" \
-d '{
"from": { "postal_code": "78701", "country": "US" },
"to": { "postal_code": "11201", "country": "US" },
"parcel": { "length": 10, "width": 8, "height": 4, "weight": 2 }
}'
The draft is the create call, shown in four languages in the next section. The purchase then sends the acknowledgements block: a version, the time it was accepted, and five flags that must all be true. It also carries an Idempotency-Key header, so a retry after a timeout cannot buy a second label:
curl -X POST https://goatlabels.io/api/v1/shipments/shp_test_123/purchase \
-H "Authorization: Bearer $GOATLABELS_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: po-1001" \
-d '{
"acknowledgements": {
"version": "v1-2026-05",
"acceptedAt": "2026-11-29T15:00:00Z",
"noHazardous": true,
"noPerishable": true,
"noProhibited": true,
"accurateDeclaration": true,
"carrierTermsAccepted": true
}
}'
The purchase answer is camelCase: read trackingNumber and labelUrl from it. The fourth call, a GET on the shipment's label path with the same Bearer header, returns the label file. For how the retry header behaves when an order system resends a purchase, see idempotent label purchases from an ERP.
What does the create call look like in each language?
GoatLabels' docs carry curl, Node.js and Python samples. The PHP and C# samples here are plain HTTP written from the documented request, because there is no SDK. All four send the same POST /v1/shipments body (from, to, parcel and a reference), read the key from an environment variable and print the shipment id.
Python, with the requests package:
import os, requests
body = {
"from": {"name": "Acme Parts", "line1": "500 W 2nd St", "city": "Austin", "state": "TX", "postal_code": "78701", "country": "US"},
"to": {"name": "Dana Lee", "line1": "55 Water St", "city": "Brooklyn", "state": "NY", "postal_code": "11201", "country": "US"},
"parcel": {"length": 10, "width": 8, "height": 4, "weight": 2},
"reference": "PO-1001",
}
r = requests.post(
"https://goatlabels.io/api/v1/shipments",
headers={"Authorization": "Bearer " + os.environ["GOATLABELS_KEY"]},
json=body,
)
print(r.json()["id"])
Node.js 18 or later, with the built-in fetch (save the file as .mjs so await works at the top level):
const body = {
from: { name: "Acme Parts", line1: "500 W 2nd St", city: "Austin", state: "TX", postal_code: "78701", country: "US" },
to: { name: "Dana Lee", line1: "55 Water St", city: "Brooklyn", state: "NY", postal_code: "11201", country: "US" },
parcel: { length: 10, width: 8, height: 4, weight: 2 },
reference: "PO-1001",
};
const res = await fetch("https://goatlabels.io/api/v1/shipments", {
method: "POST",
headers: { Authorization: "Bearer " + process.env.GOATLABELS_KEY, "Content-Type": "application/json" },
body: JSON.stringify(body),
});
const shipment = await res.json();
console.log(shipment.id);
PHP, with the cURL extension and json_encode:
$body = [
"from" => ["name" => "Acme Parts", "line1" => "500 W 2nd St", "city" => "Austin", "state" => "TX", "postal_code" => "78701", "country" => "US"],
"to" => ["name" => "Dana Lee", "line1" => "55 Water St", "city" => "Brooklyn", "state" => "NY", "postal_code" => "11201", "country" => "US"],
"parcel" => ["length" => 10, "width" => 8, "height" => 4, "weight" => 2],
"reference" => "PO-1001",
];
$ch = curl_init("https://goatlabels.io/api/v1/shipments");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer " . getenv("GOATLABELS_KEY"), "Content-Type: application/json"],
CURLOPT_POSTFIELDS => json_encode($body),
]);
echo json_decode(curl_exec($ch), true)["id"];
C#, with HttpClient and a JSON string (the raw string literal needs C# 11, which ships with .NET 7 and later):
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
var json = """
{ "from": { "name": "Acme Parts", "line1": "500 W 2nd St", "city": "Austin", "state": "TX", "postal_code": "78701", "country": "US" },
"to": { "name": "Dana Lee", "line1": "55 Water St", "city": "Brooklyn", "state": "NY", "postal_code": "11201", "country": "US" },
"parcel": { "length": 10, "width": 8, "height": 4, "weight": 2 }, "reference": "PO-1001" }
""";
var http = new HttpClient();
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("GOATLABELS_KEY"));
var res = await http.PostAsync("https://goatlabels.io/api/v1/shipments", new StringContent(json, Encoding.UTF8, "application/json"));
var doc = JsonDocument.Parse(await res.Content.ReadAsStringAsync());
Console.WriteLine(doc.RootElement.GetProperty("id").GetString());
The id in the response starts shp_, or shp_test_ with a Sandbox key, and the response carries rates[] inline, so the create call can stand in for a separate quote. Keep the id: the purchase and the label download both take it in the path.
Which errors should a first version handle?
Five answers cover what a first integration meets. Every error body has the same shape: error.type and error.message, with issues[] on validation errors.
| Status | When | What to do |
|---|---|---|
| 402 | the wallet (or the sandbox test balance) is short at purchase | top up in the dashboard and retry with the same Idempotency-Key |
| 409 | the shipment is already purchased or voided, or the label is not ready yet (label_not_ready) | do not retry a finished purchase; wait and ask for the label again |
| 429 | over 300 requests a minute per key | wait the seconds in Retry-After |
| 503 | a carrier outage; nothing is taken | retry after Retry-After |
| 422 address_needs_confirmation | the carrier would print a different city, state or ZIP; nothing is charged | fix the address or confirm it as typed |
The 429 is the one a batch job meets first. Shipping API rate limits in batch integrations covers pacing a job against the per-minute window.
How do you go live from the sandbox?
Swap the Sandbox key for a Live key, which starts sk_live_. Nothing else in the code changes. Every response carries the header GoatLabels-Environment with the value sandbox or live, so log it: it is the quickest way to see which key a job ran with.
A live purchase debits the prepaid wallet. Fund the wallet in the dashboard before the first live label, because there is no top-up by API. Sandbox shipments never appear in the dashboard, so do not look for them there once you switch.
The sandbox does not cover insurance claims, carrier adjustments or the Free plan's monthly allowance, so plan for those on a Live key. Once labels are going out, the shipping webhook recipes show how to consume tracking and adjustment events, and the shipping API comparison sets this API beside the others a developer is likely weighing.
Shipping API quickstart: FAQ
- Is there a GoatLabels SDK for Python, Node.js, PHP or C#?
- No. GoatLabels has no official SDK in any language. Call the REST API directly, as the samples on this page do, or generate a client from the OpenAPI 3.1 description, which is served without a key at /api/v1/openapi.json.
- Does a sandbox label cost anything?
- No. A purchase made with a Sandbox key draws on a sandbox balance that starts at $1,000.00, so nothing is charged to you. It returns a tracking number that starts GLTEST and a sample 4x6 PDF that no carrier accepts.
- Are sandbox rates real?
- Yes. A quote made with a Sandbox key returns the live prices. What follows the quote is simulated: a sandbox purchase draws on a sandbox balance and no carrier is booked.
- How do I stop a retry from buying two labels?
- Send an Idempotency-Key header on the create and purchase calls. A retry with the same value and the same body replays the first response and adds the header Idempotent-Replayed: true. The same value with a different body returns 409 idempotency_error.
- What is the rate limit?
- 300 requests a minute per key, on both plans. Every response carries X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset, and a 429 answer carries a Retry-After header with the seconds to wait.
Related: the shipping API for developers, shipping webhook recipes, and the API docs.
Make a Sandbox key.
Buy a sample label.
Quote a parcel, create the draft, buy the label and download the PDF. With a Sandbox key nothing is charged, and going live is a change of key.
Free account. No card needed.