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?