One of the most used examples in INEXTIA API is the update of counter values.
This is due to that, for example, a SCADA system already knows the values. Therefor it is advantageous to use it in the maintenance planning.
The API is also used for automatic counter readings in INEXTIA.
The example below assumes that you do not have a token, and therefore must get one first.
After getting the token, a new counter reading is inserted on a specific counter.
The code example below is from PowerShell:
$postParamsAuth = @{"login"="<user>"; "password"="<password>"} | ConvertTo-Json;
$token = Invoke-WebRequest -Uri https://<sitename>.inextia.dk/api/Auth -ContentType "application/json" -Method POST -Body $postParamsAuth | ConvertFrom-Json;
$headers = @{
"Authorization" = "Bearer " + $token.accessToken;
"Content-Type" = "application/json; charset=utf-8";
}
$postParamsCounter = @{"value"=<value>; "valuedate"="<date>"} | ConvertTo-Json;
Invoke-WebRequest -Uri https://<sitename>.inextia.dk/api/counters/<no>/readings -Method POST -Body $postParamsCounter -Headers $headers;
<user> and <password> is replaced with the interface user’s login details.
<sitename> is replaced with the actual INEXTIA site.
<value> is replaced with the value wanted for the counter.
<valuedate> is replaced with today’s date. The format is “yyyy-mm-dd”.
<no> is replaced with the number (ID) of the counter that is getting updated.
There are different conditions for the above-mentioned example to work.
The user needs to have access to update the counter. Furthermore, the counter must exist. The date for the new reading must be later than the last reading. The value must be higher than the last reading.
If the reading is inserted correctly, the StatusCode 200 will return.
If it does not return, the error message will describe what went wrong.
The code example below will find the error, if there is one, and print it:
$postParamsCounter = @{"value"=<value>; "valuedate"="<date>"} | ConvertTo-Json;
try{
Invoke-WebRequest -Uri https://<sitename>.inextia.dk/api/counters/<no>/readings -Method POST -Body $postParamsCounter -Headers $headers;
}
Catch{
$streamReader = [System.IO.StreamReader]::new($_.Exception.Response.GetResponseStream())
$errorJson = $streamReader.ReadToEnd()
$streamReader.Close()
Write-Output $errorJson
}
The counter readings that has already been inserted can be viewed by using this code:
$readings = Invoke-WebRequest -Uri https://<sitename>.inextia.dk/api/counters/<no>/readings -Method GET -Headers $headers;
Write-Output $readings.Content | ConvertFrom-Json
Comments
0 comments
Article is closed for comments.