Workflow keeps passing the wrong item data to the final step after an IF block (run once for each)

Describe the problem/error/question

I have a workflow that takes data from an API (a list of speakers + their bios), sorts out unnecessary data (the source tool contains both attendees and speakers), then checks if the destination system already has the speaker profile created, and then either makes a POST to create a new speaker profile (if the destination system doesn’t contain it) or a PATCH request (if the speaker exists).

However, after the first time I run it, the POST flow will always take the first item returned by the host, even if that already exists in the destination system.

Could someone help me POST the correct data from the item that should be passed?

As an example:

Let’s say that the first time the workflow runs:

  • Source system returns 5 items [A, B, C, D, E,]
  • These 5 are passed to the destination system correctly (through the final POST HTTP Request node in the workflow).

The second time the workflow runs:

  • The source system returns 7 items (2 new speakers have been added), so: [A, B, C, D, E, F, G]
  • However, the items whose data gets sent to the POST node are: A and B. (Not F and G, as it should be). So, I end up with duplicates of A and B.

If there are 3 new items the next time, then the workflow will just resend A, B and C from the source system, instead of the new ones.

In addition, if, for some reason, the the first time the workflow runs, one of the speakers (let’s say “C”) doesn’t get passed through (maybe the profile is incomplete / there was an error); then, the next time it runs, the workflow will not send “C” to the POST request, but will instead send “A” again (creating a duplicate).

Is there anyone who could help with this? I’ve been struggling with this for 3 days now :sweat:— any assistance / ideas would be super helpful!

Thank you :slight_smile:

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

The last POST node always POSTs the first few items in the IF1 node. It’s never the correct ones that actually don’t exist in the destination system (for which “myKey” from the code step has a false value).

Information on your n8n setup

  • n8n version: 0.221.2 (Latest Stable)
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Cloud
  • Operating system:

Welcome to the community @kaviw!

Sorry do not have time to answer all of your question but at least a quick one regarding it using the wrong items.

Use instead of the syntax:

$node["NodeName"].json["name"]

the following:

$("NodeName").pairedItem().json["name"]

That will make sure that it does not simply get the item with the same index, it rather gets the one it did originate from.

Hope that first step is already helpful.

1 Like

Hi Jan! Thanks so much for this. Will try it out and report back :slight_smile:

1 Like