Page 1 of 1

Flux, Influxdb, HTTP post

Posted: 26. Jan 2020, 17:00
by salvq123
Hello,

I am using flux scripting lang used by Influxdb database and trying to use HTTP POST to send a message, details https://v2.docs.influxdata.com/v2.0/ref ... http/post/.

Can you let me know how to specify the HTTP request to send a message ?

Thanks

Function

Code: Select all

http.post(
  url: "http://localhost:9999/",
  headers: {x:"a", y:"b", z:"c"},
  data: bytes(v: "body")
)

Example

Code: Select all

import "json"
import "http"

lastReported =
  from(bucket: "example-bucket")
    |> range(start: -1m)
    |> filter(fn: (r) => r._measurement == "statuses")
    |> last()
    |> tableFind(fn: (key) => exists key._level)
    |> getColumn(column: "_level")

http.post(
  url: "http://myawsomeurl.com/api/notify",
  headers: {Authorization: "Bearer mySuPerSecRetTokEn"},
  data: bytes(v: lastReported[0])
)

Re: Flux, Influxdb, HTTP post

Posted: 26. Jan 2020, 21:23
by admin
Hello,

i think this is what you need:

Code: Select all

import "http"

http.post(
  url: "https://www.pushsafer.com/api",
  data: bytes(k: "PRIVATEKEY", d: "DEVICEID", s: "5", i: "12", v: "3")
)

Replace data by you own. You can add more pushsafer parameter in the same way!

Kevin

Re: Flux, Influxdb, HTTP post

Posted: 30. Jan 2020, 12:53
by salvq123
Unfortunately it does not work.

I have asked influxdb to help to translate HTTP POST from your examples to Flux HTTP POST.

When I get answer, will post solution here.

Re: Flux, Influxdb, HTTP post

Posted: 30. Jan 2020, 13:13
by admin
thanks, i will wait ...