Way to find sales channel of an order?

Solved
Highlighted
New Member
7 0 0

I'm a developer and one of our users asked for a feature to iterate through all sales channels similar as from the admin page (similar as shown in the below screenshot).

屏幕快照 2020-07-14 上午11.22.45.png

However, I couldn't find ways to retrieve this from the Orders API. It seems the "Order" object has "source_name" and "app_id" fields but they only have values within a fixed enum set ("web" and "shopify_draft_order"). Anyone knows if there's a way to get the "real" sales channel of an order or it's still not a live feature yet? Thanks!

0 Likes
Highlighted
Shopify Partner
318 21 65

If you look at the Shopify GraphQL API reference (https://shopify.dev/docs/admin-api/graphql/reference/object/order?api[version]=2020-07) you will see a publication field. This should link back to the sales channel that brought in the order I believe.

As for the REST API endpoint for orders, the app_id has hard-coded integer values that translate to the sales channel that the order was created through. Actually in the Shopify web admin, you can filter orders by sales channel and see the app_id values in the URL. These app_id values don't change once the shop has installed the sales channels.  See below.

Sales Channel Filter.jpg

If this doesn't suffice, hopefully the GraphQL route will automatically perform the mapping as to the real sales channel names...

0 Likes
Highlighted
New Member
7 0 0

Hi @Greg_Kujawa, could you give a simple example on where the name of sales channel locates? Thanks!

0 Likes
Highlighted
Shopify Partner
318 21 65

Look at my screen shot I provided up above. It shows in the Shopify web admin where if I select a sales channel in the GUI, the ID appears in the URL in the address bar. That's a quick way to map which ID goes with which sales channel name. While you might be able to get at this programmatically using the GraphQL API or something, if you don't have a lot of sales channels and since the ID mappings don't change, this is a quick and easy way to do this   

0 Likes
Highlighted
New Member
7 0 0

Hi @Greg_Kujawa sorry I didn't make my question clear. I meant would it be possible to give a simple GraphQL example for this? Since I'm an app developer it's not quite likely to access our user's admin dashboard to read ID-name mappings of their sales channels. 

0 Likes
Highlighted
Shopify Partner
318 21 65

This is an accepted solution.

Try this, for the most recent 20 orders.

 

{
  orders(first: 20, reverse: true) {
    edges {
      node {
        id
        createdAt
        publication {
          id
          name
        }        
      }
    }
  }
}
0 Likes
Highlighted
New Member
7 0 0

Thanks @Greg_Kujawa for the solution  

0 Likes