docs

n8n: save your top 10 and collect their emails

An n8n workflow that saves your 10 best matches, finds each one's email and adds them to a Google Sheet.

Once a week, n8n takes your 10 best-fit matches from RecruitAffiliates.ai, saves them and finds their emails. Then it writes each one to a Google Sheet you can work from.

Finding an email uses one email credit, and only when a usable address comes back. If we find nothing, the credit comes straight back. So this workflow can use up to 10 email credits a run.

What you need

  • A plan that includes the API, and a key with the finder:write scope.
  • n8n, on their cloud or your own server.
  • A Google Sheet with columns for Name, Website and Email.

Store the key once

  1. In n8n, create a credential of the type "Header Auth".
  2. Set the name to Authorization and the value to Bearer rail_test_....

Every HTTP Request node below uses this credential. Your key then lives in one place, not in every node.

Build the workflow

  1. Add a "Schedule Trigger" node. Set it to once a week.
  2. Add an "HTTP Request" node to get your best matches:
SettingValue
MethodGET
URLhttps://api.affiliaterail.com/v1/finder/prospects
AuthenticationGeneric, Header Auth, your credential
Query parameterssort = fit, limit = 10
  1. Add a "Split Out" node on the field data. Each match becomes its own item.
  2. Add an "HTTP Request" node to save them all in one call. Set it to run once for all items (in its settings, "Execute Once"):
SettingValue
MethodPOST
URLhttps://api.affiliaterail.com/v1/finder/prospects/save
Send bodyJSON, {"ids": {{ JSON.stringify($('Split Out').all().map(i => i.json.id)) }} }
HeaderIdempotency-Key = save-{{ $execution.id }}
  1. Add an "HTTP Request" node to reveal each email. This one runs once per item:
SettingValue
MethodPOST
URLhttps://api.affiliaterail.com/v1/finder/prospects/{{ $('Split Out').item.json.id }}/reveal_email
HeaderIdempotency-Key = reveal-{{ $execution.id }}-{{ $('Split Out').item.json.id }}
  1. In that node's settings, turn on "Retry On Fail" and set "Wait Between Tries" to 2000 milliseconds.
  2. Add a "Google Sheets" node with the operation "Append Row". Map the name and website from the Split Out node and the email from the reveal.
  3. Run the first node by hand with your test key to check the matches come back. A test key can't save, because saving records an event that reaches your live webhooks, so swap in a live key for a full run. Check the sheet, then turn it on.

Why the keys look like that

An idempotency key is a unique string you send so a retried request never runs twice. Each key here joins the run's id with the match's id. When n8n retries a reveal, it sends the same key, so you're never charged twice for the same email. Next week's run has a new run id, so it gets fresh keys.

If something goes wrong

  • A 402 means your plan doesn't include the API.
  • A 429 means you've hit the rate limit. The retry setting in step 6 handles it.
  • A reveal that finds nothing still succeeds. The email is empty and the credit comes back. Add an "If" node before the sheet to skip those rows.

Keys, errors, limits and every endpoint are in the API guide.

Get events the moment they happen

The workflow above runs when you start it. A webhook starts one for you the moment something happens, like a reply or a finished search. Webhooks explains the events. You need a plan that includes webhooks.

  1. Add a "Webhook" node. Set the method to POST.
  2. Copy its production URL. The test URL only works while the editor is listening.
  3. In RecruitAffiliates.ai, go to Settings, then the Webhooks tab. Add the URL as an endpoint and pick your events.
  4. Turn on the node's "Raw Body" option if you want to check the signature in a Code node.
  5. Activate the workflow, then press Send a test.

Keep the URL private. Anyone who has it can post to your workflow. Checking the signature is what stops a fake.

Ready-made workflows

Two workflows you can import as they are. In n8n, open a new workflow, press the three dots, choose Import from File and pick the file.

Each one checks the signature for you. It works the HMAC out with n8n's Crypto node and only lets through a message that's real and less than five minutes old. Then it fetches the affiliate's name and website from the API.

Before you turn one on, replace each REPLACE placeholder:

  1. whsec_REPLACE_WITH_YOUR_SIGNING_SECRET in "Work out the signature": the secret from the Webhooks tab.
  2. rail_live_REPLACE_WITH_A_READ_ONLY_KEY in "Get the affiliate": a Read only key from the API tab.
  3. The Slack address, or the sheet's link, in the last node. The sheet needs the columns Name, Website, Email, Signed up and How we know.

Was this page helpful?