{
  "name": "ig-token-refresh",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 3 * * *"
            }
          ]
        }
      },
      "id": "trigger",
      "name": "Daily @ 03:00 UTC",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        200,
        320
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "https://graph.instagram.com/refresh_access_token",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "grant_type",
              "value": "ig_refresh_token"
            }
          ]
        },
        "options": {}
      },
      "id": "refresh",
      "name": "Refresh IG token",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        320
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Log the new token + expiry. n8n credentials are NOT updatable via REST API\n// on most self-hosted instances without admin PAT, so this just emits a log.\n// You can wire a Slack / Email node below to notify you when the expiry is <14d.\n\nconst { access_token, token_type, expires_in } = $json;\nconst expiresInDays = Math.round((expires_in || 0) / 86400);\nreturn {\n  json: {\n    notice: 'New long-lived IG token issued. Paste it back into the `IG Login - Leo Luis` credential manually.',\n    expires_in_days: expiresInDays,\n    new_token_preview: (access_token || '').slice(0, 12) + '\u2026',\n  },\n};\n"
      },
      "id": "log",
      "name": "Log new token",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        700,
        320
      ]
    }
  ],
  "connections": {
    "Daily @ 03:00 UTC": {
      "main": [
        [
          {
            "node": "Refresh IG token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Refresh IG token": {
      "main": [
        [
          {
            "node": "Log new token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false,
  "versionId": "refresh-v1",
  "triggerCount": 0
}