Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
jjdench
Partner - Contributor III
Partner - Contributor III

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 (2)
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 - Contributor III
Partner - Contributor III
Author

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