Hello everyone,
I am just getting started with InfluxDB so I expect this issue to be sort of simple. I could not find a solution to my specific problem though.
I think the problem is that I use influx v. 1.8. and the documentation for connecting with a javascript client is a bit scarce.
I want to make a simple query to my DB from my Vue Project. The DB is running on localhost:8086.
According to this example : influxdb-client-js/examples/influxdb-1.8.ts at master · influxdata/influxdb-client-js · GitHub
i came up with the following code:
const database = 'timeseries'
const retentionPolicy = 'autogen'
const bucket = `${database}/${retentionPolicy}`
const influxDB = new InfluxDB("http://localhost:8086")
const queryAPI = influxDB.getQueryApi('')
debugger;
const query = `from(bucket: "${bucket}") |> range(start: -1h)`
queryAPI.queryRaw(query)
.then(result => {
console.log(result)
console.log('\nQueryRaw SUCCESS')
})
.catch(error => {
console.error(error)
console.log('\nQueryRaw ERROR')
})
I use queryraw just for testing purposes. My Org is just an empty string.
Now I really do not know what to do next.
Inside the Error-Catch-Block i get the following:
TypeError: Failed to fetch
My Headers look like this (status : CORS error)
1. Request URL:
http://localhost:8086/api/v2/query?org=
2. Referrer Policy:
strict-origin-when-cross-origin
1. Request Headers
1. Provisional headers are shown
2. accept:
text/csv
3. content-type:
application/json; encoding=utf-8
4. Referer:
http://localhost:8081/
5. sec-ch-ua:
" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"
6. sec-ch-ua-mobile:
?0
7. User-Agent:
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36
2. Query String Parametersview sourceview decoded
1. org:
3. Request Payloadview source
1. {query: "from(bucket: "timeseries") |> range(start: -1h)",…}
1. dialect: {header: true, delimiter: ",", quoteChar: """, commentPrefix: "#",…}
2. query: "from(bucket: \"timeseries\") |> range(start: -1h)"
3. type: "flux"
I dont know if its my cors settings thats causing the problem or if I am just querying wrong (should my org really be empty? Is my “retention policy” correct? It is neccessary?
I hope you guys can help me out here.
Thanks a lot in advance!
Chris