Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have been following a document Publish by Qlik about how to use Qlik Nprinting API's inside a load script. Se attached. I have successfully managed to set up the rest connections and managed to get the code on Page 12 of the document to work properly as shown below.
//Connect to NPrinting using the GET REST Connection
LIB CONNECT TO 'NPrinting REST Login (qtsel_gpr)';
//Perform a GET call to NPrinting NTLM login API
RestConnectorMasterTable:
SQL SELECT
"Set-Cookie",
"__KEY__response_header"
FROM JSON "_response_header" PK "__KEY__response_header";
[_response_header]:
LOAD [Set-Cookie] AS [Set-Cookie]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__KEY__response_header]);
//Extracts session cookie from the API response
let vCookieRaw = Peek('Set-Cookie',0,'_response_header');
let vCookie = TextBetween('$(vCookieRaw)','Secure,','Path=/',2);
DROP TABLE RestConnectorMasterTable;
When the code runs it manages to get the RAW cookie data and store it in the variable vCookieRaw but it's not successfully extracting the session cookie data in the variable vCookie. The contents of the variable vCookieRaw I have listed below. I need to adjust some how the delimiters in the text between function to extract the session cookie. So I need figure out how to identify the session cookie in the raw cookie data so I can extract it.
'NPWEBCONSOLE_XSRF-TOKEN=2bUxAp2KHUi4J74pAZ3IuAnq8pApPqEQFrUkfCgVySE=; Path=/; Secure; SameSite=None,NPWEBCONSOLE_SESSION=fed51ec0a77ead9fd0f78fe4ca77124e0a2380a0-%00NPWEBCONSOLE_XSRF-TOKEN%3A2bUxAp2KHUi4J74pAZ3IuAnq8pApPqEQFrUkfCgVySE%3D%00%00_TS%3Asession%00; Path=/; HttpOnly; Secure; SameSite=None,NPWEBCONSOLE_XSRF-TOKEN=2HrcIdHCYx3Bib/sJV/GcWifpT0TspCbSacMtfuUUa0=; Path=/; Secure; SameSite=None,NPWEBCONSOLE_SESSION=6dd480d385aa1695a7cbbf87f20554958a4d429f-%00NPWEBCONSOLE_XSRF-TOKEN%3A2HrcIdHCYx3Bib%2FsJV%2FGcWifpT0TspCbSacMtfuUUa0%3D%00%00_TS%3Asession%00%00userid%3A4368b68a2ed54443bf0c7b85a76b3d4f%00%00userlogin%3A2025-05-26T07%3A12%3A19.3449016Z%00; Path=/; HttpOnly; Secure; SameSite=None'
@michasiuk have you looked at this post:
https://community.qlik.com/t5/Qlik-NPrinting/NPrinting-Task-Execution-call-using-Rest-API-throwing-4...
Looks like Lech answered this question possibly.
I had a look at the solution, but unfortunate it doesn't appear to be working for me. I did replace the comma(,) with a semi colon(;) and I managed to extract a session cookie out of the information this time but it doesn't appear to be the correct session cookie. I tried adjusting the last parameter in the test between function but I don't seem to be able to find the correct session cookie
let vCookie = TextBetween('NPWEBCONSOLE_XSRF-TOKEN=6hbt1My1sj72pnx6On/IFJLbVy2m1nc2qLEa3IClcL8=; Path=/; Secure; SameSite=None,NPWEBCONSOLE_SESSION=94be81b308c3bfc2f500d00cfb77d3ebb7da3ace-%00NPWEBCONSOLE_XSRF-TOKEN%3A6hbt1My1sj72pnx6On%2FIFJLbVy2m1nc2qLEa3IClcL8%3D%00%00_TS%3Asession%00; Path=/; HttpOnly; Secure; SameSite=None,NPWEBCONSOLE_XSRF-TOKEN=IoUMvOtN19/PKLBxtRJ2m/VOr9w3JA1KHNRjilsQcxo=; Path=/; Secure; SameSite=None,NPWEBCONSOLE_SESSION=e045c91f8d03ec3090174dd230ac87020c630396-%00NPWEBCONSOLE_XSRF-TOKEN%3AIoUMvOtN19%2FPKLBxtRJ2m%2FVOr9w3JA1KHNRjilsQcxo%3D%00%00_TS%3Asession%00%00userid%3A4368b68a2ed54443bf0c7b85a76b3d4f%00%00userlogin%3A2025-05-28T04%3A39%3A04.8790075Z%00; Path=/; HttpOnly; Secure; SameSite=None','Secure;','Path=/',2)
RestUserMasterTable:
SQL SELECT
"__KEY_data",
(SELECT
"id",
"email",
"__FK_items"
FROM "items" FK "__FK_items")
FROM JSON (wrap off) "data" PK "__KEY_data"
WITH CONNECTION( URL "https://Nprinting.Server:4993/api/v1/users", HTTPHEADER "cookie" " SameSite=None,NPWEBCONSOLE_XSRF-TOKEN=IoUMvOtN19/PKLBxtRJ2m/VOr9w3JA1KHNRjilsQcxo=; " )
14:39:06
Connected
14:39:07
RestConnectorMasterTable << RestConnectorMasterTable
Lines fetched: 1
14:39:15
_response_header << RestConnectorMasterTable
Lines fetched: 1
14:52:45
RestUserMasterTable << RestConnectorMasterTable
Script error: HTTP protocol error 403 (Forbidden):
The server refused to fulfill the request.
The following error occurred:
HTTP protocol error 403 (Forbidden):
The server refused to fulfill the request.
The error occurred here:
RestUserMasterTable:
SQL SELECT
"__KEY_data",
(SELECT
"id",
"email",
"__FK_items"
FROM "items" FK "__FK_items")
FROM JSON (wrap off) "data" PK "__KEY_data"
WITH CONNECTION( URL "https://Nprinting.Server:4993/api/v1/users", HTTPHEADER "cookie" " SameSite=None,NPWEBCONSOLE_XSRF-TOKEN=IoUMvOtN19/PKLBxtRJ2m/VOr9w3JA1KHNRjilsQcxo=; " )
I did some more research and came across an article How to use NPrinting APIs with Qlik REST Connector - Qlik Community - 1717126. This gave enough information to work with. I managed to figure out that Nprinting has changed the way it manages session cookies. I had to replace the line of code
let vCookie = TextBetween('$(vCookieRaw)','Secure;','Path=/',2);
with the following line of code to make things work
Let vCookie = SubField('$(vCookieRaw)',',',4); The session cookie that I extracted looks something like this
"NPWEBCONSOLE_SESSION=733bed0dea75f6a1c9c816b583b8d8fe51baebb8-%00NPWEBCONSOLE_XSRF-TOKEN%3AdYp3GrNFhWQNk2tTxt362YK02zkAtJL2UfCVm1w5C%2BI%3D%00%00_TS%3Asession%00%00userid%3A4368b68a2ed54443bf0c7b85a76b3d4f%00%00userlogin%3A2025-06-11T03%3A43%3A43.6158566Z%00; Path=/; HttpOnly; Secure; SameSite=None"
You have to split the raw cookie on the comma it appears with the later versions of nprinting.