Particle telegraf and influxDB webhook documentation not so clear

Hello eveyrone,
after spending a lot of time, i'm still trying to create a custom webhook to telegraf input.

I have this ref, problem look close ... but i'm not sure that documentation is up to date:

On telegraf side, webhook explanation is not so great too:

For exemple, when i select "request type" --> json with default body, i have this error on telegraf:

Jan 23 15:47:19 scw-zen-raman telegraf[4687]: 2023-01-23T15:47:19Z E! [inputs.webhooks] Error in plugin: json: cannot unmarshal string into Go struct field event.data of type particle.data
Jan 23 15:47:27 scw-zen-raman telegraf[4687]: 2023-01-23T15:47:27Z D! [outputs.http] Wrote batch of 21 metrics in 12.706223ms
Jan 23 15:47:27 scw-zen-raman telegraf[4687]: 2023-01-23T15:47:27Z D! [outputs.http] Buffer fullness: 0 / 10000 metrics

And a 400 error code on particle console:

Error Message

A detailed message about what went wrong

error status 400 from XXXXXXXX

Event

The source event that triggered the webhook
{
  "name": "temperature",
  "data": "-1.900000",
  "published_at": "2023-01-23T15:50:20.733Z",
  "coreid": "e00fce681b7d3866a20937b0"
}

Request

The HTTP request sent to the webhook url


POST /particle HTTP/1.1
User-Agent: ParticleBot/1.1 (https://docs.particle.io/webhooks)
host: 51.158.230.47:1619
accept: application/json
content-type: application/json
content-length: 120
Connection: keep-alive

Response

The HTTP response received from the webhook url

HTTP/1.1 400 Bad Request
Date: Mon, 23 Jan 2023 15:51:20 GMT
Content-Length: 0

undefined

Error is recurrent when i'm searching help ... but nothing to resolve.

Could someone have a valid Body / full config for telegraf webhook input ?

thanks a lot.

Can you copy and paste the custom JSON from your webhook configuration?

Also make sure you follow the instructions exactly. The correct configuration will show up as an error in the webhook editor. If you add the quotes to make the editor error go away, it will no longer work with Telegraf.

Hello rick, thanks helping me.

Full webhook conf:

{
    "event": "temperature",
    "deviceID": "e00fce681b7d3866a20937b0",
    "url": "http://XX.XX.XX.XX:1619/particle",
    "requestType": "POST",
    "noDefaults": true,
    "rejectUnauthorized": false,
    "json": "{\n  \"event\": \"{{{PARTICLE_EVENT_NAME}}}\",\n  \"data\": {{{PARTICLE_EVENT_VALUE}}},\n  \"coreid\": \"{{{PARTICLE_DEVICE_ID}}}\",\n  \"published_at\": \"{{{PARTICLE_PUBLISHED_AT}}}\",\n  \"userid\": \"{{{PRODUCT_USER_ID}}}\",\n  \"fw_version\": \"{{{PRODUCT_VERSION}}}\",\n  \"public\": \"{{{PARTICLE_EVENT_PUBLIC}}}\",\n  \"measurement\": \"<your measurement>\",\n  \"influx_db\": \"influxdata_sensors\"\n}"
}

Stack trace from telegraf debug output:

Jan 24 09:05:22 scw-zen-raman telegraf[31379]: 2023-01-24T09:05:22Z E! [inputs.webhooks] Error in plugin: json: cannot unmarshal number into Go struct field event.data of type particle.data
Jan 24 09:05:28 scw-zen-raman telegraf[31379]: 2023-01-24T09:05:28Z D! [outputs.http] Wrote batch of 22 metrics in 14.091732ms
Jan 24 09:05:28 scw-zen-raman telegraf[31379]: 2023-01-24T09:05:28Z D! [outputs.http] Buffer fullness: 0 / 10000 metrics
Jan 24 09:05:38 scw-zen-raman telegraf[31379]: 2023-01-24T09:05:38Z D! [outputs.http] Wrote batch of 22 metrics in 12.452007ms
Jan 24 09:05:38 scw-zen-raman telegraf[31379]: 2023-01-24T09:05:38Z D! [outputs.http] Buffer fullness: 0 / 10000 metrics
Jan 24 09:05:48 scw-zen-raman telegraf[31379]: 2023-01-24T09:05:48Z D! [outputs.http] Wrote batch of 22 metrics in 13.582396ms
Jan 24 09:05:48 scw-zen-raman telegraf[31379]: 2023-01-24T09:05:48Z D! [outputs.http] Buffer fullness: 0 / 10000 metrics
Jan 24 09:05:52 scw-zen-raman telegraf[31379]: 2023-01-24T09:05:52Z E! [inputs.webhooks] Error in plugin: json: cannot unmarshal number into Go struct field event.data of type particle.data
Jan 24 09:05:58 scw-zen-raman telegraf[31379]: 2023-01-24T09:05:58Z D! [outputs.http] Wrote batch of 22 metrics in 14.137167ms
Jan 24 09:05:58 scw-zen-raman telegraf[31379]: 2023-01-24T09:05:58Z D! [outputs.http] Buffer fullness: 0 / 10000 metrics
Jan 24 09:06:08 scw-zen-raman telegraf[31379]: 2023-01-24T09:06:08Z D! [outputs.http] Wrote batch of 22 metrics in 32.273145ms
Jan 24 09:06:08 scw-zen-raman telegraf[31379]: 2023-01-24T09:06:08Z D! [outputs.http] Buffer fullness: 0 / 10000 metrics
Jan 24 09:06:18 scw-zen-raman telegraf[31379]: 2023-01-24T09:06:18Z D! [outputs.http] Wrote batch of 22 metrics in 14.286064ms
Jan 24 09:06:18 scw-zen-raman telegraf[31379]: 2023-01-24T09:06:18Z D! [outputs.http] Buffer fullness: 0 / 10000 metrics

i use telegraf

root@scw-zen-raman:~# telegraf --version
Telegraf 1.25.0 (git: HEAD@4d17ec79)
root@scw-zen-raman:~#

I'm not positive but I think this error:

[inputs.webhooks] Error in plugin: json: cannot unmarshal number into Go struct field event.data of type particle.data

Is caused because your source event:

{
  "name": "temperature",
  "data": "-1.900000",
  "published_at": "2023-01-23T15:50:20.733Z",
  "coreid": "e00fce681b7d3866a20937b0"
}

only contains a number in the data (event data) field. In the tutorial is looks like the data field is supposed to be a JSON structure with "tags" and "values" not just a value.

It’s make sens …i didn’t think about that !

i will try …thanks rickk :wink:

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