I am trying to get to grips with setting up a series of POST requests using Thunderclient in VSCode.
I have a cURL statement:
curl -X POST https://influxdburl/query
-u USERNAME:PASSWORD
-d "q=SELECT "value" AS "MyMeasurement" FROM "dbname"."autogen"."data"
WHERE time >= '2022-01-01T00:00:00Z' AND time < '2023-01-01T00:00:00Z'
AND "TagRef"='tagidentifier'"
which works fine, but I am unable to replicate the statement succcessfully in Thunderclient. I had thought to use the Import cURL functionality, but this fails because it does not import the credentials. Attempting to replicate the credentials elements of the statement in Thunderclient by stipulating the Username and Password content under Basic Authentication does not work, I get the error '407 Proxy Authentication Required'. However I can successfully interact with the database using a little Excel VBA test client that I knocked up, the code for which is:
Public Function GetData(ByVal ws As Worksheet, ByVal startTime, ByVal endTime, ByVal TagName As String) As String
Dim objrequest As Object
Dim strUrl As String
Dim blnAsync As Boolean
Dim strResponse As String
Dim token As String
Dim json As Object
Dim query As String
Set objrequest = CreateObject("MSXML2.XMLHTTP.6.0")
strUrl = ws.Range("url")
blnAsync = True
With objrequest
.Open "POST", strUrl, blnAsync
.setRequestHeader "Accept", "application/json"
'.setRequestHeader "Content-Type", "text/plain"
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.setRequestHeader "Authorization", "Basic " + Base64Encode("USERNAME" + ":" + "PASSWORD")
query = "q=SELECT ""Value"" AS ""MyMeasurement"" FROM ""dbname"".""autogen"".""lv_data"" WHERE TIME >= '" & startTime & "' AND time < '" & endTime & "' AND ""TagRef""='tagidentifier'"
.send query
'spin wheels whilst waiting for response
While objrequest.readyState <> 4
DoEvents
Wend
strResponse = Replace(.responseText, "\", "")
strResponse = Mid(strResponse, 2, Len(strResponse) - 1)
End With
GetData = strResponse
End Function
However, even this is not working correctly as if I change the content_type to ‘text/plain’ which I believe is really what I want, I get the error ":"missing required parameter "q""}’: returned. In order to get this to work I am forced to specify content_type as ‘application/x-www-form-urlencoded’. Any help would eb much appreciated.
Kind Regards Paul J.