Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Bo_PT
Contributor III
Contributor III

Question about QSR API

Hi,
 
I am implementing QSR API features with .NET SDK to start Qlik Sense task and assign user license. I followed instructions on this page: https://help.qlik.com/en-US/sense-developer/May2023/APIs/RepositoryServiceAPI/index.html?page=1753
 
The starting task part works well but the assigning license part does not. Here is my code:
 
public void DoWork(string qsserver, string taskid, string uid)
        {
            var restClient = new RestClient(qsserver);
            restClient.AsNtlmUserViaProxy();
 
            string taskinfo_json = restClient.Get("/qrs/reloadtask/" + taskid);
 
            System.Web.Script.Serialization.JavaScriptSerializer serializer =
                new System.Web.Script.Serialization.JavaScriptSerializer();
            QSTaskInfo qstaskInfo = serializer.Deserialize<QSTaskInfo>(taskinfo_json);
 
            string taskstatuscode = qstaskInfo.Operational.LastExecutionResult.Status;
    if ( taskstatuscode == "8")
            {
                   restClient.Post("/qrs/task/" + taskid + "/start");
            }
            /// The code above work well
 
    /// The following code do not work
            string body = "{";
            body += "\"user\":{";
            body += "\"id\":\"" + uid + "\"}";    //uid is in format like e85cbb9e-b4cd-40b6-9687-1e7a0dc0a5c3
            body += "}";          
 
    /// This line throws error: 404 bad content
            string result_json = restClient.Post("/qrs/license/analyzeraccesstype/", body);
        }
 
I am not sure what I missed or did wrong. Any help is appreciated.
 
Thanks
Labels (2)
1 Solution

Accepted Solutions
marksouzacosta
Partner - Specialist II
Partner - Specialist II

Hi @Bo_PT,

I think you are missing userId and userDirectory fields. I think they are required according to this reference:
https://help.qlik.com/en-US/sense-developer/May2023/APIs/RepositoryServiceAPI/index.html?page=1911

 

Read more at Data Voyagers - datavoyagers.net

View solution in original post

6 Replies
Øystein_Kolsrud
Employee
Employee

I'm afraid I'm not familiar with that particular endpoint, but I have some ideas about what you could look into:

  1. Are you sure you should use the POST endpoint? If you are assigning a new access, then perhaps you should be using a PUT endpoint instead?
  2. When updating an entity you often need to set the "modifiedDate" value as that is used to avoid conflict. If the "modifiedDate" value is smaller than the original value then it would be considered a conflict and you get an error. I think you typically get the "409 Conflict" in that case though and not a 404, but it could be worth to keep this in mind.
  3. Perhaps there's more info you need in that body? I see the properties of the "LicenseAnalyzerAccessType" structure are marked as "optional", but that doesn't necessarily mean that they are optional when calling a particular endpoint. I typically resort to reverse engineering the traffic in the QMC to resolve what is needed, but you can also try to simply define everything and see if that does the trick.
Øystein_Kolsrud
Employee
Employee

Another thing: I find that a rather nice way to define those bodies are to use the anonymous object type in C#. You can turn those into a JObject and then pass it on as a body. Like this:

var body = JObject.FromObject(new
{
user = new { id = uid }
});
restClient.Post("/qrs/license/analyzeraccesstype/", body);

That way you can avoid all that convoluted string concatenation. I find it's very easy to miss a bracket or comma or something when I use that approach.

Bo_PT
Contributor III
Contributor III
Author

HI,  Øystein_Kolsrud thanks for your reply and tips. I will try that.

Also I want to correct one typo error: The error I got is 400: bad request. (not 404).

marksouzacosta
Partner - Specialist II
Partner - Specialist II

Hi @Bo_PT,

I think you are missing userId and userDirectory fields. I think they are required according to this reference:
https://help.qlik.com/en-US/sense-developer/May2023/APIs/RepositoryServiceAPI/index.html?page=1911

 

Read more at Data Voyagers - datavoyagers.net
Bo_PT
Contributor III
Contributor III
Author

Thanks all for your reply. I haven't tried JObject thing yet but tried others. Here is the body part:

string body = "{";
body += "\"id\":\"" + uid + "\",";
body += "\"modifiedDate\":\"2024-08-14T04:56:07.000+00:00\",";
body += "\"user\":{";
body += "\"id\":\"" + uid + "\",";
body += "\"userId\":\"" + userid + "\",";
body += "\"userDirectory\":\"" + domainname + "\"}";
body += "}";

I still got 400 error.

Bo_PT
Contributor III
Contributor III
Author

It works now. It turned out that there is a special character in uid which was somehow generated during copy & paste. It looks like letter 'a' which is why I missed it. Normally this type of character is only generated by foreign language input method, which I do not have on my laptop. Not sure how this happened.

Id, userid and userDirectory must be set to make it work. Other properties are optional. Here is the working code with minimum properties:

string body = "{";
body += "\"user\":{";
body += "\"id\":\"" + uid + "\",";
body += "\"userId\":\"" + userid + "\",";
body += "\"userDirectory\":\"" + domainname + "\"}";
body += "}";

And JObject works too.

string uid = "<uid>";
string userid = "<userid>";
string udirectory = "<domainname>";

var body = JObject.FromObject(new
{
user = new { id = uid, userid = userid, userDirectory = udirectory }
});

Thanks again for everyone.