Log http request

I am getting an error with custom HTTP Requests using Oauth2 authentication:

ERROR: The client is not authorized to request an authorization code using this method.
Error: The client is not authorized to request an authorization code using this method.
at getAuthError (/usr/local/lib/node_modules/n8n/node_modules/client-oauth2/src/client-oauth2.js:122:15)
at /usr/local/lib/node_modules/n8n/node_modules/client-oauth2/src/client-oauth2.js:270:21
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/NodeExecuteFunctions.js:78:30
at async Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/HttpRequest.node.js:749:32)
at async /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/WorkflowExecute.js:369:47

I reported this error to the service we are using (Exact Online), but they are asking me for request logs (which I can understand). I tried to catch the requests on my localhost (Mac) using mitmproxy, but for some reason that is not working.

Is there another way to log http requests so I can send debug information to Exact?

1 Like

since we are using this module request-promise - npm to do the requests you can set an env variable NODE_DEBUG=request and you should be able to see all the request are being made on the terminal.

2 Likes

Thanks! That works for the HTTP requests, but unfortunately the OAuth2 requests are not logged. Can you give me a hint for those as well?

Hi @RicardoE105 , I am digging this post from the graveyard but I find the issue of logging HTTP request relevant as a I hit a bug with a connector that could only be debugged by observing the request ( Google Calendar node fails with Luxon-formatted date from Google Sheets (works with hardcoded string) - #4 by jabbson ).

Is your answer with request-promise still valid? The logging documentation only mentions winston but winston is an app-level log, I couldn’t find a source for the “NODE_DEBUG” environment variable.

Up: I’ve explored n8n current codebase and it uses Axios. Axios doesn’t have an environment variable to enable debugging as it doesn’t use the “debug” package.
Instead an interceptor has to be configured, Axios docs lists a few solutions:

* [axios-response-logger](GitHub - srph/axios-response-logger: 📣 Axios interceptor which logs responses) - Axios interceptor which logs responses

* [axios-debug-log](GitHub - Gerhut/axios-debug-log: Axios interceptor of logging request & response with debug library.) - Axios interceptor of logging requests & responses by debug.

* [axios-curlirize](https://www.npmjs.com/package/axios-curlirize) - Logs axios requests as curl commands, also adds a property to the response object with the curl command as value.

However this means contributing to n8n codebase to add this option, since this requires setting up the interceptor when the axios client is created.

The relevant file in the n8n codebase seems to be :
packages/core/src/execution-engine/node-execution-context/utils/request-helper-functions.ts

Legacy HTTP helpers seem to use Winston logger but they barely log anything anyway, and the new HTTP helper doesn’t have any logging included.

Related closed question: Is there a way to inspect the actual http requests in n8n?

It doesn’t provide any acceptable solution though that would be built in n8n.