Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Jun 1, 2021 2:59:54 PM
Jun 21, 2018 8:29:19 AM
How can one connect to the Nprinting API via Powershell, such as in cases when using a REST client such as Postman isn't possible?
Environments:
Connecting to the NPrinting API is documented on our help site, in the section Extending Qlik Nprinting.
Connecting to the Nprinting API is done in the following steps:
Here is some example code that (1) Logs in to Nprinting as the user executing the script, (2) makes a GET request to retrieve the first task, and (3) makes a POST request to execute said task.
# Set TLS to minimum 1.1 for Nprinting Feb 2018, using 1.2 in this example [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # Authenticate and get cookie $url = "https://YOUR-NPRINTING-SERVER:4993/api/v1/login/ntlm" Invoke-RestMethod -UseDefaultCredentials -Uri $url -Method Get -Headers $hdrs -SessionVariable websession $cookies = $websession.Cookies.GetCookies($url) $session = New-Object Microsoft.PowerShell.Commands.WebRequestSession $session.Cookies.Add($cookies); # Extract XSRF token from cookie $xsrf_token = $($cookies | Where-Object {$_.Name -eq "NPWEBCONSOLE_XSRF-TOKEN"}).Value # Get list of tasks in Nprinting $hdrs = @{} $hdrs.Add("X-XSRF-token",$xsrf_token) $url = "https://YOUR-NPRINTING-SERVER:4993/api/v1/tasks" $tasks = $(Invoke-RestMethod -WebSession $session -Uri $url -Method Get -Headers $hdrs).data.items # Pick an arbitrary task (first one) and execute it $taskid = $tasks[0].id $url = "https://YOUR-NPRINTING-SERVER:4993/api/v1/tasks/$($taskid)/executions" Invoke-RestMethod -WebSession $session -Uri $url -Method Post -Headers $hdrs
Note: Debugging or writing custom code is supported by the Qlik Professional Services or Presales teams. This example is provided for demonstration purposes to explain specific scenarios. No Support or maintenance is implied or provided. Further customization is expected to be necessary and it is the responsibility of the end administrator to test and implement an appropriate implementation for their specific use case.