I need to send error message to google chat through webhook

I was unable to send the a object that is stringified to the google chat through webhook

below is the input

401 - "{\n  \"error\": {\n    \"code\": 401,\n    \"message\": \"Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.\",\n    \"errors\": [\n      {\n        \"message\": \"Login Required.\",\n        \"domain\": \"global\",\n        \"reason\": \"required\",\n        \"location\": \"Authorization\",\n        \"locationType\": \"header\"\n      }\n    ],\n    \"status\": \"UNAUTHENTICATED\",\n    \"details\": [\n      {\n        \"@type\": \"type.googleapis.com/google.rpc.ErrorInfo\",\n        \"reason\": \"CREDENTIALS_MISSING\",\n        \"domain\": \"googleapis.com\",\n        \"metadata\": {\n          \"method\": \"ccc.hosted.frontend.directory.v1.DirectoryGroups.Get\",\n          \"service\": \"admin.googleapis.com\"\n        }\n      }\n    ]\n  }\n}\n"

my post method for this is

{
  "text":{{ 'name ' + $json.name + ' ' + $json.error.toJsonString() }}
}

when i do this i am getting the below error

{
  "errorMessage": "JSON parameter need to be an valid JSON",
  "errorDetails": {},
  "n8nDetails": {
    "nodeName": "HTTP Request11",
    "nodeType": "n8n-nodes-base.httpRequest",
    "nodeVersion": 4.2,
    "itemIndex": 0,
    "time": "23/10/2024, 23:26:39",
    "n8nVersion": "1.62.1 (Self Hosted)",
    "binaryDataMode": "default",
    "stackTrace": [
      "NodeOperationError: JSON parameter need to be an valid JSON",
      "    at Object.execute (/home/harshavardhan.macchetti/zemoso/it-security/n8n-testing/packages/nodes-base/nodes/HttpRequest/V3/HttpRequestV3.node.ts:1520:14)",
      "    at Workflow.runNode (/home/harshavardhan.macchetti/zemoso/it-security/n8n-testing/packages/workflow/src/Workflow.ts:1382:31)",
      "    at /home/harshavardhan.macchetti/zemoso/it-security/n8n-testing/packages/core/src/WorkflowExecute.ts:1167:42",
      "    at /home/harshavardhan.macchetti/zemoso/it-security/n8n-testing/packages/core/src/WorkflowExecute.ts:1887:11"
    ]
  }
}

i need to send the error as a message into my google chat using webhook suggest the best way to do it

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @Harsha_Vardhan_Macch

The problem is most likely the \n and \ in your input. Ideally, can you share your workflow though with some pinned data, so we can see what you’re trying to achieve?

Thanks!

Tip for sharing your workflow in the forum

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

Make sure that you’ve removed any sensitive information from your workflow and include dummy data or pinned data as much as you can!


I actually ran into this myself today and as Ria suggested, it was the special characters. I solved it like this:

"text": "{{ $json.status.replace(/(?:\r\n|\r|\n)/g, '\\n') }}",

1 Like