update_lead
Modify lead details in your sales pipeline including status, value, notes, and next actions to maintain accurate revenue tracking and follow-up scheduling.
Instructions
Update an existing lead
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| estimatedValue | No | ||
| leadId | Yes | Lead ID to update | |
| nextAction | No | ||
| nextActionDate | No | YYYY-MM-DD | |
| notes | No | ||
| status | No |
Implementation Reference
- index.js:642-644 (handler)Handler execution for the update_lead tool. Delegates to callAPI helper function with action 'updateLead' and tool arguments.case "update_lead": result = await callAPI("updateLead", args); break;
- index.js:200-214 (schema)Input schema/validation for update_lead tool defining parameters such as leadId (required), status enum, estimatedValue, notes, nextAction, and nextActionDate.inputSchema: { type: "object", properties: { leadId: { type: "number", description: "Lead ID to update" }, status: { type: "string", enum: ["New", "Contacted", "Call Booked", "Proposal Sent", "Closed", "Lost"] }, estimatedValue: { type: "number" }, notes: { type: "string" }, nextAction: { type: "string" }, nextActionDate: { type: "string", description: "YYYY-MM-DD" }, }, required: ["leadId"], },
- index.js:197-215 (registration)Registration of the update_lead tool in the tools list returned by the ListToolsRequestSchema handler.{ name: "update_lead", description: "Update an existing lead", inputSchema: { type: "object", properties: { leadId: { type: "number", description: "Lead ID to update" }, status: { type: "string", enum: ["New", "Contacted", "Call Booked", "Proposal Sent", "Closed", "Lost"] }, estimatedValue: { type: "number" }, notes: { type: "string" }, nextAction: { type: "string" }, nextActionDate: { type: "string", description: "YYYY-MM-DD" }, }, required: ["leadId"], }, },
- index.js:74-131 (helper)Shared helper function callAPI that performs HTTP POST to the Google Apps Script backend (API_URL) with form-encoded action and data, handles logging, error checking, and JSON parsing. This is invoked by the update_lead handler.async function callAPI(action, data = {}) { debugLog('=== API CALL START ==='); debugLog(`Action: ${action}`); debugLog(`Data: ${JSON.stringify(data)}`); try { // Build form-encoded body for POST const formData = new URLSearchParams(); formData.append('action', action); // Add all data fields to form for (const [key, value] of Object.entries(data)) { if (value !== undefined && value !== null) { formData.append(key, value.toString()); } } const formString = formData.toString(); debugLog(`FormData: ${formString}`); debugLog(`API_URL: ${API_URL}`); // Use POST with proper content type const response = await fetch(API_URL, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: formString }); debugLog(`Response status: ${response.status}`); debugLog(`Response ok: ${response.ok}`); if (!response.ok) { debugLog(`Response not OK: ${response.status} ${response.statusText}`); throw new Error(`API request failed: ${response.status} ${response.statusText}`); } const text = await response.text(); debugLog(`Response text length: ${text.length}`); debugLog(`Response text: ${text}`); if (!text) { debugLog('ERROR: Empty response from API'); throw new Error('Empty response from API'); } const parsed = JSON.parse(text); debugLog(`Parsed successfully: ${JSON.stringify(parsed)}`); debugLog('=== API CALL END ==='); return parsed; } catch (error) { debugLog(`ERROR in callAPI: ${error.message}`); debugLog(`ERROR stack: ${error.stack}`); throw error; } }