Question

How to get array of arrays from Shopify field?

  • 27 October 2021
  • 10 replies
  • 437 views

Badge

I have a Shopify field (“Line Items Properties Name”) coming in as an array of arrays (e.g. [“_instoreAppId”], [“1”, “4”, “6”, “10”, “_instoreAppId”]). I need to work with that in a Code step, but Code forces everything into a string (and not even JSON), so when it comes in, it ends up looking like _instoreAppId,1,4,6,10,_instoreAppId”, which is not helpful. When I try to do a line-item-to-text formatter step and separate the array items by |||, I get the nonsensical output of

output

item_1
_instoreAppId,1,4,6,10,_instoreAppId

item_2
_instoreAppId,1,4,6,10,_instoreAppId

item_last
_instoreAppId,1,4,6,10,_instoreAppId

text
_instoreAppId,1,4,6,10,_instoreAppId|||_instoreAppId,1,4,6,10,_instoreAppId

How is one supposed to get this data?


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

10 replies

Userlevel 6
Badge +6

Hey @djung ,

 

What exactly do you want to do with with array? 

Badge

I want to get the numbers of cookies per flavor. Let’s say I order 2 items: 1 dozen cookies and 2 dozen cookies. Let’s say I choose 4 flavors for the 1st item and 2 flavors for the 2nd item. The flavors data would then come in like

["Cinnamon", "Apple", "Cookies N' Cream", "Yellow-Green"],["White Chocolate", "Cinnamon"]

This would help me see I need 15 Cinnamon cookies, 3 Apple cookies, 3 Cookies N’ Cream cookies, 3 Yellow-Green cookies, and 12 White Chocolate cookies. However, when that data comes in to a Code step, it gets squashed into “Cinnamon”,”Apple”,”Cookies N’ Cream”,”Yellow-Green”,”White Chocolate”,”Cinnamon”, and I have no idea where one line item ends and another begins.

Userlevel 6
Badge +6

@djung Hey, Thanks for the explanation.

 

What do you want to do with Flavours array in Code by Zapier? You want data in which format, can you post an example?

 

Aso Can you post screenshot of code by Zapier action and the data that gets squashed?

Badge

I want the data in the format I gave above, where it’s an array of arrays. But since Code by Zapier can only provide strings, the next best ideal would be to be able to separate the array of arrays by a separator like “|||”. As in my original post, if I had an array of arrays like [“_instoreAppId”], [“1”, “4”, “6”, “10”, “_instoreAppId”], being able to separate those arrays w/ a separator before being converted into a string would ideally look like “_instoreAppId|||,1,4,6,10,_instoreAppId”. However, when I try the closest thing to that in Zapier (using line-item-to-text formatter), it ends up looking like, as I stated in my original post, “_instoreAppId,1,4,6,10,_instoreAppId|||_instoreAppId,1,4,6,10,_instoreAppId” for some odd reason.

 

As for an example of data getting squashed, you can see it via any array of arrays getting set to an input variable for Code by Zapier and simply seeing what that is (you can even see it just from the input).

If I didn’t have something like “FT=delivery” in between, I wouldn’t be able to tell where one array ended and another began.

Userlevel 6
Badge +6

Hey @djung ,

 

Is this what you are looking for? Lets assume You get an output like below. Yellow marked values are array inside array

Now by writing some javascript code, i generated a value like below.

 

If this is what you are looking for? If yes, than it is possible to generate the output the way you want. (Please note abovevalue  data type is string, however i am confident we can convert this to an array also )

 

Hope this solves your problem.

Badge

No, I’m looking for how one would’ve kept that array of arrays when in a Code step. I’m not even trying to manipulate the data; just trying to have it somehow keep the array items clearly separated/delimited (even if it’s a string) when receiving an array of arrays as input to a Code step.

Badge

E.g. how do I keep [“_instoreAppId”], [“1”, “4”, “6”, “10”, “_instoreAppId”] looking like that or make it become a string like “_instoreAppId|||,1,4,6,10,_instoreAppId”?

Badge

Or like I mentioned in my first reply to you, how do I keep ["Cinnamon", "Apple", "Cookies N' Cream", "Yellow-Green"],["White Chocolate", "Cinnamon"] looking like that instead of “Cinnamon”,”Apple”,”Cookies N’ Cream”,”Yellow-Green”,”White Chocolate”,”Cinnamon”, which is how it gets converted when it’s set as input to a Code step?

Userlevel 6
Badge +6

Hey @djung ,

 

The output in 2nd image was just an example where you can create custom array in an array.  You can write a javascript code for the same.

 

However, if you think this is still not resolved, than i would like to pass this to Zapier team and they will reply to you as soon as they can.

Hi @djung,

Did you find a solution to this? 

I am experiencing the same issue & have been in talks with Zapier about it for a few days - but no solution has yet been found. I’m starting to think it is something that can’t be achieved, which seems a bit weird given that it is quite simple.