{
  "name": "RecruitAffiliates.ai: new affiliate to a Google Sheet",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "recruitaffiliates-signups",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "a1f0c001-0000-4000-8000-000000000001",
      "name": "RecruitAffiliates webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ],
      "webhookId": "recruitaffiliates-signups"
    },
    {
      "parameters": {
        "action": "hmac",
        "type": "SHA256",
        "value": "={{ ($json.headers[\"rail-signature\"] || \"\").match(/t=(\\d+)/)?.[1] + \".\" + JSON.stringify($json.body) }}",
        "dataPropertyName": "expected_signature",
        "secret": "whsec_REPLACE_WITH_YOUR_SIGNING_SECRET",
        "encoding": "hex"
      },
      "id": "a1f0c001-0000-4000-8000-000000000002",
      "name": "Work out the signature",
      "type": "n8n-nodes-base.crypto",
      "typeVersion": 1,
      "position": [
        220,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ ($json.headers[\"rail-signature\"] || \"\").split(\",\").map(p => p.trim()).filter(p => p.startsWith(\"v1=\")).map(p => p.slice(3)).includes($json.expected_signature) }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            },
            {
              "id": "c2",
              "leftValue": "={{ Math.abs(Date.now() / 1000 - Number(($json.headers[\"rail-signature\"] || \"\").match(/t=(\\d+)/)?.[1] ?? 0)) < 300 }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            },
            {
              "id": "c3",
              "leftValue": "={{ $json.body.type }}",
              "rightValue": "affiliate.signed_up",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "a1f0c001-0000-4000-8000-000000000003",
      "name": "Real, recent and the right event",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        440,
        300
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://api.affiliaterail.com/v1/finder/prospects/{{ $('RecruitAffiliates webhook').item.json.body.data.prospect_id }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer rail_live_REPLACE_WITH_A_READ_ONLY_KEY"
            }
          ]
        },
        "options": {}
      },
      "id": "a1f0c001-0000-4000-8000-000000000004",
      "name": "Get the affiliate",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        660,
        280
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "https://docs.google.com/spreadsheets/d/REPLACE_WITH_YOUR_SHEET_ID/edit"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Sheet1"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Name": "={{ $json.name }}",
            "Website": "={{ $json.url }}",
            "Email": "={{ $json.email }}",
            "Signed up": "={{ $('RecruitAffiliates webhook').item.json.body.created_at }}",
            "How we know": "={{ $('RecruitAffiliates webhook').item.json.body.data.source }}"
          },
          "schema": [
            {
              "id": "Name",
              "displayName": "Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Website",
              "displayName": "Website",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Email",
              "displayName": "Email",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Signed up",
              "displayName": "Signed up",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "How we know",
              "displayName": "How we know",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      },
      "id": "a1f0c001-0000-4000-8000-000000000005",
      "name": "Add a row",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        880,
        280
      ]
    }
  ],
  "connections": {
    "RecruitAffiliates webhook": {
      "main": [
        [
          {
            "node": "Work out the signature",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Work out the signature": {
      "main": [
        [
          {
            "node": "Real, recent and the right event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Real, recent and the right event": {
      "main": [
        [
          {
            "node": "Get the affiliate",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Get the affiliate": {
      "main": [
        [
          {
            "node": "Add a row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  }
}