In Qlik Cloud, it's possible to use OAuth authentication to call Qlik Cloud APIs.
This article explains how to verify that the OAuth client setup has been done correctly by requesting the OAuth token manually to perform the API call.
Details regarding how to set up the OAuth client are available on qlik.dev:
Steps:
- Request the OAuth token using the client ID and client secret:
$hdrs = @{}
$token_endpoint='https://xxx.ap.qlikcloud.com/oauth/token'
$clientid='bcefef34f5a6eexxxxxx2d19'
$clientsecret='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
$body = @{ client_id=$clientid
client_secret=$clientsecret
grant_type="client_credentials"
}|ConvertTo-Json -Compress
$response = Invoke-WebRequest -Uri $token_endpoint -Method Post -Body $body -Headers $hdrs -ContentType 'application/json'
echo $response.Content
The following response is returned:
{"access_token":"eyJhbGciOiJFUzM4NCIsI....bSht2erUewkKzixaVVn6W1OOXpHlHGAGmiY9cb_obw1FyJ9egEIErjW3cZPdZ3GAfgrQy_NnQg6g1a6lO5y8vhdKj5-zM7RhTXpzPxpzUfeDwBvy
yj9c3MclcMp1IfDx","token_type":"bearer","expires_at":"2023-09-06T08:29:58.000Z","expires_in":21600}
Extract the access_token for use in the next step.
-
Call an API endpoint to ensure the token is working:
$hdrs = @{}
$hdrs.Add("Authorization","Bearer eyJhb...hC1fTY4v3OAyj8Ef6SUQft6-Gd8e86o-NHeprBh19HBK5aBzyFUjlhUSSo8OO4DVieTsKryvCNbBSYEP4NNdgfBKXPmNH1EtbpehAku9rXXbFwPYNH27iinCStlR8W")
$url = "https://xxx.ap.qlikcloud.com/api/v1/users"
Invoke-RestMethod -Uri $url -Method Get -Headers $hdrs
Environments:
Qlik Cloud