{
  "name": "Workflow D \u2014 Target URL Sync",
  "nodes": [
    {
      "parameters": {
        "content": "## Workflow D \u2014 Target URL Sync\n\n**Trigger:** POST /webhook/update-target\n\n**Purpose:** Updates the monitored target URL. Saves to the targets table in Supabase and notifies Discord.\n\n**Flow:**\nWebhook (POST /update-target) \u2192 Validate URL (Code \u2014 checks url present, sets name) \u2192 Save to Supabase (Postgres insert into targets, active=true) \u2192 Notify Discord \u2192 Respond { updated: true }\n\n**Supabase targets table:** Stores url, name, set_at, active. Dashboard reads active=true row to show current target.\n\n**Called by:** Dashboard Control page \u2192 api.js setTarget() \u2014 first PATCHes active=false on old targets, then POSTs new target directly to Supabase. This webhook is an additional sync path for external callers.\n\n**Direct webhook URL:** POST https://n8n-j39n.sliplane.app/webhook/update-target\n**Body:** { \"url\": \"https://...\", \"name\": \"Display Name\" }"
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -200,
        100
      ],
      "id": "sticky-d",
      "name": "Sticky Note \u2014 Workflow D"
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "update-target",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "a365a2b9-1117-40ba-9db8-a48a5a1819b2",
      "name": "Target webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const { url, name } = $input.first().json.body;\nif (!url) throw new Error('url is required');\nreturn [{ json: { url, name: name || url } }];"
      },
      "id": "165965a4-4279-4ea4-accb-0e650467735d",
      "name": "Validate URL",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "table": {
          "__rl": true,
          "value": "targets",
          "mode": "list",
          "cachedResultName": "targets"
        },
        "dataMode": "defineBelow",
        "valuesToSend": {
          "values": [
            {
              "column": "url",
              "value": "={{ $json.url }}"
            },
            {
              "column": "name",
              "value": "={{ $json.name }}"
            },
            {
              "column": "set_at",
              "value": "={{ new Date().toISOString() }}"
            },
            {
              "column": "active",
              "value": "true"
            }
          ]
        },
        "options": {}
      },
      "id": "d43fed26-e228-4197-b12b-c0225b5ade60",
      "name": "Save to Supabase",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2,
      "position": [
        680,
        300
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "message",
        "guildId": {
          "__rl": true,
          "value": "1066890817425387581",
          "mode": "id"
        },
        "channelId": {
          "__rl": true,
          "value": "1514424075282550916",
          "mode": "list",
          "cachedResultName": "gamers-lab-monitor"
        },
        "content": "=\ud83c\udfaf Monitor target updated\nURL: {{ $json.url }}\nName: {{ $json.name }}",
        "options": {}
      },
      "id": "b924cc92-ef39-42ba-b7e2-5896824aec6e",
      "name": "Notify Discord",
      "type": "n8n-nodes-base.discord",
      "typeVersion": 2,
      "position": [
        900,
        300
      ],
      "credentials": {
        "discordBotApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"updated\": true }",
        "options": {}
      },
      "id": "f888258d-557d-4067-93f2-fb29f96faa52",
      "name": "Respond1",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1100,
        300
      ]
    }
  ],
  "connections": {
    "Target webhook": {
      "main": [
        [
          {
            "node": "Validate URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate URL": {
      "main": [
        [
          {
            "node": "Save to Supabase",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save to Supabase": {
      "main": [
        [
          {
            "node": "Notify Discord",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notify Discord": {
      "main": [
        [
          {
            "node": "Respond1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}