Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Need a sample code to do a PUT request with QRS API for updating User Accesses

Can someone provide a sample code for using a PUT method in C#.Net?
How to do the structuring of a nested element in GET request to read the response?
For Eg:

"tags": [

        {

            "id": ".......................ID Value.................",

            "name": "TagName",

            "privileges": null

        }

For reading the above response in JSON, how to write a class for the inner attributes of Tag attribute?

Currently this is how I am able to read the other properties:

            public string id { get; set; }

            public string userId { get; set; }

            public string userDirectory { get; set; }

            public string name { get; set; }

            public string privileges { get; set; }

            public string schemaPath { get; set; }

3 Replies
Øystein_Kolsrud
Employee
Employee

This project contains code for executing POST methods. PUT should be analogous: Qlik Branch

It uses the method WebClient.UploadString Method (System.Net) to do the post. There is an overload for that method that I believe can be used to do a PUT instead.

For serialization and deserialization of JSON I would recommend going with some standard library. Here is one example: Deserialize an Object

Anonymous
Not applicable
Author

Hi yko Thanks for replying.

I went through the project you have attached.

I am using HttpWebRequests and I am trying to fire a PUT request with a JSON body that is required for updating the information of a user. Whenever I am doing a PUT request. I am seeing two errors on it. The error and the exceptions are as follow:
1.) A GET request has to be made in order to make a PUT request(as the resolution I applied a GET method before the PUT method and I used the same HttpWebRequest object to modify the call as PUT but that is getting stuck on an exception that says “System.InvalidOperationException” )

2.) System.InvalidOperationException is not letting me add a request body with a PUT request.

3.) Parameters being provided with the requests are Method, Accept(Content-Type), Headers(Xrfkey), client issued certificate, X-Qlik-User(userDirectory and userId), writing the request stream with stream.write(jsonData, 0, jsonData.Length)


Any quick suggestion w.r.t will be appreciated.

Øystein_Kolsrud
Employee
Employee

I'm no expert on the HttpWebRequest class, but I think you need to be careful when reusing the same request object multiple times. There are some caveats there:

.net - Am I able to reuse a HttpWebRequest? - Stack Overflow

I personally find the WebClient class to be easier to work with as it provides some useful abstractions on top of the requests that fit well with for instance Qliks REST APIs.

Your observation on having to do a "GET" before doing a "PUT" is correct though. When you do the first Get, you will get a cookie from Qlik that is used for authentication, and that cookie needs to be included in any following non-get operations. I actually had that flow automated in that project I linked to, but realized that I never pushed my fix. Thanks for pointing that out!