Skip to main content
Glama

n8n_create_credential

Store API credentials for services like GitHub, Slack, or databases in n8n. Provide credential type, name, and authentication data to enable workflow connections.

Instructions

Store new API credentials for services like GitHub, Slack, or databases. Provide credential type, descriptive name, and authentication data. Use get_credential_schema first to see required fields for each type.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesDescriptive name (e.g., "Production GitHub Token")
typeYesCredential type from get_credential_schema (e.g., githubApi, slackApi)
dataYesAuthentication data (API keys, OAuth tokens, passwords)

Implementation Reference

  • The createCredential method in N8nClient class is the actual handler that executes the tool logic. It makes a POST request to the n8n API endpoint /api/v1/credentials with the credential data as JSON body.
    async createCredential(credential: any) {
      return this.request(`${this.apiBase}/credentials`, {
        method: 'POST',
        body: JSON.stringify(credential),
      });
    }
  • Tool schema definition for n8n_create_credential. Defines the tool name, description, inputSchema with required properties (name, type, data), and annotations including title 'Create Credential'.
    {
      name: 'n8n_create_credential',
      description: 'Store new API credentials for services like GitHub, Slack, or databases. Provide credential type, descriptive name, and authentication data. Use get_credential_schema first to see required fields for each type.',
      inputSchema: {
        type: 'object',
        properties: {
          name: { type: 'string', description: 'Descriptive name (e.g., "Production GitHub Token")' },
          type: { type: 'string', description: 'Credential type from get_credential_schema (e.g., githubApi, slackApi)' },
          data: { type: 'object', description: 'Authentication data (API keys, OAuth tokens, passwords)' },
        },
        required: ['name', 'type', 'data'],
      },
      annotations: {
        title: 'Create Credential',
        readOnlyHint: false,
        destructiveHint: false,
        idempotentHint: false,
        openWorldHint: true,
      },
    },
  • src/server.ts:57-58 (registration)
    Registration of the tool handler in the handleToolCall function. Routes 'n8n_create_credential' tool calls to client.createCredential(args).
    case 'n8n_create_credential':
      return client.createCredential(args);
  • The private request method is a helper utility that handles authenticated API calls to n8n. It adds the X-N8N-API-KEY header, sets Content-Type, handles timeouts, and throws errors for non-OK responses.
    private async request<T>(
      endpoint: string,
      options: RequestInit = {}
    ): Promise<T> {
      const url = `${this.config.apiUrl}${endpoint}`;
    
      const response = await fetch(url, {
        ...options,
        signal: AbortSignal.timeout(this.timeout),
        headers: {
          'X-N8N-API-KEY': this.config.apiKey,
          'Content-Type': 'application/json',
          ...options.headers,
        },
      });
    
      if (!response.ok) {
        const error = await response.text();
        throw new Error(`n8n API Error (${response.status}): ${error}`);
      }
    
      return response.json() as Promise<T>;
    }
  • TypeScript interface N8nCredential defines the structure of credential objects with id, name, type, data, createdAt, and updatedAt fields.
    export interface N8nCredential {
      id: string;
      name: string;
      type: string;
      data?: any;
      createdAt: string;
      updatedAt: string;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/node2flow-th/n8n-management-mcp-community'

If you have feedback or need assistance with the MCP directory API, please join our Discord server