Way to find sales channel of an order?

Solved
kenxu0927
Tourist
7 0 1

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
Greg_Kujawa
Shopify Partner
1016 83 243

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
kenxu0927
Tourist
7 0 1

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

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 243

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
kenxu0927
Tourist
7 0 1

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
Greg_Kujawa
Shopify Partner
1016 83 243

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
kenxu0927
Tourist
7 0 1

Thanks @Greg_Kujawa for the solution  

0 Likes
lindamx
New Member
2 0 0

Hi @Greg_Kujawa 

This is super helpful and relevant to me as well. I'm trying to retrieve orders data to build a database - I was using the REST APIs before realizing the GraphQL APIs will probably serve me way better to retrieve orders at bulk. However, since I had imported my orders data using REST APIs, I was extracting app_id to track the sales channel. What's the equivalent in the GraphQL API? Is orders[i].app_id in the REST API the same thing as orders.publication.app in the GraphQL API? Or would I need to go one level deeper in the GraphQL API - orders.publication.app.id?

 

Thanks!

0 Likes
Cristina5
New Member
2 0 0

@lindamx Did you ever get an answer to this question? I'm also looking to retrieve the app_id from the GraphQL API but I can't find it anywhere??

0 Likes