HTTP Request node with brackets in value field -> server error

I am trying to get some data from the FDA database via the HTTP request node.

A simple request with name= search and value = device.device_report_product_code=FRN works fine, but as soon as I use brackets in the value field for the date range, I get a server 500 error code.

Error Message:
{ “error”: { “code”: “SERVER_ERROR”, “message”: “Check your request and try again”, “details”: "[parse_exception] parse_exception: Encountered " “]” "] “” at line 1, column 35.\nWas expecting:\n “TO” …\n " } }

Workflow:
{
  "nodes": [
    {
      "parameters": {
        "url": "https://api.fda.gov/device/event.json",
        "options": {
          "useQueryString": false
        },
        "queryParametersUi": {
          "parameter": [
            {
              "name": "search",
              "value": "date_received:[20130101+TO+20141231]"
            },
            {
              "name": "limit",
              "value": "1"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        112,
        144
      ],
      "id": "0a17fb89-1320-4ed8-a554-7261b5a98ae6"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -48,
        144
      ],
      "id": "9bc1b3bb-9bf4-49fc-ab71-128d9c889045",
      "name": "When clicking ‘Execute workflow’"
    }
  ],
  "connections": {
    "HTTP Request": {
      "main": [
        []
      ]
    }
  },
  "pinData": {},
  "meta": {
    "instanceId": "0f84d620e5b95f2d23c721740bdcdb03b9d37b2aecf7f99c52ae736a8a4adff4"
  }
}

Hi,

Please try this (without the plus signs): “date_received:[20130101 TO 20141231]”

n8n should know how to escape the characters. See if that works.

Some more detail:

I know a working curl command would be:

curl "https://api.fda.gov/device/event.json?search=date_received%3A%5B20130101%20TO%2020141231%5D&limit=1"

If n8n were to escape the raw text it should give the above. The additional “+” would mess this up, as it would escape the “+” as well.

Khem

1 Like

You need to URL encode the brackets, since are required in the API date range, according to their API:

https://open.fda.gov/apis/dates-and-ranges/?hl=en-US

And yes the solution provided by @KhemOptimal , it should work :

Character URL Encoded Values :

[ %5B

] %5D

Space %20 or +

Soo, your value should look:

device.date_received%3A%5B20230101%20TO%2020231231%5D

Cheers!

2 Likes

Perfect - works. Thank you

“date_received:[20130101 TO 20141231]” does not work, but device.date_received%3A%5B20230101%20TO%2020231231%5D
does.
Thank you

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.