I’m trying to make a couple of simple “Hello world” queries with the Nintex RPA REST API.
The documentation examples use Postman, but that’s unavailable in my environment. So I’m trying to use Powershell instead.
My second API call, a graphql query to get the RPA version, is failing with “InvalidOperation”.
Here’s the code:
# Get Access Token:
$response = "XXX"
$uri = "http://MY_NINTEX_HOSTNAME/auth/realms/Kryon/protocol/openid-connect/token"
$contentType = "application/x-www-form-urlencoded" # Implicitly set to "application/x-www-form-urlencoded" for POST method calls
$formBody= @{
client_id="kryon-public-api"
grant_type="password"
username="MY_NINTEX_USER"
password="NINTEX_USER_PASSWORD"
}
$response = Invoke-RestMethod -Uri $uri -Method POST -ContentType $contentType -Body $formBody
$access_token = $response.access_token
#Write-Host "Get Access Token response: " $response
#Write-Host "access_token: " $access_token
# Get RPA Version:
$response = "XXX"
$uri = "http://MY_NINTEX_HOSTNAME/nintex-public-api/graphql"
$contentType = "application/json"
$httpHeaders = @{
"Authorization" = "Bearer $access_token"
"Accept" = "application/json"
"kryon-client-id" = "kryon-public-api"
"kryon-auth-provider" = "aerobase"
}
$formBody= @'
query {
getRpaServerVersion
}
'@
$response = Invoke-RestMethod -Uri $uri -Method POST -Headers $httpHeaders -ContentType $contentType -Body $formBody
Write-Host "Get RPA Version response: " $response
<= The first API call, “Get access token” works OK;
The next call, “Get RPA version” (GraphQL) call fails with this error:
+ $response = Invoke-RestMethod -Uri $uri -Method POST -Headers $httpHe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Get RPA Version response: XXX
Q: What am I doing wrong???
