Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Shopify Order API allows filtering by nested fields?

I'm using the shopify_api gem.

The API doc shows that you can skinny down a ShopifyAPI::Order response by telling it which fields to return. For example, the following will return only the id attribute, and the shipping_address attribute(s)

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

shipping_address happens to be a hash with multiple fields inside it. Is it possible to specify which fields nested within shipping_address to return? e.g.

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

This 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 I can pick that attributes out myself (order.shipping_address.country_code), but this is a more in the interests of 'skinnying down' the response.

Bonus Question 1: What are the perceivable advantages of using the fields parameter?

Bonus Question 2: When (if ever) might Shopify return a nil shipping address?

like image 790
Nick Malcolm Avatar asked Jul 08 '12 10:07

Nick Malcolm


1 Answers

It's usually better to post seperatly for each question, but here's the answers.

  1. No.
  2. If you limit the data being returned it will take less time to generate the response, less data to transfer across the wire and less data for you to parse. This means that it should be faster for you to do an operation. This depends on so many different factors that it's hard to say how much of a performance increase you will reciece. My feeling it is minimal unless you are doing a very large number of requests.
  3. Shipping address may be blank if the order (ie all line items) doesn't require shipping.
like image 114
John Duff Avatar answered Nov 09 '22 13:11

John Duff