{
  "id": "kT7maZy0kXONDFM8",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Credential Overwrites",
  "tags": [],
  "nodes": [
    {
      "id": "38224819-9902-49fb-aae9-865cb1433749",
      "name": "When clicking \"Test Workflow\"",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        592,
        -80
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "9283b408-e4ba-4324-bf25-56c5ee48c1e2",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        528,
        -624
      ],
      "parameters": {
        "color": 7,
        "width": 656,
        "height": 720,
        "content": "# Step 2 - Get Credential Schemas\nGet the schema of your credentials. \nThe \"schema\" just means the way the data / JSON is laid out. \n\n1. Enter your n8n base URL in the `ADD HERE` node\n2. Enter your credential name you need in the `ADD HERE` node\n3. In the n8n settings (`/settings/api`) create an n8n api key with at least read permissions\n4. Add the API key from step 3 as an n8n credential in node `Get Credential Schema`\n\n\n### How to find credential name?\nGo [here](https://github.com/n8n-io/n8n/tree/8cd75d2f2dae70820079fbdc99fe2ad83e048cad/packages/nodes-base/credentials) on GitHub and find the credential file you want to make an overwrite for. \n_note: you can make overwrites on community nodes too, but you need to find the GitHub repo where they are tracked_\n\n\nThen find the name field right at the start of the class, like shown here in the [ToDoist credential](https://github.com/n8n-io/n8n/blob/8cd75d2f2dae70820079fbdc99fe2ad83e048cad/packages/nodes-base/credentials/TodoistOAuth2Api.credentials.ts#L4): `name = 'todoistOAuth2Api';` and \"todoistOAuth2Api\" will be the credential type name\n"
      },
      "typeVersion": 1
    },
    {
      "id": "76140220-6c3b-4e4b-b480-bb0088959e8e",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -928,
        -624
      ],
      "parameters": {
        "width": 784,
        "height": 944,
        "content": "# Credential Overwrites\n\n\n## How it works\n\nLike the name suggests, you are overwriting the fields in the credential forms \nThat means you can set credential defaults _(that can not be changed by the users in n8n)_ \n\n\n## When to use\n### Simplify Oauth Credentials to a One Click Connect\nFor Oauth applications where only one registered client ID is needed. \n\nGoogle is a perfect example where only one client ID needs to be registered. Google is also a great candidate for overwrites because _almost all_ Google credentials in n8n inherits the single `googleOAuth2Api` credential type. \n\nThat means adding a credential overwrite for `googleOAuth2Api`, Gmail, Drive, Sheets, and almost every other Google n8n credential will inherit the client ID and client secret, you just get a \"Connect with Google\" button.  \n\n --\n\n### Set default values for fields that don't change\nYou can also overwrite other fields, like `baseUrl`. I have done this in the past with Atlassian credentials. \nIf you need to use another base url for any reason, you will no longer have that field available to you to change in n8n.\n\n\n## When not to use\nWhen you need the value to be more than one field. For example, if you have multiple registered GitHub apps using Oauth, if you add an overwrite, you will no longer be able to specify client ID or secret. \n"
      },
      "typeVersion": 1
    },
    {
      "id": "929622b6-075b-46a9-8ea8-d2863f742b06",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -96,
        -624
      ],
      "parameters": {
        "color": 7,
        "width": 592,
        "height": 720,
        "content": "# Step 1 - Add Environment Variable\n\n#### \u26a0\ufe0f Credential overwrite only work on self hosted instances\n\nIn your deployment configuration, add the environment variable:\n```\nCREDENTIALS_OVERWRITE_ENDPOINT=creds-overwrite\n```\n_the value can be anything, but keep `creds-overwrite` so the template works as expected_\n\n\n### Docs for more details:\n- [n8n docker docs](https://docs.n8n.io/hosting/installation/docker/)\n- [n8n credential overwrites docs](https://docs.n8n.io/administer/manage-credentials/credential-overwrites#using-the-rest-api)\n- [n8n environment variable docs](https://docs.n8n.io/hosting/configuration/environment-variables/)\n\n_if you are running queue mode, you also need to set `CREDENTIALS_OVERWRITE_PERSISTENCE=true`. [Read the docs for more info](https://docs.n8n.io/administer/manage-credentials/credential-overwrites#persistence)._"
      },
      "typeVersion": 1
    },
    {
      "id": "9b822cd8-3675-4482-9618-e102909aee81",
      "name": "Register Overwrites",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1632,
        304
      ],
      "parameters": {
        "url": "http://localhost:5678/creds-overwrite",
        "method": "POST",
        "options": {},
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpCustomAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {
        "httpCustomAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "3dded015-9e57-4e5d-a54a-11542f39ff9c",
      "name": "When n8n Starts",
      "type": "n8n-nodes-base.n8nTrigger",
      "position": [
        1360,
        304
      ],
      "parameters": {
        "events": [
          "init"
        ]
      },
      "typeVersion": 1
    },
    {
      "id": "79278a1b-f6f2-4af1-8653-9f7c78ccb926",
      "name": "Get Credential Schema",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        992,
        -80
      ],
      "parameters": {
        "url": "=http://localhost:5678/api/v1/credentials/schema/{{ $json.credentialType }}",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "n8nApi"
      },
      "credentials": {
        "n8nApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.1
    },
    {
      "id": "5c1f53dd-e5a7-4dda-90d4-106875d61a71",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1216,
        -624
      ],
      "parameters": {
        "color": 7,
        "width": 656,
        "height": 1088,
        "content": "# Step 3 - Set Credential Value\nNow that we have the credential schemas, we can construct the actual request to set the overwrites. On every single n8n startup, this sends an http request to the `/creds-overwrite` endpoint we enabled in step 1.\n\nThese values are secrets, just like passwords, so we set the credential values in a custom auth credential.\n\n1. Using the format of the code block below, add the fields you want to overwrite from the schema under the credential name. \n2. Put this value in the custom auth credential in the `Register Overwrites` node. Ensure it's not in plain text anywhere and only set in the credential.\n3. Publish the workflow. On the next instance restart, the overwrites will be set. _(Do not unpublish the workflow, it needs to run on every startup)_\n\n_note: you can have an LLM assist you with the formatting, but DO NOT paste your api keys into an AI chat_\n\n\n```\n{\n  \"body\": {\n    \"googleOAuth2Api\": {\n      \"clientId\": \"***\",\n      \"clientSecret\": \"***\"\n    },\n    \"todoistOAuth2Api\": {\n      \"serverUrl\": \"***\",\n      \"clientId\": \"***\",\n      \"clientSecret\": \"***\",\n      \"sendAdditionalBodyProperties\": \"***\"\n    }\n  }\n}\n```\n\nThese nodes are what does the actual work. Keep the workflow published so it can run on every start up"
      },
      "typeVersion": 1
    },
    {
      "id": "933da8c0-2676-4320-844b-f9cd339556f6",
      "name": "ADD HERE",
      "type": "n8n-nodes-base.set",
      "position": [
        800,
        -80
      ],
      "parameters": {
        "fields": {
          "values": [
            {
              "name": "credentialType"
            },
            {
              "name": "baseUrl"
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "c659fac3-8ae2-47a1-9690-b46ec3267ea0",
  "nodeGroups": [],
  "connections": {
    "ADD HERE": {
      "main": [
        [
          {
            "node": "Get Credential Schema",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When n8n Starts": {
      "main": [
        [
          {
            "node": "Register Overwrites",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \"Test Workflow\"": {
      "main": [
        [
          {
            "node": "ADD HERE",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}