Shopify Partner店铺订单API更新遇401错误,求解决方案
Troubleshooting the 401 Error
- Verify API Credentials: Confirm
api_keyandpasswordare 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_urlis 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_orderspermission 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_idto the fulfillment payload. Retrieve location IDs usingshopify.Location.find(). - Multiple Tracking Numbers: For orders with multiple packages, use
'tracking_numbers': ['track1', 'track2']instead oftracking_number. - Error Resilience: The try-except block ensures a single failed order won't halt the entire batch processing.
内容的提问来源于stack exchange,提问作者Med
相关产品推荐
相关产品推荐

