Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW

How to use NPrinting APIs with Qlik REST Connector

No ratings
cancel
Showing results for 
Search instead for 
Did you mean: 
Sonja_Bauernfeind
Digital Support
Digital Support

How to use NPrinting APIs with Qlik REST Connector

Last Update:

Aug 13, 2021 3:48:39 PM

Updated By:

Frank_S

Created date:

Sep 11, 2017 9:01:35 AM

Attachments

If you have upgraded Qlik Sense recently and are having REST connection failures, please visit the following articleQlik Sense June 2020 connecting to NPrinting getting "HTTP protocol error 403 (Forbidden): The serve... 

Qlik Sense April 2019 release contains the required rest connector v2.11 which resolves a previous software defect affecting versions after 1.3 and up to 2.10

Note: The Qlik Rest connectors are not supported for use where kerberos authentication is present. See details here: Feature Request: Qlik REST connector should be able to support connections to server with Kerberos a...


The following only works in specific versions of Qlik Sense and NPrinting. Please check with a Qlik Integrations/Development support engineer with any questions.
The Qlik Sense/View Rest connector is required to be manually updated to version 1.3.

  • Download and extract the appropriate Rest Connector for either QlikView or Qlik Sense v1.3 (will be available with the NPrinting Feb. 2018 release).
  • Backup the Existing Rest connector file folder
  • Copy the extracted files to the existing rest connection installation files folder
  • Reboot the server where the installation files are copied to.

When using Qlik Sense REST connector to connect to NPrinting APIs, the connector may show error “Failed to connect to server” or “HTTP protocol error 403 (Forbidden): The server refused to fulfill the request” , although the same API call works in web browsers or Postman.

According to NPrinting reference page at http://help.qlik.com/en-US/nprinting/June2017/APIs/NP%20API/, API users need to call method GET /login/ntlm to authenticate themselves first. This will create a cookie for subsequent calls in the same session. However, unlike web browsers or API tools like Postman, Qlik Sense REST connector does not save this session cookie automatically for subsequent calls.

Resolution:

A workaround is to manually save the cookie after the first authentication call, then add the cookie as a query header in the REST Connector configuration.The following article presents an example for how this can be achieved:


1.   NPrinting API only supports Windows NTLM authentication

Ref: http://help.qlik.com/en-US/nprinting/November2017/Content/Extending/Intro-Extending.htm

In Qlik Sense, when Qlik REST Connector is configured with Windows Authentication, the connector always uses credentials of the Qlik Sense service account. Therefore, the first step is to create an NPrinting user associated with the Qlik Sense service account and grant necessary roles to this user.


User-added image

 

2.  Create a REST Connector with the following configuration:
User-added image

3. Open the Select data dialog of the newly created REST connector.

Check option “Include HTTP response header” and select response field “Set-Cookie”. Insert the generated script to the app.

User-added image

Field “Set-Cookie” contains 3 cookies returned by NPrinting Server as a single string when GET /login/ntlm is called. The string should look like the following:

 
NPWEBCONSOLE_XSRF-TOKEN=V2pQHt7kUuzI4A+oe28rbyVgIyXMY8gyCdKupWjslng=; Path=/; Secure,
NPWEBCONSOLE_SESSION=86e4bf552e79e4c1d0acf898a1d8e1fe10029cc4-%00NPWEBCONSOLE_XSRF-TOKEN%3AV2pQHt7kUuzI4A%2Boe28rbyVgIyXMY8gyCdKupWjslng%3D%00%00_TS%3Asession%00; Path=/; HttpOnly; Secure,
NPWEBCONSOLE_SESSION=02cf571338171b5f04195cb4c02ca95cf7ee60d6-%00NPWEBCONSOLE_XSRF-TOKEN%3AV2pQHt7kUuzI4A%2Boe28rbyVgIyXMY8gyCdKupWjslng%3D%00%00_TS%3Asession%00%00userid%3A0d1021800b6f4ea78c478bef82a3c6f2%00; Path=/; HttpOnly; Secure

 
In which, the third cookie (highlighted in yellow, without cookie properties Path, HTTP, Secure) is needed for subsequent API calls. This cookie can be extracted from the string using any string manipulation technique in Qlik Sense. For example, the following script extract the cookie into variable vCookie:
 

let vCookieRaw = Peek('Set-Cookie',0,'_response_header');
let vCookie = TextBetween('$(vCookieRaw)','Secure,','Path=/',2);

 

(in this example, ‘_response_header’ is the name of the table generated by the REST connector in step 3)

4.  The extracted cookie can then be used as a query header in subsequent API calls.

This can be done either by creating a new REST connection, or overriding the current REST connection using WITH CONNECTION keyword.

  • New REST connection: create a new REST Connector to the API url that needs to be called. Create a query header named “cookie” and paste the cookie string in step (3) as the value

    User-added image
  • If you don’t want to create another REST connector, you can use WITH CONNECTION keyword to override the URL and query header of the existing connector created in step (2). For example:
     

 

SQL SELECT
"totalItems",
"offset",
"limit",
"__KEY_data",
(SELECT
"id",
"name",
"description",
"created",
"lastUpdate",
"__FK_items"

FROM "items" FK "__FK_items")
FROM JSON (wrap off) "data" PK "__KEY_data"
WITH CONNECTION(
URL "https://qlikserver6:4993/api/v1/apps",
HTTPHEADER "cookie" "$(vCookie)"
);

 


Please refer to the attached qvf app for an example.

Related Information:

Labels (1)
Version history
Last update:
‎2021-08-13 03:48 PM
Updated by: