[CmdletBinding()] Param( # Keycloak Server [ValidateNotNullOrEmpty()] $Keycloak_Server = 'https://keycloak-acc-bp-weu.roser-ict.com', # ClientID From Keycloak [ValidateNotNullOrEmpty()] $ClientID = 'BP_Rotterdam', # ClientSecret From Keycloak [ValidateNotNullOrEmpty()] $ClientSecret = 'a2bb4f34-d415-4cba-807f-c68a41b9cb3c', # Keycloak Realm [ValidateNotNullOrEmpty()] $Realm='BP_Rotterdam' ) $VerbosePreference='continue' # Example Powershell Code for connecting to the API and retrieving supported languages $APIswagger = 'https://api-acc-bp-weu.roser-ict.com/api/welding/swagger.yml' $APIlanguages = 'https://api-acc-bp-weu.roser-ict.com/api/configuration/languages' $APIwelding = 'https://api-acc-bp-weu.roser-ict.com/api/welding/report' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 if(-not $ClientSecret) { Write-Error 'Please configure $ClientSecret' -ErrorAction STOP } $RequestURL = $Keycloak_Server + "/auth/realms/$Realm/protocol/openid-connect/token" $body = @{ grant_type='client_credentials' client_id=$ClientID client_secret=$ClientSecret } # Token Request $result = Invoke-WebRequest -Method POST -Uri $RequestURL -ContentType "application/x-www-form-urlencoded" -Body $body $Content = $result.Content | ConvertFrom-Json $Params = @{ "URI" = $APIswagger "Method" = 'GET' "Headers" = @{ "Content-Type" = 'application/json' "Authorization" = "Bearer $($Content.access_token)" } } $Swagger = Invoke-RestMethod @Params Write-Output $Swagger $Params = @{ "URI" = $APIlanguages "Method" = 'GET' "Headers" = @{ "Content-Type" = 'application/json' "Authorization" = "Bearer $($Content.access_token)" } } Invoke-RestMethod @Params $Params = @{ "URI" = $APIwelding "Method" = 'POST' "Headers" = @{ "Content-Type" = 'application/json' "Authorization" = "Bearer $($Content.access_token)" } } Invoke-RestMethod @Params -Verbose $Params.Method = 'GET' $WelditReports = Invoke-RestMethod @Params -Verbose write-output "Received $($WelditReports.Count) Reports"