Question

Javascript only returning first value

  • 20 August 2020
  • 5 replies
  • 362 views

Userlevel 1
fetch(url, { method: "POST", headers: headers, body: JSON.stringify(data) })
  .then((res) => {
    return res.json();
  })
  .then((json) => {
    // Do something with the returned data.

    var output = json.apicallsetoutput;
    console.log(output);
    callback(null, output);
  })
  .catch((error) => console.log(error));

For some reason zapier is only taking in the first record of var ouput. Am I missing something to ensure that it is reading all records in output?


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

Userlevel 7
Badge +12

Hi @monkeybutton - What you see is totally normal. When you test a code step and the result is an array, only the first result will be shown because each item of the array would trigger the subsequent step separately.

Userlevel 7
Badge +8

@ikbelkirasan - Could you chime in here if you get the chance? It seems like we could be close to a solution. Thanks!

Userlevel 7
Badge +12

Hey @steph.n - Sure, no problem.

@monkeybutton - Did you manage to solve the problem? If not, does it update all the records when the zap is turned on? I think it only works with the first result when you’re building/testing the zap.

Userlevel 1

Hi @monkeybutton - What you see is totally normal. When you test a code step and the result is an array, only the first result will be shown because each item of the array would trigger the subsequent step separately.

I am not able to sync all the records to activecampaign though, it is only taking the first result even though I already have at least 50 records in the response of the API call.

Userlevel 1

I am getting this error when trying to do a test:

 

The email 'email1@email.com, email2@email.com, email3@email.com' is not a valid email.

 

the 3 separate email addresses are returned in the response as individual records in the array.