Qlik Community

Qlik NPrinting Discussions

Discussion Board for collaboration on Qlik NPrinting.

Announcements
Coming your way, the Qlik Data Revolution Virtual Summit. October 27-29. REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Contributor III
Contributor III

NPrinting Task Execution call using Rest API throwing 403 Forbidden error

Hi,

We have recently migrated to NPrinting February 2020 SR1 version. Everything went smoothly and the server was up and running in no time. The only problem we are struggling to fix is the REST API calls to execute tasks.

API call to login URL is working i.e. https://nprinting_server/api/v1/login/ntlm

 

But all the other calls to URLs like the following giving me error "QVX_UNEXPECTED_END_OF_DATA: HTTP protocol error 403 (Forbidden)."  

https://nprinting_server/api/v1/users or 

https://nprinting_server/api/v1/tasks/430133d4-7ce7-4418-96f2-ef4112339d4b/executions

 

Script code that I am using is as below:

Please note that vCookie requires a little change after upgrade i.e. replace comma(,) with a semicolon(;) after the word Secure


let vCookie = TextBetween('$(vCookieRaw)','Secure;','Path=/',2);

let vPublshTaskURL = 'https://nprinting_server/api/v1/tasks/430133d4-7ce7-4418-96f2-ef4112339d4b/executions';

RestNPTaskTriggerTable:
SQL SELECT
"__KEY_data"
FROM JSON (wrap off) "data" PK "__KEY_data"
WITH CONNECTION( URL "$(vPublshTaskURL)", HTTPHEADER "cookie" "$(vCookie)");
[_post_items]:
LOAD [__KEY_data] AS [__KEY_data]
RESIDENT RestNPTaskTriggerTable
WHERE NOT IsNull([__KEY_data]);
DROP TABLE RestNPTaskTriggerTable;
Server throwing error:

QVX_UNEXPECTED_END_OF_DATA: HTTP protocol error 403 (Forbidden):
The server refused to fulfill the request.

I have checked the roles for user I am using to create the REST connection, which a domain user and has the Administrator role, everything looks alright.

 

Is there any configuration I need to make on Nprinting server to allow resources to be used from other servers?

Any suggestions to resolve the issue?

 

Thanks,

JM

Labels (2)
1 Solution

Accepted Solutions
Highlighted

I guess you are not inspecting/ tracing on each step what your script is doing. 

I faced the same issue after upgrade however code i am using is tracing all variables i capture on the way. I noticed that cookie was not returned as the structure of the string after authentication has changed!

You need to adjust your code to capture cookie - see red bit of the code below.

You can also see Trace statements below which straight away helped me identify this issue!


    //  Extracts session cookie from the API response

            Let vCookieRaw  = Peek('Set-Cookie',0,'cookie_items');
            Let vCookie     = TextBetween('$(vCookieRaw)','SameSite=None,','Path=/',2);

            DROP TABLE RestConnectorMasterTable;

    //  Trace

            Trace   ---;
            Trace   Raw Session Cookie: "$(vCookieRaw)";
            Trace   Truncated Session Cookie: "$(vCookie)";

 

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.

View solution in original post

6 Replies
Highlighted

I guess you are not inspecting/ tracing on each step what your script is doing. 

I faced the same issue after upgrade however code i am using is tracing all variables i capture on the way. I noticed that cookie was not returned as the structure of the string after authentication has changed!

You need to adjust your code to capture cookie - see red bit of the code below.

You can also see Trace statements below which straight away helped me identify this issue!


    //  Extracts session cookie from the API response

            Let vCookieRaw  = Peek('Set-Cookie',0,'cookie_items');
            Let vCookie     = TextBetween('$(vCookieRaw)','SameSite=None,','Path=/',2);

            DROP TABLE RestConnectorMasterTable;

    //  Trace

            Trace   ---;
            Trace   Raw Session Cookie: "$(vCookieRaw)";
            Trace   Truncated Session Cookie: "$(vCookie)";

 

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.

View solution in original post

Highlighted
Contributor III
Contributor III

Hi,

I did trace the variables and outputs but didn't get the idea of removing the SameSite=None from the Cookie id as the API documentation are not updated. 

Our code was working fine with the earlier version of NPrinting i.e Sept 2018.

Appreciate your support and help.

Thanks,

JM

Highlighted

Hi,

I am glad I could help.

I was also blindsided,  but then I went to Qlik download page and checked documentation. This change was highlighted in release notes as a change to cookie.

If you preview cookies in your web browser you would notice which bits are necessary.

Capture.PNG

cheers

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.
Highlighted
Contributor III
Contributor III

Lech,

I tried your solution, but it's not working for me - I'm getting a protocol error 500 now. 

Here's my two variables (I changed the variable names slightly):

let vNPCookieRaw = Peek('Set-Cookie',0,'_response_header');
let vNPCookie = TextBetween('$(vNPCookieRaw)','SameSite=None,','Path=/',2);

Here's the resulting text (from a trace):

vNPCookie = 'NPWEBCONSOLE_SESSION=ac61db90490f70b1da9ae39b3c7f3d5ae4a0c6b7-%00NPWEBCONSOLE_XSRF-TOKEN%3AALEfIIvxiMe82JtSi3AUoe0ZU5dDKIjhP%2BLvCBr2qBc%3D%00%00_TS%3Asession%00%00userid%3Aad3f1e18086040a39f6b094fde386016%00%00userlogin%3A2020-03-28T17%3A02%3A09.1431719Z%00; '

The following error occurred:
HTTP protocol error 500 (Internal Server Error): An unhandled exception occurred; check the log for more information.
 
The error occurred here:
RestNPTaskTriggerTable: SQL SELECT "__KEY_data", "id", "task", "status" FROM JSON (wrap off) "data" PK "__KEY_data" WITH CONNECTION( URL "https://<masked>.<masked>.com:4993/api/v1/tasks/f407413e-93cd-49e6-9864-6602a0044528/executions", HTTPHEADER "cookie" "NPWEBCONSOLE_SESSION=e05a0f599c17e87bea77db6c73fac4994605847f-%00NPWEBCONSOLE_XSRF-TOKEN%3ASm%2FENNSoBUQVu0KE4zbt9ck1kPx%2BxfXypwZRtqzaQfo%3D%00%00_TS%3Asession%00%00userid%3Aad3f1e18086040a39f6b094fde386016%00%00userlogin%3A2020-03-28T16%3A56%3A45.8676365Z%00; ")

 

Any idea what I'm doing wrong?

 

Contributor III
Contributor III

Wow, I feel dumb.  I realized that the NPrinting task I was trying to run had been disabled.  Once I enabled the task, the following code worked:

let vNPCookieRaw = Peek('Set-Cookie',0,'_response_header');
let vNPCookie = TextBetween('$(vNPCookieRaw)','SameSite=None,','Path=/',2);

Highlighted
Contributor II
Contributor II

Hi,

Thanks for this info. 

I was trying your solution but it seems something else is going wrong. As you see in my raw session cookie TextBetween('$(vCookieRaw)','SameSite=None,','Path=/',2) won't work as 'SameSite=None,' only comes once in whole string.

Is my raw cookie wrong ?

 

Raw Session Cookie:

"NPWEBCONSOLE_SESSION=7803373bd0a0e6a9ab3fb6a87e2fc8933aede485-%00_TS%3Asession%00%00NPWEBCONSOLE_XSRF-TOKEN%3AVK7fJ59JPWsnmn9vJ89JoCkxGeO8V1IHh0o3eccyc1w%3D%00; Path=/; HttpOnly; Secure; SameSite=None,NPWEBCONSOLE_SESSION=5454317aee4bdce61ae0d9de0ad9399eef193fcc-%00_TS%3Asession%00%00NPWEBCONSOLE_XSRF-TOKEN%3AVK7fJ59JPWsnmn9vJ89JoCkxGeO8V1IHh0o3eccyc1w%3D%00%00userid%3A9f88adfb825a4eb19178e0dc2c4ca312%00%00userlogin%3A2020-08-07T10%3A16%3A15.1375265Z%00; Path=/; HttpOnly; Secure; SameSite=None"

Truncated Session Cookie:

"NPWEBCONSOLE_SESSION=5454317aee4bdce61ae0d9de0ad9399eef193fcc-%00_TS%3Asession%00%00NPWEBCONSOLE_XSRF-TOKEN%3AVK7fJ59JPWsnmn9vJ89JoCkxGeO8V1IHh0o3eccyc1w%3D%00%00userid%3A9f88adfb825a4eb19178e0dc2c4ca312%00%00userlogin%3A2020-08-07T10%3A16%3A15.1375265Z%00; "