Webhooks - Defining the request body as json array?

Hi @dreamnid,

Looking at the Webhooks documentation, it seems that a custom body request is not supported.

I was actually thinking about something similar in order to make the Particle <> Ubidots integration as seamless as possible and deployed a new endpoint specifically for Particle. Would you like to test it? it works like this:

1- Create a Webhook

Make this HTTP request from a tool like Postman or Hurl.it. Following these tests, we would integrate this request into Ubidots, so you don’t have to use an external tool:

POST https://api.particle.io/v1/webhooks?access_token=YOUR-PARTICLE-TOKEN
Content-Type: application/json

{
    "event": "ubidots",
    "url": "http://translate.ubidots.com:9080/particle/?ubi_token=YOUR-UBIDOTS-TOKEN",
    "requestType": "POST"
}

2- Flash your device

This code will send two analog inputs (A0 and A1) to Ubidots, every 10 seconds. In the spark.publish function, specify the event name “ubidots”, and a JSON string in the format {“variable_name”: value, “variable_name”: value, “variable_name”: value, … “variable_name”: value, }.

#define publish_delay 10000

unsigned int lastPublish = 0;

void setup() {
    //Serial.begin(9600);
}

void loop() {
    unsigned long now = millis();
    int temp = analogRead(A0);
    int hum = analogRead(A1);

    if ((now - lastPublish) < publish_delay) {
        // it hasn't been 10 seconds yet...
        return;
    }

    Spark.publish("ubidots", "{\"temperature\":" + String(temp) + ", \"humidity\":"+ String(hum) + "}");
    
    lastPublish = now;
}

Once flashed, you should see the “Spark.publish” events coming in, and the Ubidots webhook replying {“status”:“OK”}

What’s cool about this is you won’t have to create datasources or variables in Ubidots; they will be automatically created using the “core_id” and “variable_name”'s. This is great for provisioning several devices automatically (every device can have the same firmware, but will appear as a different data source inside Ubidots).

Here’s how the data looks inside Ubidots:

Please note that the data source has a tag with the “core_id”; this is how we differentiate each Core, so be careful about not changing it. The data source name can be change without problems:

The variable names should match the ones in your code. If you change them, then a new variable will be created.

3 Likes