I was able to get data from an Azure database and put it into a Perspective Table in Ignition but I'm having trouble formatting the Post into the database. When I successfully do it through Postman, there's quite a few headers that it adds and I'm not sure which ones are required by system.net.httpClient() if any.
With the code below, I get a 415 – Unsupported Media Type error.
'https://TEST-api.azurewebsites.net/datapoints?point=Temp&unit=1X&system=System+X§or=175X&value=87.6×tamp=2023-07-21T01%3A00%3A00.053Z' [415]>
TagList = {
"system": "System X",
"sector": "175X",
"unit": "1X",
"point": "Temp",
"value": 87.6,
"timestamp": "2023-07-21T00:00:00.053Z"
}
client = system.net.httpClient()
url = self.parent.parent.getChild("FlexContainer_datapoints_URL").getChild("TextField").props.text
Response = client.post(url, TagList, username="admin", password="!%^$!")
I thought the TagList object would be converted to JSON but if I try to add the Content-Type Header I do then get the 400 – Bad Request error.
'https://TEST-api.azurewebsites.net/datapoints?point=Temp&unit=1X&system=System+X§or=175X&value=87.6×tamp=2023-07-21T01%3A00%3A00.053Z' [400]>
SentHeaders = {'Content-Type': 'application/json'}
Response = client.post(url, TagList, headers = SentHeaders, username="adc_admin", password="!%^$!")
The working Post in Postman shows a lot more request headers and so on but I'm not sure what else the Ignition post function requires to work. Token, Cookie?
POST https://TEST-api.azurewebsites.net/datapoints
200
747 ms
Network
Request Headers
Content-Type: application/json
Authorization: Basic wwQ0gzMExAJCE=
User-Agent: PostmanRuntime/7.32.3
Accept: */*
Postman-Token: 4147c0625
Host: [TEST-api.azurewebsites.net](http://TEST-api.azurewebsites.net/)
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 153
Cookie: ARRAffinity=625456a57; ARRAffinitySameSite=625456a5791
Request Body
{
"system": "System X",
"sector": "175X",
"unit": "1X",
"point": "Temp",
"value": 87.6,
"timestamp": "2023-07-21T00:00:00.053Z"
}
Response Headers
Content-Length: 0
Date: Sat, 22 Jul 2023 15:20:33 GMT
Server: Microsoft-IIS/10.0
Request-Context: appId=cid-
X-Powered-By: [ASP.NET](http://asp.net/)