[SOLVED] Issue creating a webhook for Particle photon


#1

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.


#2

Hi there, can you post the payload that is being sent to Ubidots? Additionally, can you try with the basic example as well?

All the best


#3

@jotathebest, I have managed to fix the issue. Apparently, the test feature, used to validate a webhook in the Particle Console, doesn’t work with Ubidots. Once I ignored that and actually tested it, it worked fine.


#4

Nice to know that it worked for you, the particle console utility just works if you set both fixed device label and payload.

Enjoy using Ubidots.