Skip to main content
Glama

sale_create

Create a new sale transaction in a POS system by specifying payment method and items, which can be catalog products, department items, or custom entries, while optionally linking to an existing customer.

Instructions

Crée une nouvelle vente pour l'établissement. Prend en entrée le mode de paiement (optionnel) et la liste des articles. Chaque article peut être du type « catalogue » (avec productId) ou « rayon » (avec deptId) ou « libre » (avec titre et prix). Vérifier si le client n'existe déjà en utilisant data_list_clients et si le client existe, uniquement préciser idClient. Retourne un objet JSON de confirmation de la vente tel que fourni par l’API distante.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paymentNo
deliveryMethodNo
idtableNo
idcaisseNo
numcouvertsNo
publicCommentNo
privateCommentNo
pagerNumNo
idUserNo
idClientNo
clientNo
itemsYes

Implementation Reference

  • The handler function for the sale_create tool that processes input, builds legacy API request body, encodes items list, calls postForm to /workers/webapp.php, and returns the response.
    async (input: SalesCreateArgs, ctx: Ctx) => { const { shopId, apiKey } = resolveAuth(undefined, ctx); // ---------- Mode legacy ---------- const body: Record<string, unknown> = { idboutique: shopId, key: apiKey }; if (input.payment !== undefined) body.payment = input.payment; if (input.deliveryMethod !== undefined) body.deliveryMethod = String(input.deliveryMethod); if (input.idUser !== undefined) body.idUser = input.idUser; if (input.idtable !== undefined) body.idtable = input.idtable; if (input.idcaisse !== undefined) body.idcaisse = input.idcaisse; if (input.numcouverts !== undefined) body.numcouverts = input.numcouverts; if (input.publicComment !== undefined) body.publicComment = input.publicComment; if (input.privateComment !== undefined) body.privateComment = input.privateComment; if (input.pagerNum !== undefined) body.pagerNum = input.pagerNum; if (input.idClient !== undefined) body.idClient = input.idClient; if (!input.idClient && input.client) { // Le legacy aime les clés client[...] for (const [k, v] of Object.entries(input.client)) { if (v !== undefined && v !== null && v !== '') { body[`client[${k}]`] = String(v); } } } body['itemsList[]'] = encodeItemsList(input.items); const data = await postForm('/workers/webapp.php', body); return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }], structuredContent: data, }; }
  • Zod input schema (SalesCreateShape) for the sale_create tool, defining parameters like payment, deliveryMethod, client details, and items array. References ClientShape and SalesItemShape.
    const SalesCreateShape = { payment: z.union([z.number(), z.string()]).transform((v) => Number(v)).optional(), deliveryMethod: z.union([ z.number().int().min(0).max(6), z.enum(['0','1','2','3','4','5','6']) ]).transform((v) => Number(v)).optional(), idtable: z.union([z.number().int(), z.string()]).optional(), idcaisse: z.union([z.number().int(), z.string()]).optional(), numcouverts: z.union([z.number().int(), z.string()]).optional(), publicComment: z.string().optional(), privateComment: z.string().optional(), pagerNum: z.union([z.number().int(), z.string()]).optional(), idUser: z.union([z.number().int(), z.string()]).optional(), idClient: z.union([z.number().int(), z.string()]).optional(), client: z.object(ClientShape).partial().optional(), items: z.array(z.object(SalesItemShape)).min(1), } satisfies Record<string, ZodTypeAny>;
  • MCP server registration of the sale_create tool within registerSalesTools, specifying name, i18n title/description, input schema, and handler function.
    server.registerTool( 'sale_create', { title: t('tools.sale_create.title'), description: t('tools.sale_create.description'), inputSchema: SalesCreateShape, // ✅ ZodRawShape }, async (input: SalesCreateArgs, ctx: Ctx) => { const { shopId, apiKey } = resolveAuth(undefined, ctx); // ---------- Mode legacy ---------- const body: Record<string, unknown> = { idboutique: shopId, key: apiKey }; if (input.payment !== undefined) body.payment = input.payment; if (input.deliveryMethod !== undefined) body.deliveryMethod = String(input.deliveryMethod); if (input.idUser !== undefined) body.idUser = input.idUser; if (input.idtable !== undefined) body.idtable = input.idtable; if (input.idcaisse !== undefined) body.idcaisse = input.idcaisse; if (input.numcouverts !== undefined) body.numcouverts = input.numcouverts; if (input.publicComment !== undefined) body.publicComment = input.publicComment; if (input.privateComment !== undefined) body.privateComment = input.privateComment; if (input.pagerNum !== undefined) body.pagerNum = input.pagerNum; if (input.idClient !== undefined) body.idClient = input.idClient; if (!input.idClient && input.client) { // Le legacy aime les clés client[...] for (const [k, v] of Object.entries(input.client)) { if (v !== undefined && v !== null && v !== '') { body[`client[${k}]`] = String(v); } } } body['itemsList[]'] = encodeItemsList(input.items); const data = await postForm('/workers/webapp.php', body); return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }], structuredContent: data, }; } );
  • Helper function to encode the items array into the legacy 'itemsList[]' string format required by the API.
    function encodeItemsList(items: SalesCreateArgs['items']): string[] { const out: string[] = []; for (const it of items) { if (it.type === 'catalog') { const parts = [ it.productId ?? '', it.quantity ?? 1, it.titleOverride ?? '', it.priceOverride ?? '', ]; if (it.declinaisons?.length) parts.push(...it.declinaisons); out.push(parts.join('_')); } else if (it.type === 'free') { const parts = [ 'Free', it.priceOverride ?? '', it.titleOverride ?? '', ]; out.push(parts.join('_')); } else { // ligne libre : -<departmentId>_<price>_<title> out.push(`-${it.departmentId ?? ''}_${it.price ?? ''}_${it.title ?? ''}`); } } return out; }
  • src/index.ts:61-61 (registration)
    Invocation of registerSalesTools to register sale tools including sale_create in the main MCP server setup.
    registerSalesTools(mcpServer);

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/paracetamol951/caisse-enregistreuse-mcp-server'

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