n8n-io / n8n

Free and source-available fair-code licensed workflow automation tool. Easily automate tasks across different services.
https://n8n.io
Other
47.61k stars 7.23k forks source link

Affinity trigger is ran but throws `Unknown API endpoint` #11425

Open geraldyeo opened 4 hours ago

geraldyeo commented 4 hours ago

Bug Description

I have an Affinity trigger node in a workflow to monitor field_value.updated event. Credential used is API key.

I tested the step and used Postman to GET https://api.affinity.co/webhook to verify the subscription:

[
    {
        "id": 20209,
        "webhook_url": "https://januarycapital.app.n8n.cloud/webhook-test/e74627bf-b2fd-4348-8c03-0e752fe687c5/webhook",
        "subscriptions": [
            "field_value.updated"
        ],
        "created_by": 67303684,
        "updated_at": null,
        "disabled": false
    }
]

I then went to Affinity CRM to change/update one of the fields (Status) and in my workflow, the Affinity webhook was triggered but ran into an error:

{
  "errorMessage": "The resource you are requesting could not be found",
  "errorDescription": "Unknown API endpoint",
  "errorDetails": {
    "rawErrorMessage": [
      "404 - \"Unknown API endpoint\""
    ],
    "httpCode": "404"
  },
  "n8nDetails": {
    "nodeName": "Field Value Changes",
    "nodeType": "n8n-nodes-base.affinityTrigger",
    "nodeVersion": 1,
    "time": "26/10/2024, 08:51:55",
    "n8nVersion": "1.63.4 (Cloud)",
    "binaryDataMode": "filesystem",
    "stackTrace": [
      "NodeApiError: The resource you are requesting could not be found",
      "    at Object.affinityApiRequest (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Affinity/GenericFunctions.js:34:15)",
      "    at processTicksAndRejections (node:internal/process/task_queues:95:5)",
      "    at Object.webhook (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Affinity/AffinityTrigger.node.js:207:28)",
      "    at Workflow.runWebhook (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:660:15)",
      "    at Object.executeWebhook (/usr/local/lib/node_modules/n8n/dist/webhooks/webhook-helpers.js:127:33)",
      "    at /usr/local/lib/node_modules/n8n/dist/webhooks/test-webhooks.js:99:37"
    ]
  }
}

The error seems to stem from affinityApiRequest not being able to call the uri formatted from ${endpoint}/${mapResource(resource)}/${id}.

In my own troubleshooting using the n8n repo, I'm guessing in the method mapResource of file /n8n/packages/nodes-base/nodes/Affinity/GenericFunctions.ts, the mapping didn't have the other Affinity resources?

export function mapResource(key: string) {
    //@ts-ignore
    return {
        person: 'persons',
        list: 'lists',
        note: 'notes',
        organization: 'organizatitons',
        list_entry: 'list-entries',
        field: 'fields',
        file: 'files',

        /* probably missing? */
        field_values: 'field-values',
        field_value_changes: 'field-value-changes',
        // ...etc
    }[key];
}

To Reproduce

  1. Add an Affinity trigger node
  2. Listen for the event field_value.updated
  3. Trigger a field value change in Affinity CRM
  4. Error shown in workflow

Expected behavior

I'd expect the trigger node to show the payload for Affinity's field value change.

Operating System

n8n Cloud

n8n Version

1.63.4

Node.js Version

1

Database

SQLite (default)

Execution mode

main (default)

Joffcom commented 4 hours ago

Hey @geraldyeo,

We have created an internal ticket to look into this which we will be tracking as "GHC-353"

geraldyeo commented 4 hours ago

Additional context: The field value change monitoring works in our Zapier zaps, so I know my API key credential is working.