Qlik Community

Qlik NPrinting Discussions

Discussion Board for collaboration on Qlik NPrinting.

davwade1
New Contributor II

users/{id}/roles body parameter

I am trying to update my Nprinting user roles from within a Qlik Sense script. I have been successful with GET and POST, but am stuck on the required BODY parameters when adding roles to a user. I read the other post about this topic but it was not helpful for me. I confirmed that the userId and roleID being used are accurate and active.

Here is what my script looks like now -( I changed the server names and cookie to protect the innocent 😉 );

UpdateUser:
SQL SELECT
"__KEY_data"
FROM
JSON (wrap off) "data" PK "__KEY_data"
WITH CONNECTION
(
URL "https://server.domain.com:4993/api/v1/users/1ed5d811-a345-52ce-ba8e-4dd6723f65905/roles", BODY """a4882700-d42a-4703-906c-d6104b0d012a""",
HTTPHEADER "Origin" "https://senseserver.domain.com",
HTTPHEADER "Content-Type" "application/json",
HTTPHEADER "X-HTTP-Method-Override" "PUT",
HTTPHEADER "cookie" "longcookiestring; "
);

I have tried several things for the body, but they all return an error about malformed body.

Can someone please help me out and tell me what to put between the 2 double quotes after BODY? Thanks

FYI - Nprinting version is 19.19.4.0, QS Enterprise version is Feb 2019 and my QS REST connector is version 2.11.0

Below were all failures:

BODY "a4882700-d42a-4703-906c-d6104b0d012a"

BODY ""a4882700-d42a-4703-906c-d6104b0d012a""

BODY "'a4882700-d42a-4703-906c-d6104b0d012a'"

BODY "["a4882700-d42a-4703-906c-d6104b0d012a"]"

Labels (1)
1 Solution

Accepted Solutions
Support
Support

Re: users/{id}/roles body parameter

Hi @davwade1 

See attached QVF from one of my colleagues. 

In any case, this comes with a caveat and should be used as is...there is no guarantee of it's success in your environment ... but it may guide you to the answers you need.

  • The QVF (attached) contains code that pulls in Users/Roles from the QS Repository and assigns appropriate roles within NPrinting. I have highlighted the tabs relevant to Role assignment.
  • Note: I was unable to create new roles using this script. However, I was able to assign users to existing NP roles.

Hope this helps...if not, hopefully someone else will provide a response here for you that will be helpful.

Have a good weekend...

 

 

We are just 'like' you & like to be liked when we provide a helpful answer and or when you press the 'Solution Accepted' button if an answer provided resolves your question or issue... Cheers!

View solution in original post

8 Replies
Support
Support

Re: users/{id}/roles body parameter

Hi @davwade1 

Please check the following article: https://support.qlik.com/articles/000059611

It contains information about validating the version of the rest connector, and mentions QS April 2019 or later versions that contain the defect fixed version of the rest connection along with other requirements. (copy pasting the connector may not work. Using the QS installation server program will ensure it is installed correctly.)

If you still have an issue after checking the above article and steps there in I would suggest starting a support ticket with Qlik or your Qlik Support partner.

Kind regards...

We are just 'like' you & like to be liked when we provide a helpful answer and or when you press the 'Solution Accepted' button if an answer provided resolves your question or issue... Cheers!
davwade1
New Contributor II

Re: users/{id}/roles body parameter

Frank,

Thanks for the quick response. Our QS Feb 2019 is at patch 4 and has the "good" REST connector 2.11.0. I read the article and can confirm that the Trusted origin is setup and we are using a windows service account that has admin rights on both the QS and Nprinting applications. We have used the API with POST to reload metadata for connections, so I feel good that the setup is working correctly.

I was hoping that I just overlooked something obvious about the BODY syntax.

Support
Support

Re: users/{id}/roles body parameter

@davwade1 

Good point re: QS Feb 2019 patch 4. I've updated the article I mentioned accordingly. I check other working code. 

Check out the following:

  • Instead of BODY "["a4882700-d42a-4703-906c-d6104b0d012a"]"
  • Try BODY '{"a4882700-d42a-4703-906c-d6104b0d012a"}'

Regards...

We are just 'like' you & like to be liked when we provide a helpful answer and or when you press the 'Solution Accepted' button if an answer provided resolves your question or issue... Cheers!
davwade1
New Contributor II

Re: users/{id}/roles body parameter

Thanks, but it did not like these options either.

BODY '{"a4882700-d42a-4703-906c-d6104b0d012a"}',

Connector reply error: Unknown substring, string, or value at (7,108): ''{"a4882700-d42a-4703-906c-d6104b0d'

I also tried double quotes with the curly brackets and got a similar error:

BODY "{"a4882700-d42a-4703-906c-d6104b0d012a"}",

Connector reply error: Unknown substring, string, or value at (7,119): '-d42a-4703-906c-d6104b0d012a"}",'

Support
Support

Re: users/{id}/roles body parameter

@davwade1 

I've put the word out to my colleagues.

In the meantime, just check the role GUID again as shown in the image below:

role GUID.PNG

We are just 'like' you & like to be liked when we provide a helpful answer and or when you press the 'Solution Accepted' button if an answer provided resolves your question or issue... Cheers!
davwade1
New Contributor II

Re: users/{id}/roles body parameter

OK. I confirmed the IDs for the role and user. They are correct.

I'll keep my fingers crossed that one of your colleagues has done battle with this API in the past. Thanks

And not to be greedy...but it looks like the API will allow multiple roles to be passed in during one call (because the API Reference mentions roleIDs (plural)). So it would also be great to get the syntax for passing multiple roles as I will definitely need to do that.

Thanks again.

Support
Support

Re: users/{id}/roles body parameter

Hi @davwade1 

See attached QVF from one of my colleagues. 

In any case, this comes with a caveat and should be used as is...there is no guarantee of it's success in your environment ... but it may guide you to the answers you need.

  • The QVF (attached) contains code that pulls in Users/Roles from the QS Repository and assigns appropriate roles within NPrinting. I have highlighted the tabs relevant to Role assignment.
  • Note: I was unable to create new roles using this script. However, I was able to assign users to existing NP roles.

Hope this helps...if not, hopefully someone else will provide a response here for you that will be helpful.

Have a good weekend...

 

 

We are just 'like' you & like to be liked when we provide a helpful answer and or when you press the 'Solution Accepted' button if an answer provided resolves your question or issue... Cheers!

View solution in original post

davwade1
New Contributor II

Re: users/{id}/roles body parameter

WOOHOO!! That did it!! I had a copy of v1 of that qvf (it did not contain the role stuff).

Thanks so much for all your help today. I REALLY appreciate it. Have a great weekend.

let vRoleID = '024a9f15-70ef-45c9-a473-df4580fcdb1a,c3501700-d42a-4703-906c-d6104b0d012a,bde92144-4b8b-4382-a675-6b25afa63c54,ae214d96-1455-498d-a8da-061f159ce9ba,af6b14bb-96d9-4569-ba1f-da8eaaa10f09,ee907ad7-52ce-420c-bbd8-3b4b77df48cc,61a74a24-7ced-4318-8b0d-7571a82c3de9,feaa01d3-b6ac-422a-bd7a-f28a59149065,c511834a-2cb9-416e-b11c-d9a15303da06';

LET vUserRoleBody = '[""' & replace(vRoleID,',',chr(34) & chr(34)&','&chr(34) & chr(34)) & '""]' ;

UpdateRoles:
SQL SELECT
"__KEY_data"
FROM
JSON (wrap off) "data" PK "__KEY_data"
WITH CONNECTION
(
URL "$(vURL)", BODY "$(vUserRoleBody)",
HTTPHEADER "Origin" "$(vQlikSenseServer)",
HTTPHEADER "Content-Type" "application/json",
HTTPHEADER "X-HTTP-Method-Override" "PUT",
HTTPHEADER "cookie" "$(vCookie)"
);

For everyone playing along at home this is what the BODY part of the call looked like: 

BODY "[""024a9f15-70ef-45c9-a473-df4580fcdb1a"",""c3501700-d42a-4703-906c-d6104b0d012a"",""bde92144-4b8b-4382-a675-6b25afa63c54"",""ae214d96-1455-498d-a8da-061f159ce9ba"",""af6b14bb-96d9-4569-ba1f-da8eaaa10f09"",""ee907ad7-52ce-420c-bbd8-3b4b77df48cc"",""61a74a24-7ced-4318-8b0d-7571a82c3de9"",""feaa01d3-b6ac-422a-bd7a-f28a59149065"",""c511834a-2cb9-416e-b11c-d9a15303da06""]" ,