EZ Exporter: Retrieve Specific Field Attributes with the "search_attributes()" Function

One of our customers needed a way to pull a specific Line Item Property from his Shopify orders to his exported CSV file and assign it to a specific column.

We definitely see the value of being able to do something like this so we added a custom function called search_attributes() to be able to do this easily in the Calculated Fields.

For example, let's say you have a bunch of Line Item Properties like this:

subcategory: "Birthday Rings"
engraving: "Jane Doe"
birthday_message: "Happy Birthday! Hope you like this gift."

But in your report, you only want the "engraving" property to be included. With the search_attributes() function, you can use the following formula in a Calculated Field:

search_attributes({{ line_items.properties }}, "engraving")

This will pull just the value of the "engraving" property and put that value in the column you specified. If the order doesn't have that property, it will simply be blank in the report. If you want the default value to be something else, you can do something like this:

search_attributes({{ line_items.properties }}, "engraving", default="N/A")

In this case, if the "engraving" property doesn't exist, the value in the exported CSV will be "N/A" instead.

The search_attributes() function can be used in other dynamic fields as well such as Note/Cart Attributes and Tax Lines. By default, the function specifically searches the "name" key and returns the content of the "value" key as returned by the Shopify API. We built the search_attributes() function with flexibility in mind so it can be used in other fields where the keys are different.

To give you an example, let's say multiple taxes are applied to your orders. In this case, you'd want to search the line_Items.tax_lines field, which could look something like this:

[
    {
        "title":"NY State Tax",
        "price":"4.00",
        "rate":0.04
    },
    {
        "title":"New York County Tax",
        "price":"4.87",
        "rate":0.04875
    }
]

In your report, you may want a column called "NY State Tax Price" and "NY County Tax Price". You can use the search_attributes() function this way:

"NY State Tax Price" column

search_attributes({{ line_items.tax_lines }}, "NY State Tax", search_key="title", result_key="price", default="N/A")

"NY County Tax Price" column

search_attributes({{ line_items.tax_lines }}, "New York County Tax", search_key="title", result_key="price", default="N/A")

As you can see, the search_attributes() function can become very handy in situations where you need to separate very specific attributes from dynamic fields.

Tags: new features, shopify, csv export, ez exporter, reporting