{
  "name": "Postmark - Transactional Email With Error Codes",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "postmark-send",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "tpl-hook",
      "name": "Order paid (webhook)",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// Postmark wants one flat JSON object, so build it here and leave the HTTP Request generic.\nconst o = $json.body ?? $json;\nreturn [{ json: { email: {\n  From: 'receipts@example.com',\n  To: o.email,\n  Subject: 'Your receipt for order ' + o.order_id,\n  TextBody: 'Thanks for your order ' + o.order_id + '. Total: ' + o.total + '.',\n  MessageStream: 'outbound',\n} } }];"
      },
      "id": "tpl-build",
      "name": "Build the email",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.postmarkapp.com/email",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "postmarkApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json.email) }}",
        "options": {
          "response": {
            "response": {
              "neverError": true,
              "fullResponse": true
            }
          }
        }
      },
      "id": "tpl-send",
      "name": "Send via Postmark",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        0
      ],
      "onError": "stopWorkflow"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "version": 2,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "ok",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{ $json.statusCode }}",
              "rightValue": 300
            }
          ]
        },
        "options": {}
      },
      "id": "tpl-if",
      "name": "Accepted?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        660,
        0
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ sent: true, messageId: $json.body.MessageID }) }}",
        "options": {}
      },
      "id": "tpl-ok",
      "name": "Sent",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        880,
        -100
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "options": {
          "responseCode": 502
        },
        "responseBody": "={{ JSON.stringify({ sent: false, postmarkErrorCode: $json.body.ErrorCode, message: $json.body.Message }) }}"
      },
      "id": "tpl-no",
      "name": "Rejected by Postmark",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        880,
        100
      ]
    },
    {
      "parameters": {
        "content": "## Postmark - Transactional Email With Error Codes\n\n**Before you run it**\n1. Credentials -> New -> **Postmark API**, and paste your Server API Token.\n   To try it without an account, paste `POSTMARK_API_TEST`. Postmark validates the request and\n   delivers nothing. The credential's own connection test will FAIL on that token - it calls\n   `GET /server`, which the sandbox token may not touch. Save it anyway; sends work. Then open **Send via Postmark** and select that saved credential in the Postmark API credential picker. The download has no saved credential binding.\n2. Edit the **From** address in *Build the email* to a confirmed sender signature.\n\n**Why the HTTP Request node.** n8n ships a Postmark *Trigger* but no Postmark send node.\nAuthentication is still set to **Predefined Credential Type -> Postmark API**, so the token\nstays in the credential store instead of being pasted into a header.\n\n**Why Never Error is on.** With the default settings a 422 from Postmark reaches the error\noutput as n8n's own error object, and **`ErrorCode` and the HTTP status are both discarded**.\nNever Error + full response keeps `body.ErrorCode` and `statusCode`, which is what *Accepted?*\nbranches on. That is also why the *Accepted?* check is not optional: without it a rejected\nemail looks exactly like a sent one.\n\nGuide: https://noderecipe.com/n8n-postmark-email",
        "height": 520,
        "width": 560
      },
      "id": "tpl-note",
      "name": "Read me first",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -620,
        -160
      ]
    }
  ],
  "connections": {
    "Order paid (webhook)": {
      "main": [
        [
          {
            "node": "Build the email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build the email": {
      "main": [
        [
          {
            "node": "Send via Postmark",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send via Postmark": {
      "main": [
        [
          {
            "node": "Accepted?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Accepted?": {
      "main": [
        [
          {
            "node": "Sent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Rejected by Postmark",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}
