Qlik Community

Ask a Question

Qlik NPrinting Discussions

Discussion Board for collaboration on Qlik NPrinting.

Announcements
May 18th, Changes to the way you login: using email vs. username. READ DETAILS/WATCH VIDEO
cancel
Showing results for 
Search instead for 
Did you mean: 
lauranvh
Partner
Partner

NPrinting REST API User Import problem - Malformed request

Hello,

I have a problem with the importing of users with the NPrinting REST API. I keeps giving me the same error. Malformed Request. I'll show some of the error and the code in here
The request is through the Qlik Sense Rest connector and there is some code 

lauranvh_0-1620127794021.png

RestNPPOSTandPUTTestTable:
SQL SELECT
"__KEY_data"
FROM JSON (wrap off) "data" PK "__KEY_data"
WITH CONNECTION( URL "https://win-lr9hsnaels0:4993/api/v1/users", BODY "{""Username"":""gkjhguy hguvkh"",""Email"":""gkjhguy@gmail.com"",""Password"":""123456"",""Enabled"":""Yes"",""Folder"":"""",""Subfolder"":"""",""DomainAccount"":"""",""Timezone"":""Europe/Amsterdam"",""Locale"":""En""}",
HTTPHEADER "Origin" "https://win-817i8f3iff9.qlik.testenvironment",
HTTPHEADER "Content-Type" "application/json",
HTTPHEADER "cookie" "NPWEBCONSOLE_SESSION=59800a636c2ce5f56b070c76b50658ca538782c2-%00userlogin%3A2021-05-04T11%3A31%3A04.3118216Z%00%00NPWEBCONSOLE_XSRF-TOKEN%3AJ52m4veZyAerzxeC%2BUs9ccPnuLswHfrjEyFgcvpdZnw%3D%00%00_TS%3Asession%00%00userid%3A86221fb97d104e16870713d992444f88%00")


I can't tell what is going wrong. I read somewhere that the domain account, folder and subfolder should be filled but that doesn't do the trick.

 

Labels (2)
1 Solution

Accepted Solutions
lauranvh
Partner
Partner
Author

@Lech_Miszkiewicz  and @Frank_S thank you for the replies. I had everything working via REST. (Getting a log-in cookie, refreshing metadata, publishing a task and checking the status for the metadata and publish task. Except for the creation of the user.

I was testing everything once more and got the answer for my question. In my post request I send a "Enabled: Yes" in the body. This is wrong and should be "Enabled: True". 
I think this is an oversight in the REST connector because when importing via Excel this is allowed. 

My problem is solved 😁

View solution in original post

7 Replies
Lech_Miszkiewicz

Without looking at your code an connection settiongs it is hard to say what you do wrong.

here you have link to subroutines which do that:

https://nprintingadventures.com/2019/04/08/nprinting-api-qlik-rest-subroutines/

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.
Lech_Miszkiewicz

also

  • are you trying to import new user or update existing one?
  • if update you need to use PUT method
  • if create new - do you connect to Lib POST connection?
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.
Frank_S
Support
Support

@lauranvh 

It sounds like you have some setup questions but also consider that there have been issues with the Qlik Sense rest connector that impact NPrinting. (It's not clear from your tags which version of Qlik Sense you are running).

So first, regarding setup requirements:

1. make sure your NP service account used in the load script is a member of the administrators role on the NP server and that your domain account used as the NP serviced account is mapped inside the properties pages of that user in the

  • "NPrinting web console Admin>Users>NP service account"> domain account (field)
  • "NPrinting web console Admin>Users>NP service account">Roles (tab)

2. Ensure your Qlik Sense server Virtual Proxy address (and alias URL's) are added to the "trusted origins" on the Settings page in the NP web console.

For more information on setup requirements see:

https://community.qlik.com/t5/Knowledge-Base/NPrinting-API-Setup-Requirements/ta-p/1715507

 

Kind regards...

We are just 'like' you and like to be liked when providing a helpful answer. You may also press the 'Solution Accepted' button if an answer provided resolves your question or issue... Cheers!
lauranvh
Partner
Partner
Author

@Lech_Miszkiewicz  and @Frank_S thank you for the replies. I had everything working via REST. (Getting a log-in cookie, refreshing metadata, publishing a task and checking the status for the metadata and publish task. Except for the creation of the user.

I was testing everything once more and got the answer for my question. In my post request I send a "Enabled: Yes" in the body. This is wrong and should be "Enabled: True". 
I think this is an oversight in the REST connector because when importing via Excel this is allowed. 

My problem is solved 😁

View solution in original post

Lech_Miszkiewicz

great - I am glad you got it figuerd.

In my script I handle this as follows:

// GET USERS FROM XLS

SUB XLS_GetUsers

XLS_Users:
LOAD
RowNo()-1 as XLS_User_RowId,
[E-mail] as XLS_User_Email,
Username as XLS_User_Name,
Password as XLS_User_Password,
[Domain Account] as XLS_User_DomainAccount,
If(Enabled like 'yes' or Enabled like 'true',true(),false()) as XLS_User_IsEnabled,
[Time Zone] as XLS_User_TimeZone,
Locale as XLS_User_Locale,
Nickname as XLS_User_NickName,
Title as XLS_User_Title,
Company as XLS_User_Company,
[Job Title] as XLS_User_JobTitle,
Department as XLS_User_Department,
Office as XLS_User_Office,
Filters as XLS_User_Filters,
Groups as XLS_User_Groups,
Roles as XLS_User_Roles,
Folder as XLS_User_Folder,
SubFolder as XLS_User_SubFolder
FROM
$(vConnection_XLS)\Recipients.xlsx
(ooxml, embedded labels, table is Users)
Where
Username <> '$(vNPrintingAdmin)'
;

ENDSUB

// CREATE USERS FROM XLS - This procedure creates all users from XLS (except ADMIN - admin defined as a variable(s))

SUB NP_CreateUpdateUsers(vCreateNewUsers)

IF '$(vCreateNewUsers)' = 'Yes' then

Call XLS_GetUsersFOR Each vUserRowId in FieldValueList('XLS_User_RowId');

// create user

LIB CONNECT TO '$(vConnection_POST)';

// setup user attributes

Let vUsername = CHR(34) & Peek('XLS_User_Name' ,$(vUserRowId),'XLS_Users') & CHR(34);
Let vEmail = CHR(34) & Peek('XLS_User_Email' ,$(vUserRowId),'XLS_Users') & CHR(34);
Let vPassword = CHR(34) & Peek('XLS_User_Password' ,$(vUserRowId),'XLS_Users') & CHR(34);
Let vEnabled = CHR(34) & Peek('XLS_User_IsEnabled' ,$(vUserRowId),'XLS_Users') & CHR(34);
Let vFolder = CHR(34) & Peek('XLS_User_Folder' ,$(vUserRowId),'XLS_Users') & CHR(34);
Let vSubfolder = CHR(34) & Peek('XLS_User_SubFolder' ,$(vUserRowId),'XLS_Users') & CHR(34);
Let vDomainAccount = Replace(CHR(34) & Peek('XLS_User_DomainAccount' ,$(vUserRowId),'XLS_Users') & CHR(34),'\','\\');
Let vTimezone = CHR(34) & Peek('XLS_User_TimeZone' ,$(vUserRowId),'XLS_Users') & CHR(34);
Let vLocale = CHR(34) & Peek('XLS_User_Locale' ,$(vUserRowId),'XLS_Users') & CHR(34);

// create json BODY

set vUserBody = '{"Username":$(vUsername),"Email":$(vEmail),"Password":$(vPassword),"Enabled":$(vEnabled),"Folder":$(vFolder),"subFolder":$(vSubfolder),"domainAccount":$(vDomainAccount),"timezone":$(vTimezone),"Locale":$(vLocale)}';
Trace $(vUserBody);
let vUserBody = replace(vUserBody,'"', chr(34)&chr(34));

// trigger request

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

DROP TABLE RestNPPOSTandPUTTestTable;
NEXT

Drop Table XLS_Users;

ENDIF

ENDSUB

 

 

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.
lauranvh
Partner
Partner
Author

@Lech_Miszkiewicz thank you for the script.

Do you also add groups and roles to the created users and maybe have a example for that?

Lech_Miszkiewicz

Hi @lauranvh 

Have you looked at the link I have given you in my previous post. It has almost all methods in API covered... 

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.