[SOLVED] Webhook data refused by API

Hello
I am trying to fetch the data from Huffington Pollster API.
The data I am trying to get is this one, which is accessible through browser without any authentication as you can see.

I have created a webhook with this file:

{
"eventName": "get_gop_poll1",
"url": "http://elections.huffingtonpost.com/pollster/api/charts?state=US&topic=2016-president-gop-primary",
"requestType": "GET",
"headers": null,
"query": null,
"json": null,
"auth": null,
"mydevices": true,
"noDefaults": true
}

However when I publish the event “get_gop_poll”, the request is rejected by the API. It is like if the webhook was sending the Particle data to the API…

event: get_gop_poll
data: {"data":"undefined","ttl":"60","published_at":"2015-12-21T09:24:06.993Z","coreid":"001"}

event: hook-sent/get_gop_poll
data: {"data":"undefined","ttl":"60","published_at":"2015-12-21T09:24:07.011Z","coreid":"particle-internal"}

event: hook-response/get_gop_poll/0
data: {"data":"{\"errors\":[\"event is an invalid parameter\",\"data is an invalid parameter\",\"published_at is an invalid parameter\",\"coreid is an invalid parameter\"]}","ttl":"60","published_at":"2015-12-21T09:24:07.183Z","coreid":"particle-internal"}

I want to use the data to fetch each candidate latest poll value, by using the responseTemplate, but I am not there yet, as I can’t even fetch the raw data!

is this trailing 1 in "eventName": "get_gop_poll1" a typo, or is it really part of your webhook?

Might need this:


{
"eventName": "get_gop_poll1",
"url": "http://elections.huffingtonpost.com/pollster/api/charts",
"requestType": "GET",
"headers": null,
"query": {
   "state": "US",
   "topic": "2016-president-gop-primary"
  },
"json": null,
"auth": null,
"mydevices": true,
"noDefaults": true
}
1 Like

I had tried using query also, but the result is the same.
And no the “get_gop_poll1” is not a typo, I add a number after each try to make sure I am using the webhook I just created.

AH HA!

Try this:

{
"eventName": "get_gop_poll1",
"url": "http://elections.huffingtonpost.com/pollster/api/charts",
"requestType": "GET",
"query": {
   "state": "US",
   "topic": "2016-president-gop-primary"
  },
"json": null,
"auth": null,
"mydevices": true,
"noDefaults": true
}

Testing working for me :slight_smile: Setting the headers to null caused issues when getting a request.

Unfortunately, it does not change the result, I still get the same error.
However I noticed that the webhook request is sent several times to the API. Did I mess up with webhooks creation, that confused Particle Cloud?

event: get_gop_poll3
data: {"data":"undefined","ttl":"60","published_at":"2015-12-21T10:50:24.157Z","coreid":"001"}

event: hook-sent/get_gop_poll3
data: {"data":"undefined","ttl":"60","published_at":"2015-12-21T10:50:24.166Z","coreid":"particle-internal"}

event: hook-sent/get_gop_poll3
data: {"data":"undefined","ttl":"60","published_at":"2015-12-21T10:50:24.167Z","coreid":"particle-internal"}

event: hook-response/get_gop_poll3/0
data: {"data":"{\"errors\":[\"event is an invalid parameter\",\"data is an invalid parameter\",\"published_at is an invalid parameter\",\"coreid is an invalid parameter\"]}","ttl":"60","published_at":"2015-12-21T10:50:24.241Z","coreid":"particle-internal"}

event: hook-response/get_gop_poll3/0
data: {"data":"{\"errors\":[\"event is an invalid parameter\",\"data is an invalid parameter\",\"published_at is an invalid parameter\",\"coreid is an invalid parameter\"]}","ttl":"60","published_at":"2015-12-21T10:50:24.254Z","coreid":"particle-internal"}

Did you delete the old webhooks then?

Well after creating 10 webhooks, CLI refused new creations. So I deleted the old ones. At the moment there is only one webhook related to this API.
How did you test it? Here is what i do:

  1. particle webhook create create_webhook.json
  2. particle publish get_gop_poll3
  3. The events are displayed in dashboard logs and in “curl monitoring window”

I’m mostly on CLI

particle publish get_gop_poll1 gave me this

Subscribing to all events from my personal stream (my devices only) 
Listening to: /v1/devices/events
{"name":"get_gop_poll1","data":"undefined","ttl":"60","published_at":"2015-12-21T14:28:33.546Z","coreid":"001"}
{"name":"hook-sent/get_gop_poll1","data":"undefined","ttl":"60","published_at":"2015-12-21T14:28:33.542Z","coreid":"particle-internal"}
{"name":"hook-response/get_gop_poll1/0","data":"[{\"title\":\"2016 National Republican Primary\",\"slug\":\"2016-national-gop-primary\",\"topic\":\"2016-president-gop-primary\",\"state\":\"US\",\"short_title\":\"2016 National Republican Primary\",\"election_date\":null,\"poll_count\":243,\"last_updated\":\"2015-12-18T23:04:23.000Z\",\"url\":\"http://elections.huffingtonpost.com/pollster/2016-national-gop-primary\",\"estimates\":[{\"choice\":\"Trump\",\"value\":37.5,\"lead_confidence\":null,\"first_name\":\"Donald\",\"last_name\":\"Trump\",\"party\":\"Rep\",\"incumbent\":false},{\"choice\":\"Cruz\",\"value\":14.9,\"l","ttl":"60","published_at":"2015-12-21T14:28:33.588Z","coreid":"particle-internal"}
{"name":"hook-response/get_gop_poll1/1","data":"ead_confidence\":null,\"first_name\":\"Ted\",\"last_name\":\"Cruz\",\"party\":\"Rep\",\"incumbent\":false},{\"choice\":\"Rubio\",\"value\":10.5,\"lead_confidence\":null,\"first_name\":\"Marco\",\"last_name\":\"Rubio\",\"party\":\"Rep\",\"incumbent\":false},{\"choice\":\"Carson\",\"value\":9.2,\"lead_confidence\":null,\"first_name\":\"Ben\",\"last_name\":\"Carson\",\"party\":\"Rep\",\"incumbent\":false},{\"choice\":\"Bush\",\"value\":5.7,\"lead_confidence\":null,\"first_name\":\"Jeb\",\"last_name\":\"Bush\",\"party\":\"Rep\",\"incumbent\":false},{\"choice\":\"Christie\",\"value\":3.2,\"lead_con","ttl":"60","published_at":"2015-12-21T14:28:33.842Z","coreid":"particle-internal"}
{"name":"hook-response/get_gop_poll1/2","data":"fidence\":null,\"first_name\":\"Chris\",\"last_name\":\"Christie\",\"party\":\"Rep\",\"incumbent\":false},{\"choice\":\"Huckabee\",\"value\":2.8,\"lead_confidence\":null,\"first_name\":\"Mike\",\"last_name\":\"Huckabee\",\"party\":\"Rep\",\"incumbent\":false},{\"choice\":\"Fiorina\",\"value\":2.7,\"lead_confidence\":null,\"first_name\":\"Carly\",\"last_name\":\"Fiorina\",\"party\":\"Rep\",\"incumbent\":false},{\"choice\":\"Rand Paul\",\"value\":2.6,\"lead_confidence\":null,\"first_name\":\"Rand\",\"last_name\":\"Paul\",\"party\":\"Rep\",\"incumbent\":false},{\"choice\":\"Kasich\",\"value\":2.","ttl":"60","published_at":"2015-12-21T14:28:34.093Z","coreid":"particle-internal"}
{"name":"hook-response/get_gop_poll1/3","data":"1,\"lead_confidence\":null,\"first_name\":\"John\",\"last_name\":\"Kasich\",\"party\":\"Rep\",\"incumbent\":false},{\"choice\":\"Graham\",\"value\":0.7,\"lead_confidence\":null,\"first_name\":\"Lindsey\",\"last_name\":\"Graham\",\"party\":\"Rep\",\"incumbent\":false},{\"choice\":\"Santorum\",\"value\":0.5,\"lead_confidence\":null,\"first_name\":\"Rick\",\"last_name\":\"Santorum\",\"party\":\"Rep\",\"incumbent\":false},{\"choice\":\"Pataki\",\"value\":0.3,\"lead_confidence\":null,\"first_name\":\"George\",\"last_name\":\"Pataki\",\"party\":\"Rep\",\"incumbent\":false},{\"choice\":\"Undecided","ttl":"60","published_at":"2015-12-21T14:28:34.344Z","coreid":"particle-internal"}
{"name":"hook-response/get_gop_poll1/4","data":"\",\"value\":6.9,\"lead_confidence\":null,\"first_name\":null,\"last_name\":null,\"party\":null,\"incumbent\":null},{\"choice\":\"Other\",\"value\":1.2,\"lead_confidence\":null,\"first_name\":null,\"last_name\":null,\"party\":null,\"incumbent\":null}]}]","ttl":"60","published_at":"2015-12-21T14:28:34.595Z","coreid":"particle-internal"}

It’s working now! I updated particle-cli following another thread, Maybe it’s a side effect.

Thanks @kennethlimcp !