Skip to main content
Best answer

How can I create an array of strings from a comma-separated string


jeffernst
Forum|alt.badge.img

I’m creating a Zap to post a field that is coming in from Google Sheets as a comma-separated string, to my app’s API that expects an array of strings.

In Zapier Developer, I test it by keying in a comma-separated string and it works fine with a payload like this:

 

But in the Zap, I keep getting error: The app returned "activityTypesWillingToDo must be an array of strings".

I’ve tried Transforming from String to Line-Item, I’ve tried javascript to turn it into an array:

const { lineItemEasy, } = inputData;

const lineItemEasyArray = lineItemEasy.split(',');

output = [{ lineItemEasyArray, }];

And I’ve tried actually hard-coding the array of strings into the input field of my Action.

Please help!

 

Best answer by GetUWiredBest answer by GetUWired

It can go into the backend integration. And it is assuming the input field key for “activityTypesWillingToDo” is just activityTypes.

The input field can also be configured to allow multiple multiples. https://platform.zapier.com/docs/input-designer#allows-multiples

I hope that helps !

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

5 replies

GetUWired
Forum|alt.badge.img+12
  • Zapier Expert
  • 1030 replies
  • April 27, 2021

What API are you using? 

What does your code look like or the input fields? 

If you have the items in an input field called “activityTypes” you can use the following code to check if the value is an array and if not split it into one. 

 

let lineItems = [];

if (Array.isArray(bundle.inputData.activityTypes))
  lineItems = inputData.activityTypes;
else 
  lineItems = bundle.inputData.activityTypes.split(",");

 


jeffernst
Forum|alt.badge.img
  • Author
  • Beginner
  • 12 replies
  • April 27, 2021

@GetUWired The API I’m using is in my company’s commercial software app documented here.

I currently don’t have any code on the input field itself.

The code you gave, would that go in a  Run Javascript step in the Zap? Or would that go in the back end integration setup (which I’m currently not using custom code there)?


GetUWired
Forum|alt.badge.img+12
  • Zapier Expert
  • 1030 replies
  • Answer
  • April 27, 2021

It can go into the backend integration. And it is assuming the input field key for “activityTypesWillingToDo” is just activityTypes.

The input field can also be configured to allow multiple multiples. https://platform.zapier.com/docs/input-designer#allows-multiples

I hope that helps !


Matt_Boyden
Forum|alt.badge.img
  • Zapier Staff
  • 38 replies
  • June 16, 2021

Hi @jeffernst were you able to get this resolved? Let us know how it goes!


jeffernst
Forum|alt.badge.img
  • Author
  • Beginner
  • 12 replies
  • June 16, 2021

@Matt_Boyden Yes, thank you @GetUWired , that did the trick.

Jeff