A simple example of using the SERTICA API is retrieving the first 50 components.
This example assumes that no token has been retrieved yet, so that will be the first step.
There are therefore two steps involved:
- Retrieve a token.
Use the token to fetch components.
Below is a code example using PowerShell:
$postParams = @{"login"="<user>"; "password"="<password>"} | ConvertTo-Json;
$token = Invoke-WebRequest -Uri https://<sitename>.sertica.com/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>.sertica.com/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 replaced with the actual SERTICA 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>.sertica.com/api/Components/<no> -Method GET -Headers $headers;Replace <no> with the actual component number.
Comments
0 comments
Article is closed for comments.