Can't figure out ubidots webhook

Hi,

I got my project working, but I am trying to streamline it a little bit and leverage some of the additional features offered by Particle Cloud, primarily webhooks, to post data to ubidots.

I have created the following webhook, based on Ubidots documentation:

{
    "event": "Ubidots",
    "url": "https://industrial.api.ubidots.com/api/v1.6/devices/{{{PARTICLE_DEVICE_ID}}}",
    "requestType": "POST",
    "noDefaults": false,
    "rejectUnauthorized": true,
    "headers": {
        "X-Auth-Token": "XXXXXX",
        "Content-Type": "application/json"
    },
    "body": "{{{PARTICLE_EVENT_VALUE}}}"
}

And for the life of me, I can’t figure out why it is not working. I created the webhook and then clicked on “Test” and it gave me an error status 400 from industrial.api.ubidots.com.
In my application if, instead of using UBI_PARTICLE when defining my ubidots, I use UBI_HTTP, my code works perfectly fine.
Here is my simple code to test it:

#include <Ubidots.h>


Ubidots ubidots("webhook", UBI_PARTICLE);

void setup() {
  // Put initialization like pinMode and begin functions here.
  Serial.begin(9600);
  Particle.subscribe("hook-response/Ubidots", ubidotsHandler, MY_DEVICES);
  ubidots.setDebug(true);
}

// loop() runs over and over again, as quickly as it can execute.
void loop() {
  delay(10000);
  Serial.println("main: Starting loop");
  // The core of your code will likely live here.
  Serial.println("main: posting data to ubidots");
  ubidots.add("sensor-0", 12345);
  ubidots.add("sensor-1", 67890);
  bool bufferSent = false;
  bufferSent = ubidots.send("Ubidots", PUBLIC);
  if(bufferSent) {
    Serial.println("main: data sent correctly to ubidots");
  }
  delay(30000);
}

void ubidotsHandler(const char *event, const char *data) {
  Serial.printlnf("ubidotsHandler: data = %s", data);
  if(!data) {
    Particle.publish("ubidotsResp", "No data");
    return;
  }
  int respCode = atoi(data);
  if((respCode == 200 || respCode == 201)) {
    Particle.publish("ubidotsHook", "Success");
  } else {
    Particle.publish("ubidotsHook", data);
  }
}

In my event log, I can see the hook-set/Ubidots, but then followed by hook-error/Ubidots.
Any idea where the issue is?

Thanks a lot in advance,
B.

Hi @dbblackdiamond -

I know how frustrating this can be, but alas… there is a simple answer to your problem :slight_smile:

You were/are getting a 400 error response code because the webhook setup as indicated in the help center article is meant to work while testing with a working Particle device, not with the test button option in the Particle console. As you can see in the URL, they advise to use the {{{PARTICLE_DEVICE_ID}}} key which means that every webhook call will replace that particular portion of the URL with the corresponding device id triggering the webhook.

This means your web hook is probably functioning just fine, I suggest testing it with a complete setup of a connected Particle device and monitor the inflow of data to your Ubidots account. You can refer to aprevious project of mine, I posted the working code there connecting to Ubidots dashboard.

Hope this helps :slight_smile:

1 Like

hey, last time I checked the ubidots library it contained an example for webhooks. Have you looked at it?
If so, please ignore my comment.
Thanks!

Thanks to @friedl_1977, I managed to solve my issue. It was indeed, just a matter of the “test” feature not working.

2 Likes

Glad I could help :slight_smile:

1 Like

That link appears to be dead

The shown address is correct but the link behind it is wrong :wink:

This is not a question, it is a solution. I just finished out creating a Particle Webhook to publish the values for two analog channels at the same time to Ubidots. The approach doesn’t use the Ubidots library, but rather a more direct Particle approach. Hope it helps out someone.

http://www.savvysolutions.info/savvymicrocontrollersolutions/particle.php?article=particle-webhook-ubidots

Thanks for letting me know about the issue.

http://www.savvysolutions.info/savvymicrocontrollersolutions/particle.php?article=particle-webhook-ubidots

1 Like