Unable to parse the string

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:

Welcome to the community @Harsha_Vardhan_Macch !

Tip for sharing information

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>
```

That implies to any JSON output you would like to share with us.

Make sure that you have removed any sensitive information from your workflow and include dummy or pinned data with it!


Did I get it right that $json.error referes to the string with the value

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"

You can successfuly validate the body as JSON if you rewrite it as below

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

Though, that might give you not the output you expected. If so, what do you expect to send out? Perhaps you meant to parse that error message first before utilizing it in the body of the POST method?