Request of help to configure an API call

Describe the question

I wanted to configure a call to an API in order to request some information from one service called GoCardless (still pending support from n8n).

I have that query configure with an addon from google sheet but I prefer to move to n8n as that will give me more option of further process. The issue is that I’m a little lost on how to get the same results in n8n because of my poor knowledge :frowning:

I guess someone can help me how to translate to the correct node.

This is how a have configured on google sheet add-on

image
image
image

Any help will be more than welcome!!!

Information on your n8n setup

  • n8n version: 0.198.2
  • Database you’re using (default: SQLite): I guess de default
  • Running n8n via: Docker on my Synology NAS

Hi @MaaPer, which problem exactly do you have with n8n here? Did you try out the HTTP Request node yet and got any error? And do you have any documentation for this API?

Hey @MaaPer,

As a starting point this will get all customers, You will need to add a generic header auth option that follows the API docs to get it working. It also doesn’t merge the execution outputs to provide one list but this should get you started.

2 Likes

Thanks @MutedJam & @Jon for your help.
What is not clear to me is how to configure the authorization key on header account (credential for header). I tried with different option of name a putting the key that is properly working on my actual query from google sheet but without success.
Can you help me with that?

Hi @MutedJam this is the documentation.

I think I’m failing with the authentication but not sure.

Now it’s working!
I put the configuration here for if could be usefull for someone.
The correct is put Bearer + API_KEY_SECRET on value, and Authorization on Name

Thanks again!

Now I help on how to put all the values on one single datatable. I tried to use Split Out form Item List node, but it only split the last information from the IF node and not all the records caught by the http request node. Any clue with that?

This is the flow, no I will need some kind of function to map all pages from IF node or HTTP node into one single list.?

1 Like

Glad to hear it’s working!

This is the flow, no I will need some kind of function to map all pages from IF node or HTTP node into one single list.?

You could use the approach documented here: Merge data for multiple executions | n8n workflow template

1 Like

Thanks a lot @MutedJam

I have reach to that post just few moments before your post :slight_smile:

I put this code in the code node:

//return $("Get Customers1").all()[0,$runIndex];

const allData = []

let counter = 0;
do {
  try {
    const items = $items("Get Customers1", 0, counter).map(item => item.json);
    allData.push.apply(allData, items);
  } catch (error) {
    return [{json: {allData}}];  
  }

  counter++;
} while(true);

Now I have all the pages into one!, the only thing is that the structure for the data is something like this:

[
{
"allData":
[
{
"customers":
[...], // 50 items
"meta":
{...} // 2 items
},
{
"customers":
[...], // 50 items
"meta":
{...} // 2 items
},
{
"customers":
[...], // 50 items
"meta":
{...} // 2 items
},
{
"customers":
[...], // 50 items
"meta":
{...} // 2 items
},
{
"customers":
[...], // 50 items
"meta":
{...} // 2 items
},
{
"customers":
[...], // 50 items
"meta":
{...} // 2 items
},
{
"customers":
[...], // 35 items
"meta":
{...} // 2 items
}
]
}
]

After that node, I need to use two additional steps to get all the useful information (customers) on the same table. I put two item list nodes for split out. The first node is used to split out “allData” the second to do the same with “customers”.

How can I split out in the same code node and avoid those two additional steps? (if it is possible, just for my knowledge).

Hi @MaaPer, I’ve built an updated example workflow which uses the new code node, and which returns the actual items rather than s single item with the allData property:

Simply update the name of the node you want to grab data from in the code node.

That said, the customers comes from your API, so I’ve not covered this in the code to keep it as flexible and re-usable as possible. So, you’d still need one Item Lists node here. Let me know if this is a problem, and I’ll build a quick example taking care of the customers as well :slight_smile:

Thanks for your valuable help.
In my side there is an error on that usage of all()

Now I realize that even with that call error on the code editor, the flow is working.
How it will be the code to remove the second level (customers) so avoid using the item list node at all for split out?

Hey @MaaPer,

Looking at your flow you have 2 item list nodes, I was just having a play and it only needs the one. The workflow below will get all customers from Go Cardless.

Thanks! I need to put a wait 1 second node after set, otherwise my flow execution hangs the explorer tab on testing. I also put to get 50 records (max) on each loop execution.

It’s working perfect, however still need an item list node for the last step :slight_smile:

Thanks for your valuable time!