I have my first node that gets data from PostgreSQL table. Table has User_id and Access_token.
My Second node is HTTP request, which takes this user_ids and access_token as input to fetch some data (say steps and calories).
Following are the requirements -
I need to get this data per user i.e only where the user_id with active access_token. If the user is not active and if any error then that workflow should not fail and only allow for the fetch data for active users.
After first 2 node, I need an output in json format that has user_id(coming from 1st node Postgresql node) as keys with their respective steps, calories data(coming from 2nd HTTP req node) as values.
Something like -
[
<User_id>:
{
Having different keys on each item can become a bit difficult to handle in n8n though. So depending on what you have in mind with this dataset you might want to consider writing this result into a single field, for example using the Item Lists node:
@MutedJam Thank You so much. This worked for me.
I would also like to request you, if you could suggest a solution for my first requirement.
Here, If the access token is expired/invalid, that will throw an error. Hence, I need to continue the above process for active access token user(that will not have any error) and also want to keep track of such user_ids whose access tokens are expired(due to which I might receive and authentication error).
If the access token is expired/invalid, that will throw an error
I take it the error would be thrown on your HTTP Request node? You probably want to enable the “Continue On Fail” option of the node like so:
This way, your workflow won’t stop when encountering an error. You can then use an IF node at the end of your workflow to check whether an error is present and store it as needed.
@MutedJam , Thank You for all information provided. It helped me to run most of the requirement as expected.
However, as per the second requirement wherein I wanted to keep track of such user_id that gets error due to any reason( like access token expired or wrong user_id or wrong access token etc). I want to keep track of this errors as well as corresponding user_id for which error occurred( Result should be same as our success scenario)
I tried creating the the flow with if node and then merge node but the user_ids against the error are not matching. It seems that Under Merge Node using option “Merge by position” does not guarantee the relationship of data(i.e user_id to its output).
Please check the below flow and internal insights of nodes.
Hi @SWAPNIL_NANDANWAR, looks like you are merging by position here, but the order of items might not match (so the first item on input 1 might not correspond to the first item item on your input 2).
So you probably want to use another Combination Mode on your Merge node here. Merge by Fields should work, but it would require that both inputs have a field specifying the the same id. So you might need to change your data format a bit.
@MutedJam , I thought of same solution, but the issue here is the response from HTTP Request. This node output(be it successful user_id execution or User_id with error) will not have user_ids. Hence how would we even combine them by ids that is a tricky part.
Could you please suggest on this?
the issue here is the response from HTTP Request. This node output(be it successful user_id execution or User_id with error) will not have user_ids
Hi @SWAPNIL_NANDANWAR, you could add a Set node after your HTTP Request node in order to add a field with the user ID from before your HTTP Request node. @giulioandreini has shown the idea over here for a different node, but it should work just as well with the HTTP Request one
Hi @MutedJam , I have tried below flow wherein I am trying to iterate through each row(By using Function node with mode = Run Once for each Item) and get the simultaneous output and then combine it. While I execute the nodes individually(specially the final node i.e SET node), it executes successfully but when I execute the whole workflow then the final set node is giving me error. Also I want both the set node to execute as One has successful HTTP response without error and Second has error related data.
While I execute the nodes individually(specially the final node i.e SET node), it executes successfully but when I execute the whole workflow then the final set node is giving me error
Hi @SWAPNIL_NANDANWAR, I am so sorry you are having trouble. Unfortunately you only shared screenshots, but not a workflow using which I could try to reproduce your problem. Seeing the desktop app is a bit outdated, I wonder if this could be a problem with the n8n version you currently have in use.
Perhaps you can start the current latest version of n8n using docker and verify if the problem persists? Assuming you have docker desktop installed, these two commands in the terminal should do the job (replace SWAPNIL_NANDANWAR with your actual Windows username):
If the problem persists, can you share a workflow using which I can reproduce it? Simply select your workflow on the canvas, press Ctrl+C to copy it and then use Ctrl+V here on the forum to paste it.