http.post() function

The http.post() function submits an HTTP POST request to the specified URL with headers and data and returns the HTTP status code.

*Function type: Output*

  1. import "http"
  2. http.post(
  3. url: "http://localhost:8086/",
  4. headers: {x:"a", y:"b", z:"c"},
  5. data: bytes(v: "body")
  6. )

Parameters

url

The URL to POST to.

*Data type: String*

headers

Headers to include with the POST request.

*Data type: Record*

Header keys with special characters

Wrap header keys that contain special characters in double quotes ("").

  1. {"key-1": "value 1", "key#2": "value 2" }

data

The data body to include with the POST request.

*Data type: Bytes*

Examples

Send the last reported status to a URL
  1. import "json"
  2. import "http"
  3. lastReported =
  4. from(bucket: "example-bucket")
  5. |> range(start: -1m)
  6. |> filter(fn: (r) => r._measurement == "statuses")
  7. |> last()
  8. |> findColumn(fn: (key) => true, column: "_level")
  9. http.post(
  10. url: "http://myawsomeurl.com/api/notify",
  11. headers: {
  12. Authorization: "Bearer mySuPerSecRetTokEn",
  13. "Content-type": "application/json"
  14. },
  15. data: json.encode(v: lastReported[0])
  16. )