[SOLVED] Webhook errors, Particle

Hopefully someone can enlighten me to whats happening here. I’m having a problem with errors after following this article:

Step 3. Send Multiple Variable to Ubidots, worked fine without errors.
Step 5. Create Ubidots Webhook to Particle to Control Things, not so lucky.

Using this with a Boron, even with all the errors the LED turns ON and OFF as it should.

Request
The HTTP request sent to the webhook url

X-Auth-Token:   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Content-Type: application/json
User-Agent: ParticleBot/1.1 (https://docs.particle.io/webhooks)
host: industrial.api.ubidots.com
content-length: 3
Connection: keep-alive

Response
The HTTP response received from the webhook url

HTTP/1.1 400 Bad Request
Server: nginx
Date: Mon, 19 Apr 2021 23:25:42 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
access-control-allow-origin: *

{"code":400001,"message":"The payload sent is not a valid json document."}

int led = D7;
float control = 0;
int i = 0;

void setup() {

    Serial.begin(115200);
    // Subscribe to the integration response event
    Particle.subscribe("UbidotsWebhook", myHandler);
    pinMode(led, OUTPUT);
}

float setControl(float value) {
    if (value == 1) {
        return 1;
    }
    return 0;
}

void myHandler(const char *event, const char *data) {
  // Handle the integration response
  i++;
  Serial.println(i);
  Serial.print(event);
  Serial.print(", data: ");
  if (data) {
    Serial.println(data);
    control = setControl(atof(data));
  } else {
    Serial.println("NULL");
  }
}

void loop() {    
    if (control == 1) {
        digitalWrite(led, HIGH);
    } else {
        digitalWrite(led, LOW);
    } 
}

Looks like the preformated text isn’t working right.

Any help would be much appreciated, It’s my first time using webhooks.
Thanks,
John

Good day @ardyjohn

I hope you are well.

Are you still having issues creating the Particle WebHook? if yes, can you please send us an image of the payload that is being sent? additionally, did you configure the Particle Webhook event in the Ubidots side based on the article explanation?

I will be attentive to your response.

Best,
-Isabel

Hi Isabel,
Still the same problem. It does work, only the errors have me concerned.
I believe I accurately followed the example. Is this the payload you need?

Thank You!
John

Hello @ardyjohn,

Thank you for the additional help troubleshooting this issue.

Now, the process described in the article below to control things from Ubidots through Particle API is no longer the most appropriate because although it works, you get those 400 errors.

I won’t get into the details to explain why we get those 400 errors but instead you should update your code to use Particle.function() which registers a function in Particle’s cloud that you can trigger externally through their API. This is throughly explain in the below article

Once you implement this methodology, you’ll stop having those 400 error response code while at the same time controlling your Particle devices from Ubidots.

Last but not least, we will update the first article to reflect the proper way of controlling Particle devices from Ubidots.

Best,

–David

@dsr
Have it working error free.
Thank You David!
John