Hello everyone,
i need to query a database influxDB and i'm using Postman successfully, making an http request with the following parameters:
endpointUrl = "https://mydomain.com:8086/api/v2/query?org=myorg"
body:
from(bucket: "example-buket")
|> range(start: -1h)
|> filter(fn: (r) => r["_measurement"] == "meteo_garden")
|> filter(fn: (r) => r["_field"] == "METEO_GardenWS_AH.PV")
Header:
Accept: application/csv
Content-type: application/vnd.flux
Authorization: Token l3uZ4CVH_...........................................................41t5K6PHuYalg==
Now i'm trying to use B4X with okHTTP, but my request is not compiled and i get an error message. This is my code:
I'm almost sure i'm parsing the body in a wrong way .... the errore message i get is the following
{"code":"invalid","message":"compilation failed: error @1:6-1:20: invalid expression @1:20-1:21: '\n\nerror @1:15-1:20: invalid expression @1:14-1:15: '\n\nerror @3:14-3:59: invalid expression @3:59-3:60: '\n\nerror @3:25-3:42: invalid expression @3:40-3:41: '\n\nerror @3:28-3:40: invalid expression @3:27-3:28: '\n\nerror @3:46-3:47: invalid expression: invalid token for primary expression: ILLEGAL\n\nerror @3:47-3:59: invalid expression @3:46-3:47: '\n\nerror @4:14-4:61: invalid expression @4:61-4:62: '\n\nerror @4:25-4:36: invalid expression @4:34-4:35: '\n\nerror @4:28-4:34: invalid expression @4:27-4:28: '\n\nerror @4:40-4:41: invalid expression: invalid token for primary expression: ILLEGAL\n\nerror @4:41-4:58: invalid expression @4:40-4:41: '"}
Can anyone help me? Thank you very much in advance!
i need to query a database influxDB and i'm using Postman successfully, making an http request with the following parameters:
endpointUrl = "https://mydomain.com:8086/api/v2/query?org=myorg"
body:
from(bucket: "example-buket")
|> range(start: -1h)
|> filter(fn: (r) => r["_measurement"] == "meteo_garden")
|> filter(fn: (r) => r["_field"] == "METEO_GardenWS_AH.PV")
Header:
Accept: application/csv
Content-type: application/vnd.flux
Authorization: Token l3uZ4CVH_...........................................................41t5K6PHuYalg==
Now i'm trying to use B4X with okHTTP, but my request is not compiled and i get an error message. This is my code:
influxDB connection:
Sub Globals
Dim endpointUrl As String = "https://mydomain.com:8086/api/v2/query?org=myorg"
' Dim Body As String = $"from(bucket: 'example-buket')
' |> range(start: -1h)
' |> filter(fn: (r) => r['_measurement'] == 'meteo_garden')
' |> filter(fn: (r) => r['_field'] == 'METEO_GardenWS_AH.PV')"$
Dim Body As String = "from(bucket: 'example-buket')\r\n |> range(start: -2d)\r\n |> filter(fn: (r) => r['_measurement'] == 'meteo_garden')\r\n |> filter(fn: (r) => r['_field'] == 'METEO_GardenWS_AH.PV')\r\n"
Dim authCode As String = "Token l3uZ4CVH_...................41t5K6PHuYalg==" '<- Put your auth code here
End Sub
'
Sub Activity_Create(FirstTime As Boolean)
Dim ok As HttpJob
ok.Initialize("",Me)
ok.PostString(endpointUrl, body)
ok.GetRequest.SetContentType("application/vnd.flux")
ok.GetRequest.SetHeader("Authorization", authCode)
ok.GetRequest.SetHeader("Content-Type", "application/vnd.flux")
ok.GetRequest.SetHeader("Accept", "application/csv")
'
Wait For (ok) Jobdone(ok As HttpJob)
If ok.Success Then
Log("Success")
Log(ok.GetString)
Else
Log("FAiled")
Log(ok.ErrorMessage)
End If
ok.Release
End Sub
I'm almost sure i'm parsing the body in a wrong way .... the errore message i get is the following
{"code":"invalid","message":"compilation failed: error @1:6-1:20: invalid expression @1:20-1:21: '\n\nerror @1:15-1:20: invalid expression @1:14-1:15: '\n\nerror @3:14-3:59: invalid expression @3:59-3:60: '\n\nerror @3:25-3:42: invalid expression @3:40-3:41: '\n\nerror @3:28-3:40: invalid expression @3:27-3:28: '\n\nerror @3:46-3:47: invalid expression: invalid token for primary expression: ILLEGAL\n\nerror @3:47-3:59: invalid expression @3:46-3:47: '\n\nerror @4:14-4:61: invalid expression @4:61-4:62: '\n\nerror @4:25-4:36: invalid expression @4:34-4:35: '\n\nerror @4:28-4:34: invalid expression @4:27-4:28: '\n\nerror @4:40-4:41: invalid expression: invalid token for primary expression: ILLEGAL\n\nerror @4:41-4:58: invalid expression @4:40-4:41: '"}
Can anyone help me? Thank you very much in advance!