How to structure a query to InfluxDB with the Flux API
I am also interested in how to structure a query to InfluxDB with the Flux API, mainly for the time grouping and functions that are available OOTB. If anyone has a sample of a PostJSON that is working, it would be great to see, I think the issue is how the fluxQuery part is structured, I have tried multiple formats with the same failure result. Below is a sample of what I am trying, but the response I get is "An internal error has occurred - check server logs"
// Construct the Flux query as a string
let fluxQuery = "data = from(bucket: \"thingworx\")\n |> range(start: -60m, stop: -1m)\n |> filter(fn: (r) => r[\"_measurement\"] == \"Winder_Thing01\")\n |> filter(fn: (r) => r[\"_field\"] == \"KibbleWinderAmps\")\n |> filter(fn: (r) => r[\"valuestreamname\"] == \"Winder_Thing01_VS\")\n |> aggregateWindow(every: 1m, fn: median, createEmpty: false)\n |> yield(name: \"median\")";
var headers = {
"Content-Type": "application/json", // Correct the Content-Type
"Authorization": "Token ourToken"
};
let params = {
proxyScheme: undefined /* STRING {"defaultValue":"http"} */,
headers: headers /* JSON */,
ignoreSSLErrors: undefined /* BOOLEAN */,
useNTLM: undefined /* BOOLEAN {"defaultValue":false} */,
workstation: undefined /* STRING {"defaultValue":""} */,
useProxy: undefined /* BOOLEAN {"defaultValue":false} */,
withCookies: undefined /* BOOLEAN {"defaultValue":false} */,
proxyHost: undefined /* STRING {"defaultValue":""} */,
url: 'http://localhost:8086/api/v2/query/analyze?orgID=OrgID' /* STRING */,
content: fluxQuery /* JSON */,
timeout: undefined /* NUMBER {"defaultValue":60} */,
proxyPort: undefined /* INTEGER {"defaultValue":8080} */,
password: undefined /* STRING */,
domain: undefined /* STRING {"defaultValue":""} */,
username: undefined /* STRING */
};
let result = Resources["ContentLoaderFunctions"].PostJSON(params);
Question separated from Original topic.

