Skip to main content
Announcements
Defect acknowledgement with Nprinting Engine May 2022 SR2, please READ HERE
cancel
Showing results for 
Search instead for 
Did you mean: 
Huberto
Creator
Creator

How to get the user id created by the Qlik NPrinting POST Users REST API inside a Qlik Sense load script

Dear Qlik NPrinting experts,

 

My goal with this post is to know how to get the user id created by the Qlik NPrinting POST Users REST API method inside a Qlik Sense load script.

Environment:

Qlik Sense: May 2023 SR4

Qlik NPrinting: May 2023 SR1

I followed the instructions documented in the How to use Qlik NPrinting APIs inside a Qlik Sense load script post created by @Gianluca_Perin and the user creation via Qlik Sense load script implementing Qlik NPrinting REST APIs worked perfectly well. Although my new user is created as expected, I need to know why I don't get the user id returned to my Qlik Sense script.

I followed the documentation above and the table remains empty after creating the user.

Here is my Qlik Sense script and the data connection configuration is also attached:

 

/*** lOGIN ***/
LIB CONNECT TO 'REST_NPrinting_GET';

//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);

let vCookieRaw = Peek('Set-Cookie',0,'_response_header');
let vCookie = TextBetween('$(vCookieRaw)', 'SameSite=None,', 'Path=/', 3);


DROP TABLE RestConnectorMasterTable;

//----------------------------------------------------------------

/*** CREATE USER ***/
LIB CONNECT TO 'REST_NPrinting_POST';

set vBody = '{"Username":"UserA","Email":"usera@qlik.com","Password":"123","Enabled":"true","Folder":"","Subfolder":"","DomainAccount":"","Timezone":"Europe/Berlin","Locale":"en"}';
let vBody = replace(vBody,'"', chr(34)&chr(34));

set vPostUserULR = 'https://mynprintingserver:4993/api/v1/users';
set vQSServer = 'https://myqliksenseserver';


RestNPPOSTandPUTTestTable:
SQL SELECT
	"__KEY_data"
FROM JSON (wrap off) "data" PK "__KEY_data"
WITH CONNECTION( URL "$(vPostUserULR)", BODY "$(vBody)",
HTTPHEADER "Origin" "$(vQSServer)",
HTTPHEADER "Content-Type" "application/json",
HTTPHEADER "cookie" "$(vCookie)");

// [post_and_put_items]:
// LOAD [__KEY_data] AS [__KEY_data]
// RESIDENT RestNPPOSTandPUTTestTable
// WHERE NOT IsNull([__KEY_data]);

// DROP TABLE RestNPPOSTandPUTTestTable;

 

 

It would be really great if anyone could shed some light on this issue.

 

Thanks in advance.

 

Best regards,

 

Huberto Pereira Haidemann

Labels (1)
17 Replies
Frank_S
Support
Support

@JonnyPoole @Lech_Miszkiewicz 

Thoughts?

Please remember hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Lech_Miszkiewicz
Partner Ambassador/MVP
Partner Ambassador/MVP

My guess is that wording used in API documentation is not ideal and does not represent what actually happens. Indeed documentation says:

"Adds a user.

Adds a new user, and returns its ID."

however what is not mentioned is that that ID is actually not part of the response and to obtain it you need to run another call.

Lech_Miszkiewicz_0-1717025046896.png

I have nothing else to add to it - I am basing my whole limited knowledge about this around the existing documentation and what I can make from it.

@JonnyPoole - what is your take on this?

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.
JonnyPoole
Former Employee
Former Employee

It could be an issue with the documentation. We can check. @Ruggero_Piccoli .

In the meantime, following your POST, you can use the REST Connector to issue a GET to the /users endpoint and filter on 'username' (or 'email') which are both primary keys in the user repository and values that you already have in your POST. The /users GET call *will* issue a response containing the novel user's userID value. 

 

JonnyPoole_0-1717038295187.png

 

Ruggero_Piccoli
Support
Support

Hi,

The ID of the created user is returned:

Ruggero_Piccoli_0-1717073961985.png

 

Ruggero_Piccoli_1-1717074093656.png

Best Regards,

Ruggero



Best Regards,
Ruggero
---------------------------------------------
When applicable please mark the appropriate replies as CORRECT. This will help community members and Qlik Employees know which discussions have already been addressed and have a possible known solution. Please mark threads with a LIKE if the provided solution is helpful to the problem, but does not necessarily solve the indicated problem. You can mark multiple threads with LIKEs if you feel additional info is useful to others.
Frank_S
Support
Support

@Huberto See above comments from @Ruggero_Piccoli @Lech_Miszkiewicz @JonnyPoole 

Please remember hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Huberto
Creator
Creator
Author

Hi @Frank_S,

Thank you @Ruggero_Piccoli@Lech_Miszkiewicz, and @JonnyPoole for taking the time for the investigation. However, I have to say that the replies did not answer my question because I am calling the Qlik NPrinting API from the Qlik Sense script, it is a Qlik Sense/Qlik NPrinting integration that I am working on. Although the tests with Postman seemed to work as designed (the POST method returned user id), I can't say the same about the Qlik Sense script.

 

My question is: does the Qlik NPrinting POST Users REST API method used inside a Qlik Sense load script return the user id?

Can anyone show me an example using the Qlik Sense script? So far I haven't seen any.

 

Thank you once again for your time.

 

Regards,

Huberto

Frank_S
Support
Support

@Huberto 

I had another look at your load script.

It appears to be incorrect (from your original post)

let vCookieRaw = Peek('Set-Cookie',0,'_response_header');
let vCookie = TextBetween('$(vCookieRaw)', 'SameSite=None,', 'Path=/', 3);

should be

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

 

https://community.qlik.com/t5/Official-Support-Articles/Qlik-Sense-June-2020-connecting-to-NPrinting...

 

Although you are not getting the error in the article however you do need to update the 'let' syntax.

Also double check that your get (and post) rest connections are set up correctly to ensure end to end success.

Check in to that and let us know.

As far as providing specific code, perhaps others here can assist you with that.

(you may wish to check this community post/white page as well. It is for use 'as is' and is quite old now. If you need assistance developing your requirement, you may wish to consider working with a trusted partner or arrange a professional services engagement with Qlik Professional Services. https://community.qlik.com/t5/Qlik-NPrinting/How-to-use-Qlik-NPrinting-APIs-inside-a-Qlik-Sense-load...)

Please remember hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Ruggero_Piccoli
Support
Support

Hi @Huberto 

I divided the question in two steps. The first returns the User ID so we can go ahead with the second. I'm trying to create a working example of the reload script that creates the user.

Best Regards,

Ruggero



Best Regards,
Ruggero
---------------------------------------------
When applicable please mark the appropriate replies as CORRECT. This will help community members and Qlik Employees know which discussions have already been addressed and have a possible known solution. Please mark threads with a LIKE if the provided solution is helpful to the problem, but does not necessarily solve the indicated problem. You can mark multiple threads with LIKEs if you feel additional info is useful to others.