Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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.
@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 😁
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/
also
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
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...
@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 😁
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
@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?
Hi @lauranvh
Have you looked at the link I have given you in my previous post. It has almost all methods in API covered...