Webhook woes :)

Hi -

@Support

Hoping someone can point out what I am doing wrong. I am setting up a new webhook to send data to @Blynk. I have done this before, several times in fact but for some reason something is amiss this time.

First check, yes... I have the Blynk-stuff right at the top of my firmware. For the sake of clarity, I am leaving my auth token exposed, will change it later.

#define BLYNK_TEMPLATE_ID "TMPL4doYO7xzH"
#define BLYNK_TEMPLATE_NAME "Smart Pot"
#define BLYNK_AUTH_TOKEN "Nmjfq45ZMWASwdD6IXEQMx1x0xj4hYvC"

const char *WEBHOOK_NAME = "Blynk_Send";          // Particle Webhook name

This is where I actually construct and send the message:

void publish () {
    
    snprintf(data, sizeof(data) 
        , "{\"t\":\"%s\",\"sun_light_level\":%i\"soil_level\":%i}"
        , BLYNK_AUTH_TOKEN, sun_light_level,soil_level
        );  
        
        Particle.publish("Send_smartpot_data", data, PRIVATE);
}

This is the message I get from Particle events:

{"t":"Nmjfq45ZMWASwdD6IXEQMx1x0xj4hYvC","sun_light_level":0"soil_level":0}

Now comes the problem. The webhook keeps failing with the the following response.

HTTP/1.1 400 Bad Request
connection: keep-alive
content-type: application/json;charset=utf-8
access-control-allow-origin: *
content-length: 42

{"error":{"message":"No token provided."}}

Digging deeper I noticed the following.

EVENT:

HTTP/1.1 400 Bad Request
connection: keep-alive
content-type: application/json;charset=utf-8
access-control-allow-origin: *
content-length: 42

{"error":{"message":"No token provided."}}

REQUEST:

GET /external/api/batch/update?token=&V0=&V1= HTTP/1.1
User-Agent: ParticleBot/1.1 (https://docs.particle.io/webhooks)
host: fra1.blynk.cloud
Connection: keep-alive

For the life of me, I do not know why the Auth token is not passed.

I really hope I am missing something very obvious.... :exploding_head: :smile:

Regards,
Friedl.

There's a typo here:

"{\"t\":\"%s\",\"sun_light_level\":%i\"soil_level\":%i}"
                                     ^here 

There needs to be a comma between the i and \. Since the JSON payload is invalid it can't be parsed so all of the template variables will be empty.

3 Likes

@rickkas7

OH MY WORD!!! :exploding_head: :blush:

Thanks, really appreciated, I was going insane! Let me check quick.

You are a lifesaver, thanks @rickkas7 :smiling_face:

1 Like

Friedl,

You can use a json validator online like:

Or any other.

I copy pasted your json and it gave the error away :slight_smile:

{"t":"Nmjfq45ZMWASwdD6IXEQMx1x0xj4hYvC","sun_light_level":0"soil_level":0}

Best

5 Likes

Hi @gusgonnet -

Thank you for your patience, soooo many new things for me but I am trying to learn as I go along.. :exploding_head:

Appreciate the info on the validation tool, will most certainly make use of it! Good to have all these tools to help out when stuck.

Regards.
Friedl.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.