How do I specify nested fields in the Order API?

David_Miller4
Visitor
3 0 8

The API for requesting order information includes a “fields” parameter where one can specify fields of interest. Extra, unneeded data doesn’t come over the wire. Great! If one of the fields I’m interested in is line_items, is there a way to specify which fields of each line_item I want?

This request will still give me a bunch of data that I don't care about via the line_items:

https://mystore.myshopify.com/admin/orders.json?fields=id,total_price,line_items

I just need the ‘name’ field for each line item.

Thanks!

Replies 10 (10)

DevaGH
Visitor
1 0 0

Did you find a solution for this?

O0O0
Shopify Staff
5 0 1

Unfortunately at this time the `fields` filtering only supports top-level fields. In other words, you can't select fields of nested objects.

To learn more visit the Shopify Help Center or the Community Blog.

bterrell
Visitor
1 0 1

Is this something Shopify might be adding in the near future?  

Matt_Bertino
New Member
5 0 0

Is any update on this at this time? I've got a similar scenario and the entire line_items object to just a ton of data that isn't necessary.

RC_CH
Visitor
2 0 1

Hi ,

I am also looking for the solution for this. Not sure if Shopify has added this feature which I feel really a good feature. 

Hope they will add it soon if not already done. Please confirm how can we access the nested field if already done.

Thnks & regards,

RC

Gregarican
Shopify Partner
1033 86 285

I've found when working with most API providers...it's better to get too much data than too little. 🙂 Sometimes there can be a lack of API endpoint properties, or a litany of nested relational fields that have to be queried.

So in those cases you either can't retrieve the data, or else have to make several iterative calls to retrieve the data you are looking for. While I get it, in that you have to parse through the response sets and ignore a lot of fields that you don't need or care about. But it's far better than the alternative. And at least we can issue REST API queries with filter criteria. Some API providers lack enough of this functionality. So besides unnecessary fields in the responses, you have to discard entire records that aren't what you're looking for! 

Matt_Bertino
New Member
5 0 0

I typically agree with everything you are saying. 

I won't speak for anyone else but the main reason I'd like to see this is due to memory consumption issues at scale. 

While working on hosted application platforms like heroku you are often memory constrained. And while it's nice to have all the data for testing purposes it's create a memory problem when you are trying to import 250 orders at a time and the line_items array of objects is massive. 

It's caused us to lower this to retrieving 100 orders at a time which of course means more API call in general but other than beefing up our own dynos (cost prohibitive for some) there's really not an option. 

Varun_Dhondea
Visitor
1 0 0

Hi,

Has this feature been implemented?


Thanks

rikkertkoppes
Shopify Partner
1 0 0

Any news on this? I want to specifically omit customer data like addresses and names and stuff, but keep country information for reporting.

This way, I can show in my code that I only ever retrieve non-sensitive information

ShopifyDevSup
Shopify Staff
1322 216 456

Hi @rikkertkoppes 👋

 

GraphQL `orders` query allows only a selection of fields to be returned as seen below. Please keep in mind that the app may still be subject to certain protected data scopes.

 

{
    orders (first:25) {
        nodes {
            id
            createdAt
            lineItems (first:10) {
                nodes {
                    id
                }
            }
        }
    }
}

 

Hope that helps!

 

 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog