SemaphoreUI API with n8n weird problem

n8n http request to SemaphoreUI API only works randomly.

This seems to be a really weird issue and hopefully I have described it correctly! I have an n8n automation which makes a call to SemaphoreUI API and (authenticates with a bearer token) it runs a specific ansible playbook - playbook number 5 or as n8n sees it in the variables:

“name”: “template_id”,
“value”: “5”

Everything works perfectly as expected however, if I duplicate the node and add it to the same workflow as an additional step later and make only one change to the values - the template_id to “7” instead of the original number “5”, the process fails citing Bad Request etc. No matter what value I change it to other than 5 in n8n it fails (the other values being that of other ansible playbooks that SemaphoreUI has configured).

Strangely enough, if I download the workflow from n8n and open it in Visual code studio and change the “5” to a “7” and import it back as a new workflow it works! If I then change the “7” back to “5” in n8n it breaks again so I am really confused about what is happening here and unsure if it is an n8n issue or SemaphoreUI one. If I use Postman to do the same API call it works for whatever playbook value I specify so this leads me to suspect perhaps it’s an n8n problem somehow? Both n8n and semaphoreui are self hosted on a local lan on same hypervisor.

What is the error message (if any)? “Bad request - please check your parameters”

Please share your workflow

{
“meta”: {
“instanceId”: “34aa1191088d9904526754fc1fd0890555e45f15009a62bb18e2ba17d11eedc6”
},
“nodes”: [
{
“parameters”: {},
“id”: “8305406f-5d23-4da9-aea2-0640d0ab9b16”,
“name”: “When clicking ‘Test workflow’”,
“type”: “n8n-nodes-base.manualTrigger”,
“typeVersion”: 1,
“position”: [
400,
520
]
},
{
“parameters”: {
“method”: “POST”,
“url”: “https://192.168.1.2/api/project/1/tasks”,
“sendHeaders”: true,
“headerParameters”: {
“parameters”: [
{
“name”: “Accept”,
“value”: “application/json”
},
{
“name”: “Authorization”,
“value”: “Bearer cjlwoqs3g5cqmge91kfrl9fyqy1qfjlnmrus0wvlqns=”
}
]
},
“sendBody”: true,
“bodyParameters”: {
“parameters”: [
{
“name”: “template_id”,
“value”: “7”
}
]
},
“options”: {
“allowUnauthorizedCerts”: true
}
},
“id”: “1a6218c7-4e66-4ebc-8e4e-b9f5784ebd55”,
“name”: “HTTP Request2”,
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4.2,
“position”: [
1060,
520
]
}
],
“connections”: {
“When clicking ‘Test workflow’”: {
“main”: [
[
{
“node”: “HTTP Request2”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“pinData”: {}
}

Share the output returned by the last node

From HTTP Request

Error code

400

Full message

400 - ""

Request

{ "body": { "template_id": "7" }, "headers": { "accept": "application/json", "authorization": "**hidden**" }, "method": "POST", "uri": "https://192.168.1.2/api/project/1/tasks", "gzip": true, "rejectUnauthorized": false, "followRedirect": true, "resolveWithFullResponse": true, "followAllRedirects": true, "timeout": 300000, "encoding": null, "json": false, "useStream": true

Information on your n8n setup

  • **n8n version :1.66.0
  • **Database default:SQLite
  • **n8n EXECUTIONS_PROCESS setting (default):default
  • **Running n8n via:Dcoker
  • **Operating system:Ubuntu Server 22.04.

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:

Out of desperation I disabled Nginx reverse proxy and dropped back to the default http on 5678 in the hope that somehow the proxy was mangling the data but same problem. If anybody has any suggestions on how to explore further I would appreciate it as I had been hoping this tool could replace our company’s existing SOAR platform and we would go for enterprise support but if I can’t figure out this issue that will put a halt to my gallop.

Hey @bindybandy

Welcome to the community :raised_hands:

Have you tried sending the same request to something like webhook.site (after replacing the auth header) to see if the data is being correctly sent?

Hi Jon,

Excellent suggestion - thank you as I was pulling my hair out on this one! I had not been aware of that website. So I think I might have found the problem. Submitting to webhook.site shows the inital sucessful automation runs the template id as 5

Raw Content

{
“template_id”: 5
}

However if I double click the node in the canvas and delete the 5 and change it to a 7 and submit it comes out as “7” instead of just 7.

Raw Content

{
“template_id”: “7”
}

Any idea how this happens or how to fix? I am not using an expression and the number is a fixed value.

All solved and working now beautifully!

swapped out the fixed value to an expression using the double curly braces i.e. {{7}} and it works fine.

Should this be considered a bug perhaps in n8n where it processes the integer as a string or is this expected behavior?

1 Like

Hey @bindybandy,

In theory we treat all values as strings unless told otherwise by doing what you have done. Maybe we should add an option to the body to select the json data type to make life easier.

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