A simple example of using INEXTIA API is by getting the first 50 components.
The example is based on that you do not have a token, and therefor need to get one first.
Two things must be done:
- First, get a token
- Then get the components by using the token.
A code example using PowerShell is shown below:
$postParams = @{"login"="<user>"; "password"="<password>"} | ConvertTo-Json;
$token = Invoke-WebRequest -Uri https://<sitename>.inextia.dk/api/Auth -ContentType "application/json" -Method POST -Body $postParams | ConvertFrom-Json;
$headers = @{
"Authorization" = "Bearer " + $token.accessToken;
"Content-Type" = "application/json; charset=utf-8";
}
$components = Invoke-WebRequest -Uri https://<sitename>.inextia.dk/api/Components?pageSize=50
-Method GET -Headers $headers;
Write-Output $components.Content | ConvertFrom-Json
<user> and <password> is replaced with the interface of the users actual login.
Likewise, <sitename> is replace with the actual INEXTIA site.
PageSize is only written to mention how many components which are to be returned.
There are a few conditions for the example above to work.
First, a user must be created for the purpose. The user must have access to read component data.
When running the example in PowerShell and everything works as expected, the list of components will be shown as text.
If it does not work, an error message will show. A reason why could for example be if the login information were invalid.
Read more about handling error messages in the next example
When wanting to get data for a specific component, this is done based on the component number.
$component = Invoke-WebRequest -Uri https://<sitename>.inextia.dk/api/Components/<no> -Method GET -Headers $headers;
Replace <no> with the actual component number.
Comments
0 comments
Article is closed for comments.