Qlik Community

Integration, Extension & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

Announcements
IMPORTANT security patches for GeoAnalytics Server available to download: READ DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
jjdench
Partner
Partner

Using Qlik-cli and powershell for app reloads in SAAS

Has anyone created a powershell script to trigger a reload in Qlik Sense SAAS, or is anyone able to point me in the direction of a working example. Wanting to reload app's at intervals less than an hour.

i can reload an app via qlik-cli but would like to put the commands into a single powershell command

Labels (5)
1 Solution

Accepted Solutions
Levi_Turner
Employee
Employee

Here's an example of the technique:

# Define your tenant URL
$tenant = Get-Content -Path .\qcs-tenant.txt
# Define your API key
$apikey = Get-Content -Path .\qcs-api_key.txt

# Define app
$appId = 'd4cf7dc5-88d5-447c-8dd6-a57264d59e2a'

$hdrs = @{}

# Add in the API key to the headers from the qcs-api_key.txt file
$hdrs.Add("Authorization","Bearer $($apikey)")

# Write appId into the Body for reload request
$bodyLines = '{"appId":"'
$bodyLines += $appId
$bodyLines += '"}'

# Get the App Information
$app = Invoke-RestMethod -Uri "https://$($tenant)/api/v1/apps/$($appId)" -Method Get -Headers $hdrs

# Send the reloads request to QCS
$request = Invoke-RestMethod -Uri "https://$($tenant)/api/v1/reloads" -Body $bodyLines -Method Post -Headers $hdrs

Write-Host "Beginning reload of $($app.attributes.name)"

# If the request was created or queued then poll execution for completion
if($request.status -eq 'CREATED' -or 'QUEUED') {
    # Signal reload request success
    Write-Host "Reload Request created for $($app.attributes.name)"
    # Poll every 10 seconds to see if the reload has completed.
    # Valid status values are CREATED, QUEUED, RELOADING, SUCCEEDED, FAILED
    do {
        $reloadStatus = Invoke-RestMethod -Uri "https://$($tenant)/api/v1/reloads/$($request.id)" -Method Get -Headers $hdrs
        Start-Sleep -Seconds 10
    } until ($reloadStatus.status -eq 'SUCCEEDED' -or $reloadStatus.status -eq 'FAILED')
    # Log on success
    Write-Host "Reload of $($app.attributes.name) finished with status $($reloadStatus.status)"
} else {
    Write-Host "Reload Request Failed for $($app.attributes.name)"
}

 

View solution in original post

2 Replies
Levi_Turner
Employee
Employee

Here's an example of the technique:

# Define your tenant URL
$tenant = Get-Content -Path .\qcs-tenant.txt
# Define your API key
$apikey = Get-Content -Path .\qcs-api_key.txt

# Define app
$appId = 'd4cf7dc5-88d5-447c-8dd6-a57264d59e2a'

$hdrs = @{}

# Add in the API key to the headers from the qcs-api_key.txt file
$hdrs.Add("Authorization","Bearer $($apikey)")

# Write appId into the Body for reload request
$bodyLines = '{"appId":"'
$bodyLines += $appId
$bodyLines += '"}'

# Get the App Information
$app = Invoke-RestMethod -Uri "https://$($tenant)/api/v1/apps/$($appId)" -Method Get -Headers $hdrs

# Send the reloads request to QCS
$request = Invoke-RestMethod -Uri "https://$($tenant)/api/v1/reloads" -Body $bodyLines -Method Post -Headers $hdrs

Write-Host "Beginning reload of $($app.attributes.name)"

# If the request was created or queued then poll execution for completion
if($request.status -eq 'CREATED' -or 'QUEUED') {
    # Signal reload request success
    Write-Host "Reload Request created for $($app.attributes.name)"
    # Poll every 10 seconds to see if the reload has completed.
    # Valid status values are CREATED, QUEUED, RELOADING, SUCCEEDED, FAILED
    do {
        $reloadStatus = Invoke-RestMethod -Uri "https://$($tenant)/api/v1/reloads/$($request.id)" -Method Get -Headers $hdrs
        Start-Sleep -Seconds 10
    } until ($reloadStatus.status -eq 'SUCCEEDED' -or $reloadStatus.status -eq 'FAILED')
    # Log on success
    Write-Host "Reload of $($app.attributes.name) finished with status $($reloadStatus.status)"
} else {
    Write-Host "Reload Request Failed for $($app.attributes.name)"
}

 

jjdench
Partner
Partner
Author

Thanks for that @Levi_Turner I'll have a go at this now!