HTTP Request - Put - How to assign RAW/Body attributes

Greetings,

Using n8n - Docker Image 0.58.0

I’m having difficulty using HTTP request with a PUT passing a boolean as an argument via RAW/CUSTOM

I’m trying to utilise Meraki API located here:
https://dashboard.meraki.com/api_docs/v0#switch-ports

In particular update a port that can be surmised as follows:

Update a switch port

HTTP REQUEST

PUT/devices/{serial}/switchPorts/{number}`

PARAMETERS

  • name
    The name of the switch port
  • tags
    The tags of the switch port
  • enabled

https://dashboard.meraki.com/api/v0/devices/AAAA-BBBB-CCCC/switchPorts/8
With params as per screenshot. I have tried “enabled”:false in inverted commas and also as an expression.

It generates the error![n8nOptionsBodyError|636x274]

I also have tried enabling JSON/RAW Parameters

It generates a temporary redirect error.

I have test harnesses in Postman/httpbot that work correctly. Am I filling the parameters incorrectly ?
Any assistance greatly appreciated.

Workflow

JSON Params enabled

Error Message when JSON Raw Enabled.

Body Error that is generated using RAW/Custom
n8nOptionsBodyError

Welcome to the community @GavinTomlins!

Is there any particular reason why you set “Body Content Type” and “Mime Type”? Looking at the API I do not see any reason why it should be needed. Especially setting an empty “Mime Type” has for sure the potential to mess stuff up. I would try to remove everything under “Options”.

@Jan thanks for the reply.

I must confess then, I don’t know how to set to pass in the required parameters in via the n8n interface.

Using Postman, I can get it to work via this mechanism:

(I set the X-Cisco-Meraki-API-Key via the Header)

Again, trying to model this API call extrapolated

One possible way would be this:

{
  "nodes": [
    {
      "parameters": {
        "requestMethod": "PUT",
        "url": "https://api.meraki.com/api/v0/devices/:serial/switchPorts/:number",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "{ \"enabled\": false }",
        "headerParametersJson": "{ \"X-Cisco-Meraki-API-Key\": \"xxxxx\" }"
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        519,
        475
      ]
    }
  ],
  "connections": {}
}

Did set the data via JSON to be more like in Postman and to be sure that “enabled” get send as boolean and not string.

If you change th URL and header accordingly it should theoretically work.

Hi Jan,

do I put your suggested code into the ‘Node’ of the HTTP Request or do I use another component ? (I tried the function component)

If so, do I leave everything else blank ? I’ve tried a few variations and still not having any luck.

You can simply copy it, click once into n8n and then paste it (CTRL+v). It will then create the node.

Greetings all,

further to Jan’s help I was able to rectify the issue., I’ll post a more complete solution in the near future, For the record, the issue was more to do with HTTP Redirect’s and HTTP follow than with n8n execution.

The correct order of flow in using the Meraki:

https://api.meraki.com/api/v0/organizations
The header contains your API key for Meraki
it
returns a JSON string with URL to utilise for API calls. Using that URL it works (ie. don’t call dashboark.meraki.com or api.meraki.com)

For those interested, find below simple screenshot have working parameters and assigned RAW Body attributes
,

1 Like

Thanks a lot @GavinTomlins for posting this. I am sure it will be helpful for other people in a similar situation in the future!