Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

cesaraccardi
Valued Contributor

QRS API - updating users custom properties

Hello,

I have defined a custom property "Department" and associated to apps/users for access control. I would like to automate the process of going to QMC and manually setting the "Department" values for each user. I believe this should be possible using QRS API but as I don't have much experience with the API am not sure how to do this.

I am using Postman and managed to retrieve the details of a given user as well as the custom properties associated:

Request

GET /qrs/user/2e04436f-a71a-45c5-999c-793a00ba6a77/?Xrfkey=ABCDEFG123456789 HTTP/1.1

Host: myserver

X-Qlik-Xrfkey: ABCDEFG123456789

Response

json get user by id.PNG

In this case User 1 is associated to Finance and Sales, now let's say I wanted to move it to Executive and Sales. Can I just update the value of "Finance" to "Executive"? I have tried sending a PUT request like below but it doesn't work (it gives a 409 Conflict error message). Does anybody know why?


PUT /qrs/user/2e04436f-a71a-45c5-999c-793a00ba6a77?Xrfkey=ABCDEFG123456789 HTTP/1.1

Host: myserver

X-Qlik-Xrfkey: ABCDEFG123456789

Content-Type: application/json

{

  "id": "2e04436f-a71a-45c5-999c-793a00ba6a77",

"customProperties": [

    {

      "id": "fb5e68ec-d382-4bd1-b9f3-81c5a5f1b3e1",

      "value": "Executive"

    }

  ]

}

Thanks in advance,

Cesar

1 Solution

Accepted Solutions
cesaraccardi
Valued Contributor

Re: QRS API - updating users custom properties

Hi,

I managed to get the update property working, in order to do this I have copied the JSON response of the GET user and changed the fields highlighted in green:

json update cp.png

So looks like in this case we need to provide the actual date and time to both the modifiedDate of the User as well as the property that is being changed.

I am not going to close this thread yet because I want to test add/removing properties as well.

Cesar

14 Replies
Not applicable

Re: QRS API - updating users custom properties

Hi Cesar,

As you noticed, I had the same kind of issue with updates => 409 Conflict.

I could solve it by sending the modifiedDate in the PUT body message to the actual date and hour.

The format of the is not important YYY-MM_DD HH:MMSmiley FrustratedS is good enought.


This might not be the only step to make it work, for other similar request, I then received 400 Bad Request due to invalid body content, I am still on it, each body structure depends on the object type, sending same structure as received with the GET method is not working in every case ...

Ghislain

Highlighted
cesaraccardi
Valued Contributor

Re: QRS API - updating users custom properties

Thanks for the reply Ghislain,

I will try adding the modifiedDate as you suggested and will come back later with the results.

Cesar

cesaraccardi
Valued Contributor

Re: QRS API - updating users custom properties

Hi,

I managed to get the update property working, in order to do this I have copied the JSON response of the GET user and changed the fields highlighted in green:

json update cp.png

So looks like in this case we need to provide the actual date and time to both the modifiedDate of the User as well as the property that is being changed.

I am not going to close this thread yet because I want to test add/removing properties as well.

Cesar

cesaraccardi
Valued Contributor

Re: QRS API - updating users custom properties

I managed to add/remove properties as well, the process is similar to updating. As long as the ModifiedDate is changed to an actual date and time it works fine.

Not applicable

Re: QRS API - updating users custom properties

The way I understand how Qlik works is that it will use modifiedDate for detecting dirty write situations. So when updating an entity in Qlik, you should pass the existing modifiedDate that you can fetch with GET qrs/user/full

cesaraccardi
Valued Contributor

Re: QRS API - updating users custom properties

I noticed that the modifiedDate is replaced by a "system"date after the request is processed so you don't need to send the exact date and time obtained with GET qrs/user/full apparently.

Not applicable

Re: QRS API - updating users custom properties

Hmm interesting. Where is it replaced and by whom? By Qlik? We've been monitoring all JSON traffic and I'm pretty sure you need to pass the exact same modifiedDate that was in Qlik repository before update. I'm not sure about the precision of the date though, if you add a couple of seconds to modifiedDate in PUT (compared to existing modifiedDate) I always get 409 conflict error.

cesaraccardi
Valued Contributor

Re: QRS API - updating users custom properties

Basically what I am doing is sending a GET qrs/user/{id}, copying the JSON, changing the parameters I want to update and setting the modifiedDate to actual date time (doing this manually, with a precision of minutes). Example:

Request:

"modifiedDate": "2016-03-10T14:49:18.684Z"

Response - 200 OK:

"modifiedDate": "2016-03-10T14:50:09.281Z"

Not applicable

Re: QRS API - updating users custom properties

We actually contacted Qlik, and they can reproduce the 409 issue.

They updated the documentation on this:

https://help.qlik.com/en-US/sense-developer/2.2/Subsystems/RepositoryServiceAPI/Content/RepositorySe...

"Many JSON structs in the Qlik Sense Repository Service (QRS) API include the modifiedDate property, which is used to avoid conflicts in the repository database. For example, when updating an entity, leave the modifiedDate property unchanged. If the modifiedDate property for the updated entity differs from the modifiedDate property for the entity in the QRS, there is a conflict (that is, the entity in the QRS has already been updated by someone else)."