2
votes

I'm trying to query for "Sales channel name" for Orders from Shopify via the Shopify Python API. I was able to get an order and use to_dict() to get all all fields of the Order but I couldn't find any field related to "Sales channel name". However, as you can see from the attached image, there's a column relates to that in Shopify own report tool.

result = shopify.Order.find(name = "#99735")
result[0].to_dict()

Sales channel name in Shopify site

1

1 Answers

0
votes

You need to look for the "source_name" in the Order object.

Source Name is set to Where the order originated. Can be set only during order creation, and is not writeable afterwards. Values for Shopify channels are protected and cannot be assigned by other API clients: web, pos, shopify_draft_order, iphone, and android. Orders created via the API can be assigned any other string of your choice. If unspecified, then new orders are assigned the value of your app's ID. - Source

How to get source name -

result = shopify.Order.find(name = "#99735")
result[0].to_dict()
source_name = result[0].to_dict().get('source_name')

Update: Ideally, if you want to get the source of sale you need to take a look at transactions for the order. Try this -

for trn in shopify.Transaction.find(order_id = "<order_id>"):
    trn.to_dict().get('source_name')