Problem passing data to API

Hi,

I have two API calls in the workflow. First API return results, consolidating using function node with code like this

payment.json.map(i => ({json:i})).forEach(j => paymentsInfo.push(j));

and for second API passing the function node results as input. When I do node[“Function”].json, I only see one item in the input passed to second API as supposed to all items.

Input to the second API body expression is
{{ { “receipts”: $node[“Function”].json } }}

What am I doing wrong here…Please help

@jan an @jon @RicardoE105

Morning @dsuresh,

Is your first node returning more than one result and on your second node at the top does it have a number?

Which nodes are you using and are you able to send some screenshots of the output of the function and the output of the second node? A full snip of the node pop up box is best and you can edit out anything personal / sensitive.


@jon

Sent images

second image is the input to the API call

Does that second node have a little number at the top of it? It looks like it should be working but I may be missing something.

@jon

Hey @dsuresh,

Looking at the screenshot of the Function node, it seems like it is returning 3205 items. If you want to use all the items in a single request, you will have to change the data structure. You can use the Item Lists node for that.
Currently, your data structure is as follow

[
 {},
 {},
...
]

You need to transform it to

[
 [
  {},
  {},
 ...
 ]
]
1 Like

@harshil1712

Can you pls provide more details…sorry

Here’s a small example workflow

{
  "nodes": [
    {
      "parameters": {
        "operation": "getAllPeople",
        "returnAll": true
      },
      "name": "Customer Datastore",
      "type": "n8n-nodes-base.n8nTrainingCustomerDatastore",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": " return [\n  {\n    json: {\n      receipts: items.map(item => item.json)\n    }\n  }\n]\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    }
  ],
  "connections": {
    "Customer Datastore": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

The first node returns 5 items. We use the Function node to combine all the items and return all the values in a single item. If you execute both the nodes, you will be able to see the number of items returned by them.
You will have to use a similar function node to combine and return a single item, and pass that to your HTTP Request node.

1 Like

Thanks
@jan
@harshil1712
@jon
@RicardoE105
Really appreciated.

1 Like

No problem!

Can you please mark the solution that helped you? This will help others find it easily :slight_smile:

Sure, marked as solution

1 Like