Does the Shopify Order API allow you to filter by nested fields?

I use stone shopify_api .

The API dock shows that you can smooth out the answer of ShopifyAPI::Order by specifying which fields to return. For example, the following returns only the id attribute and shipping_address attribute

ShopifyAPI::Order.find(:all, params: {fields: "id,shipping_address"})

shipping_address turns out to be a hash with several fields inside it. Can I specify which fields are nested in shipping_address for return? , eg.

ShopifyAPI::Order.find(:all, params: {fields: "id,shipping_address['country_code']"})

It might return something like

  #<ShopifyAPI::Order:0x0000010558b348 @attributes={ "id"=>12345678, "shipping_address"=>#<ShopifyAPI::ShippingAddress:0x0000010558aa88 @attributes={"country_code"=>"US"}, @prefix_options={}, @persisted=false> }, @prefix_options={}, @persisted=true> 

I know that I can select these attributes ( order.shipping_address.country_code ), but this is more in the interests of a "skinny" reaction.

Bonus Question 1: What are the tangible benefits of using the fields parameter?

Bonus Question 2: When (if ever) can Shopify return a zero shipping address?

+4
source share
1 answer

It is usually best to post separately for each question, but here are the answers.

  • Not.
  • If you limit the returned data, it will take less time to generate a response, less data to wire and less data to analyze. This means you need to complete the operation faster. It depends on many different factors, which are difficult to say how much of the productivity increase you will reward. I feel that this is minimal if you are not performing a very large number of requests.
  • The delivery address may be empty if the order (i.e. all items) does not require delivery.
+3
source

All Articles