Invalid JSON in HTTP Request

Hello everyone,

I’ve been really enjoying n8n and have undertaken integrating some of my applications.
However, I have recently struggled with creating tickets from a monitoring system alarm with the HTTP Request node.

The service desk application expects the following format for creating tickets:

{
  "title": "Help me!",
  "group": "Users",
  "customer": "[email protected]",
  "article": {
    "subject": "some subject",
    "body": "some message",
    "type": "note",
    "internal": false
  },
  "note": "some note",
  ...
}

What I’m trying to do is use the alarm message as an article body. Here’s an example of the alarm message

"message": "Ping latency Overview ----------------------------- --Error: All pings to the given host have failed! Failed pings: 15:58:52:TimedOut 15:58:47:TimedOut 15:58:42:TimedOut 15:58:37:TimedOut 15:58:32:TimedOut 15:58:27:TimedOut Tracing route -------------------------------- -Info: Hop Nr 0: 172.23.42.4 [HV]: 0%. Latency: 0ms (Threshold: 200ms) "

I’ve used the “JSON/RAW Parameters” option in the HTTP Request node because of the “article” array and constructed my body accordingly. This works when entering some sample value. However, when I try using the value of “message” for the article body n8n doesn’t accept it as valid JSON and throws an error.

Is there some way I can prepare the message to be used by the HTTP Request node?

Best Regards

Welcome to the community @SupersonicWaffle!

Great to hear that you enjoy n8n!

Here an example workflow which shows you how you can do what you want to do:

{
  "nodes": [
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "={{ { \"title\": \"Help me!\", \"group\": \"Users\", \"customer\": \"[email protected]\", \"article\": { \"subject\": \"some subject\", \"body\": $json.message, \"type\": \"note\", \"internal\": false }, \"note\": \"some note\"} }}"
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "message",
              "value": "Here is the message."
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    }
  ],
  "connections": {
    "Set": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

Thank you so much, this work beautifully :slight_smile:

Even requesting the message as HTML to get proper formatting in the ticket system works.

You are welcome. That is great to hear that it now works fine.

Have fun!