{
  "name": "Ratifia: try to get around the protected send",
  "nodes": [
    {
      "parameters": {
        "content": "## Try to get around it\n\nHands the protected send six emails. Five are refused. The sixth is the approved email again: it is recognised as a retry and **not** sent a second time.\n\nPaste an approved and a rejected decision id into **Attempts**, and point **Try to send** at the protected send workflow.",
        "height": 220,
        "width": 520
      },
      "id": "fa545fcc-a239-4d9e-b719-b608ac1d3a80",
      "name": "Note 7b6d7a",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {},
      "id": "518efe62-41d7-4170-a0ae-ffed2de95b35",
      "name": "Run it",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Each item hands the protected send something it should not accept, except the last.\nconst approved = 'dec_REPLACE_WITH_THE_APPROVED_DECISION' // approved for the email below\nconst rejected = 'dec_REPLACE_WITH_A_REJECTED_DECISION'\nconst email = {\n  recipient: 'dana@acme.com',\n  subject: 'Your refund for invoice INV-2291',\n  body: \"Hi Dana,\\n\\nWe've refunded the duplicate charge of $620.00 to the card ending 4242. It should appear within 5 business days.\\n\\nThanks for your patience,\\nAcme Support\",\n  attachments: ['refund-receipt-INV-2291.pdf'],\n}\nreturn [\n  { attempt: 'No decision at all', ...email, decisionId: '' },\n  { attempt: 'Body edited after approval', ...email, body: email.body.replace('$620.00', '$6,200.00'), decisionId: approved },\n  { attempt: 'Sent to a different person', ...email, recipient: 'someone.else@example.org', decisionId: approved },\n  { attempt: 'A decision that was rejected', ...email, decisionId: rejected },\n  { attempt: 'A decision that does not exist', ...email, decisionId: 'dec_does_not_exist' },\n  { attempt: 'The approved email again (a retry)', ...email, decisionId: approved },\n].map(json => ({ json }))\n"
      },
      "id": "0e038c46-bbe6-4b34-a002-61d25bfb456a",
      "name": "Attempts",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        300
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "6ba3e91f-1ca8-4b18-aa31-bb330080bda0",
      "name": "One at a time",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        440,
        300
      ]
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "REPLACE_WITH_CHILD_WORKFLOW_ID",
          "mode": "id"
        },
        "options": {}
      },
      "id": "9a1eae21-f174-4125-8bab-d2520dc57883",
      "name": "Try to send",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.2,
      "position": [
        660,
        400
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "6bf6e233-f49a-46eb-9497-93b33afd9246",
              "name": "attempt",
              "value": "={{ $(\"One at a time\").item.json.attempt }}",
              "type": "string"
            },
            {
              "id": "fcac0c52-fffd-4874-916f-7175c73ad718",
              "name": "outcome",
              "value": "={{ $json.error ? \"refused: \" + ($json.error.message || $json.error) : ($json.sent ? \"sent\" : \"not sent: \" + $json.why) }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "8ffd3549-cded-45af-be10-17592fb6a976",
      "name": "What happened",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        880,
        400
      ]
    },
    {
      "parameters": {},
      "id": "f1694c4a-947d-4a9a-b68f-25e7d931d8d2",
      "name": "Done",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        660,
        200
      ]
    }
  ],
  "connections": {
    "Run it": {
      "main": [
        [
          {
            "node": "Attempts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Attempts": {
      "main": [
        [
          {
            "node": "One at a time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "One at a time": {
      "main": [
        [
          {
            "node": "Done",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Try to send",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Try to send": {
      "main": [
        [
          {
            "node": "What happened",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "What happened": {
      "main": [
        [
          {
            "node": "One at a time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
