Skip to main content
Glama

QuickBooks Online MCP Server

by heyibad
create-quickbooks-account.handler.ts3.36 kB
import { makeQuickBooksRequest, queryQuickBooks, extractAccessToken, } from "../helpers/quickbooks-api.js"; import { getRequestHeaders } from "../helpers/request-context.js"; import { ToolResponse } from "../types/tool-response.js"; import { formatError } from "../helpers/format-error.js"; export interface CreateAccountInput { name: string; type: string; // e.g., Expense, Income, Bank, etc. sub_type?: string; description?: string; } // Helper to normalize field values to the correct data type expected by Quickbooks const accountFieldTypeMap: Record<string, "string" | "boolean" | "number"> = { Name: "string", AccountType: "string", AccountSubType: "string", Description: "string", Classification: "string", Active: "boolean", SubAccount: "boolean", ParentRef: "string", CurrentBalance: "number", }; function normalizeAccountPayload( payload: Record<string, any> ): Record<string, any> { const normalized: Record<string, any> = {}; Object.entries(payload).forEach(([key, value]) => { if (value === undefined || value === null) return; // skip undefined const expectedType = accountFieldTypeMap[key]; if (!expectedType) { // passthrough unknown keys without modification normalized[key] = value; return; } switch (expectedType) { case "string": normalized[key] = String(value); break; case "boolean": normalized[key] = typeof value === "boolean" ? value : value === "true"; break; case "number": normalized[key] = typeof value === "number" ? value : Number(value); break; default: normalized[key] = value; } }); return normalized; } export async function createQuickbooksAccount( data: CreateAccountInput ): Promise<ToolResponse<any>> { try { // Get access token from request headers const headers = getRequestHeaders(); const accessToken = extractAccessToken(headers); if (!accessToken) { return { result: null, isError: true, error: "Missing Authorization header. Please provide: Authorization: Bearer <access_token>", }; } // Build initial payload then normalize. const basePayload: any = { Name: data.name, AccountType: data.type, AccountSubType: data.sub_type, Description: data.description, }; const payload = normalizeAccountPayload(basePayload); const response = await makeQuickBooksRequest({ method: "POST", endpoint: "/account", body: payload, accessToken, }); if (response.isError) { return { result: null, isError: true, error: response.error || "Failed to create account", }; } return { result: response.result?.Account, isError: false, error: null, }; } catch (error) { return { result: null, isError: true, error: formatError(error) }; } }

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/heyibad/quickbook-mcp-'

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