Tools, Langchain, Agent, HTTP, Payload: How to Dynamically Update Only Specific Fields in Kommo (AmoCRM)?

Hello everyone! I’m building a workflow in n8n to integrate with Kommo (formerly AmoCRM). I need to update only specific fields in a Lead, but my HTTP node is configured to send the same static JSON every time, which overwrites or changes fields that shouldn’t be modified.

Current Scenario:

  • I’m using the Langchain HTTP tool in n8n, pointing to the Kommo endpoint:
    PATCH https://mydomain.kommo.com/api/v4/leads/{lead_id}
  • The request body (jsonBody) looks like this:

json

CopiarEditar

{
  "custom_fields_values": [
    {
      "field_id": 1296075,
      "values": [
        { "value": "2025-10-10" }
      ]
    }
  ]
}
  • This works for updating a single field, but if I want to update multiple fields at once, I either have to make several calls or hard-code multiple fields in the JSON.
  • Using a static JSON causes fields that haven’t changed to be overwritten or filled with empty values.

Goal:

  • Dynamically construct the payload so it only includes the fields actually changed by the user or the workflow (e.g., "data_coleta", "forma_pagamento", etc.), without overwriting the rest.
  • Avoid multiple API calls for each individual field.

Questions / Help Needed:

  1. How do you recommend building the "custom_fields_values" array so it only includes the fields that were actually modified?
  2. Is there an official tutorial or example for using a Function or Set node in n8n to generate this array and pass it to the HTTP node?
  3. Has anyone dealt with a similar challenge and found an elegant way to prevent overwriting fields that remain unchanged?

Any reference materials or workflow examples would be greatly appreciated. Thank you in advance!