QlikProfessionalServices / QlikNPrinting-CLI

Qlik NPrinting CLI - PowerShell Module to work with NPrinting
MIT License
9 stars 1 forks source link

NPrinting API could not update the proxyURL #3

Closed Kev-kutkin closed 2 years ago

Kev-kutkin commented 2 years ago

the NPrinting-Cli could not update the Proxy URL My aim is to use the NPrinting-Cli to update the existing proxy URL by using Powershell scripting. However, the API called could not have any impact on the proxy URl even I have refreshed the site (as shown below). nprinting_update

The powershell script that I use is shown below. $id = "4fa2i..." $name="Test Connection" $appID="05296ea0-..." `Connect-NPrinting -TrustAllCerts $Data= @{id=$id}; name=$$name;qlikSenseConnection=@{navigator="qliksense";proxyUrl="https://ntqlk10";appId=$appId}} Invoke-NPRequest -NPE -Path connections -method Put -Data $Data

I am using NPrinting May 2021 version. I hope anyone could advice me further.

Nillth commented 2 years ago

the code sample provided is not valid PowerShell. specifically you are closing the Hashtable, then trying to add more properties to it.

$Data= @{id=$id}; name=$$name;qlikSenseConnection=@{navigator="qliksense";proxyUrl="https://ntqlk10";appId=$appId}} should be

$Data = @{id=$id; name=$name; qlikSenseConnection=@{navigator="qliksense"; proxyUrl="https://ntqlk10"; appId=$appId}}

also when you "Put" you need to specify the Object ID that you are attempting to update in the URI. Invoke-NPRequest -NPE -Path connections -method Put -Data $Data should be Invoke-NPRequest -NPE -Path "connections/$($id)" -method Put -Data $Data

for future reference when providing code samples please review creating and highlighting code blocks

Nillth commented 2 years ago

you do not need to use the NPE (Private Endpoint) to update a data connection as there is now a Supported Public API to do this on newer versions of NPrinting.

In the following examples update the variables $ProxyToChange & $newProxy with your environment values. It is assumed that the account you are logged in with that is running the PowerShell session will be able to authenticate using windows credentials to the NPrinting API's if not you will need to adapt the Connect-NPrinting command to suit your environment.

Using the supported API.

$ProxyToChange = "https://sense01/"
$newProxy = "https://qsense01/"

Connect-NPrinting -TrustAllCerts
$AllNPConnections = Invoke-NPRequest connections
#This needs to be manually set as it is not returned by the get request
$applyUserSectionAccess = $False

$UpdateConnections = $AllNPConnections|Where-Object{$_.connectionString.Contains("proxyurl=$($ProxyToChange)")}

foreach ($connection in $UpdateConnections){
    $Connectionconfig = $connection.connectionString.Replace("\","\\") -split ';'|ConvertFrom-StringData
    #https://help.qlik.com/en-US/nprinting/May2021/APIs/NP+API/index.html?page=113
    $qlikSenseConnection = @{
        proxyUrl=$newProxy
        appId=$Connectionconfig.appID
        identity=$Connectionconfig.identity
        applyTheme=$Connectionconfig.applytheme
        applyUserSectionAccess=$applyUserSectionAccess 
    }

    #https://help.qlik.com/en-US/nprinting/May2021/APIs/NP+API/index.html?page=85
    $DataConnectionRequest = @{
        id=$connection.id
        name=$connection.name
        description=$connection.description
        appId=$connection.appId
        source=$connection.source
        qlikSenseConnection=$qlikSenseConnection
        notificationsEnabled=$connection.notificationsEnabled
    }

    #https://help.qlik.com/en-US/nprinting/May2021/APIs/NP+API/index.html?page=20
    Invoke-NPRequest -Path "connections/$($connection.id)" -method Put -Data $DataConnectionRequest -Verbose
}

Using the Unsupported NPE API


$ProxyToChange = "https://sense01/"
$newProxy = "https://qsense01/"

Connect-NPrinting -TrustAllCerts
$AllNPConnections = Invoke-NPRequest -NPE connections 
$UpdateConnections = $AllNPConnections.list|Where-Object{$_.qlikSenseConnection.proxyUrl -eq $ProxyToChange}

foreach ($connection in $UpdateConnections){
    $connection.qlikSenseConnection.proxyUrl = $newProxy
    Invoke-NPRequest -NPE "connections/$($connection.id)" -method Put -Data $connection
}