How to Use Shopify API to Get Shipping Rates

When building a custom checkout experience or integrating your own shipping solution with Shopify, you often need real-time shipping rates.

That’s where the Shopify API comes in — allowing you to get shipping rates programmatically for any order or cart.

In this guide, we’ll cover how to use the Shopify API to get shipping rates, including REST and GraphQL examples, authentication setup, and best practices for working with carrier services.

How to Use Shopify API to Get Shipping Rates

Shopify APIs Used for Shipping Rates

There are two main ways to retrieve shipping rates using Shopify’s APIs:

API Description Use Case
CarrierService API Custom apps can return live shipping rates from external carriers. For third-party shipping rate providers
Admin API (REST or GraphQL) Retrieve rates for draft orders, checkout sessions, or fulfillment services. For custom checkout or backend calculations

Let’s explore both in detail.

Method 1: Using the CarrierService API

The CarrierService API allows your custom app to provide real-time rates directly to Shopify’s checkout page.

This is useful if you operate your own logistics system or want to connect a non-standard carrier.

Step 1: Register a Carrier Service

You can register your app as a shipping rate provider via the Admin REST API:

POST /admin/api/2025-01/carrier_services.json

Example Request:

{
"carrier_service": {
"name": "Custom Carrier",
"callback_url": "https://example.com/rates",
"service_discovery": true
}
}
  • callback_url: the endpoint Shopify will call to request rates.

  • service_discovery: true allows Shopify to automatically fetch all available services.

Example Response:

{
"carrier_service": {
"id": 123456,
"name": "Custom Carrier",
"callback_url": "https://example.com/rates",
"format": "json",
"service_discovery": true
}
}

Step 2: Handle the Rate Request

When a customer checks out, Shopify sends a POST request to your callback URL with order details.

Example Callback Payload:

{
"rate": {
"origin": {
"country": "US",
"postal_code": "10001"
},
"destination": {
"country": "CA",
"postal_code": "M4B1B3"
},
"items": [
{ "name": "T-shirt", "quantity": 2, "grams": 200 }
]
}
}

Your system must respond with a list of rates:

Example Response:

{
"rates": [
{
"service_name": "Standard Shipping",
"service_code": "STANDARD",
"total_price": "1000",
"currency": "USD",
"min_delivery_date": "2025-10-23T14:00:00Z",
"max_delivery_date": "2025-10-25T14:00:00Z"
},
{
"service_name": "Express Shipping",
"service_code": "EXPRESS",
"total_price": "2000",
"currency": "USD"
}
]
}

Shopify will display these rates at checkout for the customer to choose from.

Pro Tip: You can calculate your rates dynamically using external APIs (like FedEx or UPS) before returning them to Shopify.

Method 2: Using the Shopify Admin API (REST or GraphQL)

If you’re working with custom checkouts, draft orders, or internal tools, you can get shipping rates directly from Shopify’s Admin API.

Option A: REST API Example

Endpoint:

POST /admin/api/2025-01/checkouts.json

Example Request:

{
"checkout": {
"email": "[email protected]",
"line_items": [
{ "variant_id": 123456789, "quantity": 1 }
],
"shipping_address": {
"country": "US",
"zip": "10001"
}
}
}

Example Response (Rates Section):

{
"checkout": {
"id": "abcd1234",
"shipping_rates": [
{
"id": "standard-123",
"price": "10.00",
"title": "Standard Shipping"
},
{
"id": "express-123",
"price": "20.00",
"title": "Express Shipping"
}
]
}
}

Option B: GraphQL Example

Using GraphQL, you can query for shipping rates within a checkout session:

query {
checkout(id: "gid://shopify/Checkout/1234567890") {
availableShippingRates {
ready
shippingRates {
handle
price {
amount
currencyCode
}
title
}
}
}
}

This returns all available shipping options for that checkout.

Authentication Setup

All Shopify API requests require authentication.

For private apps or custom apps, use the Admin API access token.

curl -X GET "https://{store_name}.myshopify.com/admin/api/2025-01/shipping_zones.json" \
-H "X-Shopify-Access-Token: {access_token}"

Make sure your app has permissions:

  • read_shipping

  • write_shipping

  • read_checkouts (if using checkout endpoints)

If you’re building a public app, use OAuth 2.0 for authorization.

Testing Shopify Shipping Rate API Locally

You can use tools like Postman or Insomnia to test requests.

Steps:

  1. Generate a Shopify Admin API token.

  2. Create a test order or checkout.

  3. Use API endpoints to fetch rates.

  4. Inspect JSON responses and verify expected behavior.

You can also test your callback endpoint (CarrierService) using mock data from Shopify’s test environment.

Common Issues and Troubleshooting

Issue Cause Solution
No rates returned Incorrect zone setup or carrier not available Check “Shipping and Delivery” settings
400 Bad Request Invalid request format Validate JSON structure
401 Unauthorized Missing or invalid API token Regenerate access token
Delayed response Callback timeout Ensure your server responds within 10 seconds
Incorrect currency Shopify store and response currency mismatch Use store’s default currency or specify via API

The Shopify API for getting shipping rates gives developers complete flexibility to customize delivery options for customers.

Whether you:

  • Build your own Carrier Service integration,

  • Fetch rates for custom checkouts, or

  • Automate fulfillment with multi-carrier shipping apps

…the Shopify API makes it possible to provide accurate, dynamic shipping costs in real time.

By following this guide and best practices, you’ll have full control over your Shopify store’s shipping logic — improving both customer experience and operational efficiency.

Leave A Comment

Your email address will not be published. Required fields are marked *