b24_crm_create
Create CRM records such as deals, contacts, companies, leads, quotes, or SPA items using specified fields and optional parameters.
Instructions
Crea un nuevo registro CRM: deal, contact, company, lead, cotización, o item de SPA.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| entity | No | ||
| entity_type_id | No | ||
| fields | Yes | Campos del registro a crear. Ejemplo: { "TITLE": "Nuevo deal", "STAGE_ID": "NEW", "ASSIGNED_BY_ID": 1 } | |
| params | No | Parámetros adicionales del método (ej: REGISTER_SONET_EVENT) | |
| webhook_url | No |
Implementation Reference
- index.js:117-119 (registration)Registration of the 'b24_crm_create' tool with the MCP server, binding schema (crmCreateSchema) and handler (crmCreate) via wrap().
server.tool('b24_crm_create', 'Crea un nuevo registro CRM: deal, contact, company, lead, cotización, o item de SPA.', crmCreateSchema.shape, wrap(crmCreate)); - src/tools/crm.js:71-77 (schema)Zod schema for input validation: optional entity string, optional entity_type_id int, required fields record, optional params record, optional webhook_url.
export const crmCreateSchema = z.object({ entity: z.string().optional(), entity_type_id: z.number().int().optional(), fields: z.record(z.any()).describe('Campos del registro a crear. Ejemplo: { "TITLE": "Nuevo deal", "STAGE_ID": "NEW", "ASSIGNED_BY_ID": 1 }'), params: z.record(z.any()).optional().describe('Parámetros adicionales del método (ej: REGISTER_SONET_EVENT)'), webhook_url: z.string().url().optional(), }); - src/tools/crm.js:79-85 (handler)The main handler function. Resolves the webhook, determines the CRM method base, calls the Bitrix24 REST API '{base}.add' with fields, and returns the created record ID.
export async function crmCreate({ entity, entity_type_id, fields, params = {}, webhook_url }) { const client = new Bitrix24Client(resolveWebhook(webhook_url)); const { base, extra } = resolveMethod(entity, entity_type_id); const res = await client.call(`${base}.add`, { fields: { ...fields, ...extra }, params }); const id = res.result?.item?.id ?? res.result; return { entity: entity || `SPA_${entity_type_id}`, portal: client.portal, created_id: id }; } - src/tools/crm.js:18-23 (helper)Helper function 'resolveMethod' that maps entity names to REST method bases (e.g., 'crm.deal') or uses 'crm.item' for SPA entities via entityTypeId.
function resolveMethod(entity, entityTypeId) { if (entityTypeId) return { base: 'crm.item', extra: { entityTypeId } }; const base = ENTITY_METHOD[entity?.toLowerCase()]; if (!base) throw new Error(`Entidad desconocida: "${entity}". Usá deal, contact, company, lead, quote, invoice, o pasá entityTypeId para SPA.`); return { base, extra: {} }; } - src/utils/resolve-webhook.js:1-10 (helper)Resolves the webhook URL from the provided parameter or falls back to the B24_DEFAULT_WEBHOOK environment variable.
export function resolveWebhook(webhookParam) { const url = webhookParam || process.env.B24_DEFAULT_WEBHOOK; if (!url) { throw new Error( 'No se especificó webhook_url y no hay B24_DEFAULT_WEBHOOK configurado. ' + 'Indicá el webhook en el parámetro webhook_url o configuralo en el servidor MCP.' ); } return url; }