Experience with Shopify's tracking number retrieval endpoint?

Hey everyone, I’m trying to figure out how to use Shopify’s endpoint for getting tracking numbers. I’ve looked at their docs, but I’m having trouble understanding how it works. There’s no example of what the data should look like or how to send a response.

Does anyone have experience with this? I’d really appreciate if someone could share some example data or point me in the right direction. I’m not sure if I should reply to the webhook or make a separate API call to send the tracking info.

Here’s a bit of pseudo-code to show what I’m thinking:

def handle_tracking_request(order_data):
    # Not sure what to do here
    tracking_info = get_tracking_info(order_data)
    
    # Should I do this?
    return json.dumps(tracking_info)
    
    # Or maybe this?
    # send_tracking_info_to_shopify(tracking_info)

# Help needed!

Any advice would be super helpful. Thanks!

I’ve had success using Shopify’s Fulfillment API for tracking number updates. The key is to make a separate POST request to their endpoint, rather than responding to the webhook directly. You’ll need to include the order ID in the URL and provide the tracking details in the request body.

Here’s a basic Python example using the requests library:

import requests

def send_tracking_info(order_id, tracking_number, tracking_company):
    url = f'https://your-store.myshopify.com/admin/api/2021-07/orders/{order_id}/fulfillments.json'
    headers = {'X-Shopify-Access-Token': 'your_access_token'}
    data = {
        'fulfillment': {
            'tracking_number': tracking_number,
            'tracking_company': tracking_company
        }
    }
    response = requests.post(url, json=data, headers=headers)
    return response.json()

Make sure to replace the placeholder values with your actual Shopify store URL and access token. This approach should work for most cases.

hey jack, i’ve worked with shopify’s tracking stuff before. you’ll wanna make a separate POST request to their Fulfillment API endpoint. don’t reply to the webhook directly.

heres a quick example:

POST /admin/api/2021-07/orders/{order_id}/fulfillments.json
{
  "fulfillment": {
    "tracking_number": "123456789",
    "tracking_company": "USPS"
  }
}

hope this helps!

As someone who’s integrated Shopify’s tracking system into multiple e-commerce platforms, I can say it’s not as straightforward as their documentation suggests. The key is indeed using the Fulfillment API, but there’s a bit more to it.

First, you’ll need to generate an access token with the right permissions. Then, when you receive an order webhook, don’t respond immediately. Instead, queue the order for processing.

In your background job, fetch the order details, generate the tracking info, and then make the API call. Here’s a crucial tip: always implement retry logic. Shopify’s API can be temperamental, especially during high-traffic periods.

Also, consider bulk operations if you’re dealing with high volume. Shopify has a GraphQL API that’s more efficient for multiple updates.

Lastly, thoroughly test your integration. Shopify’s sandbox environment is great for this, but it doesn’t always mirror production perfectly. Always have a plan B for when things go sideways.