Use Webhooks to POST application/x-www-form-urlencoded data

Hi there,

Im trying to do a POST request to a server like the following:

Content-Type: application/x-www-form-urlencoded

I read the documentation about Webhooks and it says about the form field that “This parameter will change the content-type header to application/x-www-form-urlencoded” and that is exactly what I need. So I’m creating a login webhook like this:

    "eventName": "login",
    "url": "",
    "requestType": "POST",
    "headers": {
        "Content-Type": "application/x-www-form-urlencoded"
    "form": {
        "user" : "{{user}}",
        "password" : "{{password}}}"
    "mydevices": true

And I’m sending the user and password through the publish function using templates:

Spark.publish("login", "{ \"user\": \"USERNAME\", \"password\": \"PASSWD\" }", 60, PRIVATE);

This isn’t working. In the dashboard I can see that the data being sent is correct (something like this {“user”:“USERNAME”,“password”:“PASSWD”} ), but I receive no data response from the server. I’ve tested sending the POST request in the beginning using HttpRequester (Firefox plugin) and it works OK.

How can I modify my webhook or Spark.publish format in order to make the webhook send a POST request like that to my server?


@luistohe, Spark.publish will send a string that you define but will not “build” it. Meaning, you will need to inject the “user” and “password” string values in the final published string. You can do that using sprintf(), String commands or char array command list strcpy and strcat for example. :smile:

Hi peekay123, thanks for your quick answer.

I’m actually sending the strings to the publish functions this way: (I know it may not be the most efficient way but it worked)

Serial.println("Sending Credentials!");

String one = String("{\"user\":\"" + userVar);
String two = String("\",\"password\":\"" + passwordVar);
String three = String("\"}");
String four = String(one + two + three);
Spark.publish("login", four, 60, PRIVATE);
Serial.println("Publish OK!");

where userVar and passwordVar are String variables that contain the user and password in String format.

Lets assume that userVar = “USERNAME”; and passwordVar = “PASSWD”;
The Serial print function that prints the variable four prints this: {“user”:“USERNAME”,“password”:“PASSWD”}.
I then handle both variables in the webhook.

This is what you meants by building the String?


Is it anything to do with the third curly brace after password when you create the webhook?

 "password" : "{{password}}}"
1 Like

Good catch @AndyRawson!!

1 Like

Thanks AndyRawson. I fixed that and removed the 3rd closing brace but still same problem.

This is what happens in the dashboard when I send the info:

NOTE: I’m actually using a webhook named “entrar” and the user variable is actually called “usuario”. I’ve translated them to make my code more understandable in English.

As you can see, in data I get nothing in response from the server.

Now, this is an example of a POST Request I’m doing with HttpRequest firefox plugin:

NOTE: Hid some private info.

How can I obtain this same info at the webhook response?


Any ideas what might be happening ? Need more info? I can provide more info here or by PM.


@luistohe, can you PM me the string that publish puts out to the webhook? I need to make sure the JSON is correctly formed. :smile: