You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Shopify Partner店铺订单API更新遇401错误,求解决方案

Fixing Shopify API 401 Unauthorized Error & Correct Order Fulfillment Code

Troubleshooting the 401 Error

  • Verify API Credentials: Confirm api_key and password are the valid API Key and API Password from your Shopify app (not your store account password). For Partner stores, generate these via Partner Dashboard > Apps > Your App > API Credentials.
  • Check Store URL: Ensure shop_url is your exact store domain (e.g., your-store.myshopify.com) with no typos or extra characters.
  • App Permissions: Make sure your app has the write_orders permission enabled—this is required to modify orders and create fulfillments.
  • API Version: Explicitly set a supported API version (e.g., 2024-01) to avoid compatibility issues with deprecated endpoints.

Corrected Implementation Code

import shopify
import json

# Initialize Shopify API with valid credentials and explicit API version
shop_url = 'your-store.myshopify.com'
api_key = 'your-api-key'
password = 'your-api-password'
api_version = '2024-01'  # Use a currently supported version

# Configure the API site with version
shopify.ShopifyResource.set_site(f'https://{api_key}:{password}@{shop_url}/admin/api/{api_version}')

# Load orders from JSON file
with open('PEBestellungen.json', 'r') as file:
    order_list = json.load(file)

# Process each order to update fulfillment status
for order_data in order_list:
    order_id = order_data['id']
    
    try:
        # Fetch the target order
        order = shopify.Order.find(order_id)
        
        # Check if fulfillment is required
        if order.fulfillment_status in [None, 'partial']:
            # Prepare fulfillment data with tracking details
            fulfillment_payload = {
                'order_id': order_id,
                'tracking_number': 'AAXXXXXXXXXBE',  # Single tracking number
                'tracking_company': 'Your Carrier Name',
                'tracking_url': 'https://your-carrier.com/track/AAXXXXXXXXXBE',  # Optional but recommended
                'notify_customer': True
            }
            
            # Create fulfillment (no need to call save() separately)
            fulfillment = shopify.Fulfillment.create(fulfillment_payload)
            
            print(f"Successfully fulfilled order {order_id}")
        else:
            print(f"Order {order_id} is already fulfilled, skipping")
    
    except Exception as e:
        print(f"Failed to process order {order_id}: {str(e)}")

print("Batch fulfillment process finished.")

Important Notes

  • Location ID: If your store uses multiple locations, add 'location_id': your_location_id to the fulfillment payload. Retrieve location IDs using shopify.Location.find().
  • Multiple Tracking Numbers: For orders with multiple packages, use 'tracking_numbers': ['track1', 'track2'] instead of tracking_number.
  • Error Resilience: The try-except block ensures a single failed order won't halt the entire batch processing.

内容的提问来源于stack exchange,提问作者Med

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 18:12:42