【问题标题】:How to set shopify order to fulfilled?如何设置shopify订单履行?
【发布时间】:2022-01-06 16:05:43
【问题描述】:

设置

我有一个未完成订单的 Shopify 商店,并且可以访问商店的 REST API。

订单已发货,我收到了tracking_numbertracking_urltransport_company

我想使用 REST API 将订单设置为已履行并将tracking_numbertracking_urltransport_company 信息发送给客户。


代码

我在 Shopify 中有订单的 ID,order_id,这样我就可以获取订单的 fulfillment_orders 商品,然后从那里获取 fulfillment_idlocation_id,就像这样,

fulfillment_orders = requests.get(shop_url + '/orders/'+ order_id +'/fulfillment_orders.json').json()   
fulfillment_id = str(fulfillment_orders['fulfillment_orders'][0]['id'])
location_id = requests.get(shop_url + '/locations.json').json()['locations'][0]['id']   

其中shop_url 是连接到商店所需的网址。

到目前为止,代码可以正常工作。

然后,我设置了有效载荷,

payload = {
    "fulfillment": 
        {            
        "notify_customer": 'false',
        "location_id": location_id,        
        "tracking_info":{                
            "tracking_url": tracking_url,
            "tracking_company": transport_company,
            "tracking_number": tracking_number,            
            }
        }
    }

其中location_id 是一个整数,其他变量是字符串。

当我随后运行以下请求以将信息插入订单时,

r = requests.post(shop_url + '/fulfillments/' + fulfillment_id + '/update_tracking.json',
                 json=payload,headers=headers)

我收到了<Response [400]>


问题

我做错了什么?

【问题讨论】:

    标签: python curl request shopify shopify-api


    【解决方案1】:

    正确的做法是discussed here

    假设您有 shopify 订单 ID order_idshop_url,以下代码会将订单设置为已发货,

    # get order fulfillment id 
    fulfillment_orders = requests.get(shop_url + '/orders/'+ order_id +'/fulfillment_orders.json').json()     
    fulfillment_id = fulfillment_orders['fulfillment_orders'][0]['id']
    location_id = requests.get(shop_url + '/locations.json').json()['locations'][0]['id']   
    
    # get orders fulfillment line items 
    
    # note: if you want to fulfill only certain products in the order with the tracking code,
    # here's where you select these products. Right now, the code isn't doing this 
    
    fulfillment_order_line_items = []
    
    for item in fulfillment_orders['fulfillment_orders'][0]['line_items']:
        
        fulfillment_order_line_items.append(
                {
                'id': item['id'],
                'quantity': item['quantity'],
                }
            )         
    
    # set up payload
    payload = {
        "fulfillment": 
            {            
                "notify_customer": 'false',
                "location_id": location_id,        
                "tracking_info":
                    {                
                    "url": tracking_url,
                    "company": transport_company,
                    "number": tracking_number,            
                    },
                "line_items_by_fulfillment_order": [
                    {
                        "fulfillment_order_id": fulfillment_id,
                        "fulfillment_order_line_items": fulfillment_order_line_items
                    }
                ]            
            }
        }
        
    # parse tracking info
    r = requests.post(shop_url + '/fulfillments.json',
                     json=payload,headers=headers)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-02
      • 1970-01-01
      • 2022-11-09
      相关资源
      最近更新 更多