Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Not applicable

Unable to get targetId from QPS ticket response

Based on blog:

http://qlikcommunity.qliktech.com/blogs/qlikviewdesignblog/2014/12/08/tickets-in-qlik-sense

I make the json request as:

  string body = "{ 'UserId':'" + user + "','UserDirectory':'" + userdirectory + "','Attributes': []," + " 'TargetId':'cd4805f4-e25f-436a-847e-8e82208fb1e0'}";

cd4805f4-e25f-436a-847e-8e82208fb1e0 being the app i want redirect to.

However the response is only:

{ "Userid: user", "UserDirectory: userdirectory" }

Why the targetid is not showing like in the blog example??

Also i would like to know where to get proxy urls ( ie. /hub) in the format like the appid in this example is.

Tags (1)
6 Replies
akl
Honored Contributor

Re: Unable to get targetId from QPS ticket response

First check out the documentation at https://help.qlik.com/sense/en-us/developer/ which has tons of great samples of the APIs.

How are you authenticating your requests? Are the certificates in place? XRF key injected into the header?

The QPS url would be https://<servername>:4243/qps/<virtual proxy if your are using one>/ticket?xrfkey=<XRF key which mat...

Check out this snippet which should give you some clues, https://gist.github.com/mindspank/4f93cac0c484cda3c500

Not applicable

Re: Unable to get targetId from QPS ticket response

I am authenticating with C# thus:

1. // get certificate

private X509Certificate2 certificate_ { get; set; }

public string TicketExampleCertificate()

        {

            // First locate the Qlik Sense certificate

            X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);

            store.Open(OpenFlags.ReadOnly);

            certificate_ = store.Certificates.Cast<X509Certificate2>().FirstOrDefault(c => c.FriendlyName == "QlikClient");

            store.Close();

            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

      

        }

2. // Get the Qlik ticket

public string TicketRequest2(string method, string server, string user, string userdirectory, string redirecturl)

        {

            //Create URL to REST endpoint for tickets

            string url = "https://" + server + ":4243/qps/ticket";

            //Create the HTTP Request and add required headers and content in Xrfkey

            string Xrfkey = "0123456789abcdef";

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + "?Xrfkey=" + Xrfkey);

            // Add the method to authentication the user

            request.ClientCertificates.Add(certificate_);

            request.Method = method;

            request.Accept = "application/json";

            request.Headers.Add("X-Qlik-Xrfkey", Xrfkey);

            string body = "{ 'UserId':'" + user + "','UserDirectory':'" + userdirectory + "','Attributes': []," + " 'TargetId':' " + redirecturl + "'}";

            byte[] bodyBytes = Encoding.UTF8.GetBytes(body);

            if (!string.IsNullOrEmpty(body))

            {

                request.ContentType = "application/json";

                request.ContentLength = bodyBytes.Length;

                Stream requestStream = request.GetRequestStream();

                requestStream.Write(bodyBytes, 0, bodyBytes.Length);

                requestStream.Close();

            }

            // make the web request and return the content

            try

            {

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                Stream stream = response.GetResponseStream();

                return stream != null ? new StreamReader(stream).ReadToEnd() : string.Empty;

            }

            catch (WebException ex)

            {

                using (var stream = ex.Response.GetResponseStream())

                using (var reader = new StreamReader(stream))

                {

                    Console.WriteLine(ex.ToString());

                    Console.WriteLine(reader.ReadToEnd());

                }

                return "Error";

            }

        }

3. Reply:

{"UserDirectory":"ASDD","UserId":"ZZZ","Attributes":[],"Ticket":"WKbfIdXGwgfhAf-

x","TargetUri":null}

akl
Honored Contributor

Re: Unable to get targetId from QPS ticket response

Ye everything seems ok.

I was playing around with it this morning, only on MS8 though, and could not get a response out of the TargetUri regardless if I posted it through the body as a query parameter.

I have logged it with support, lets see what they say.

Not applicable

Re: Unable to get targetId from QPS ticket response

although it has been almost a year

I wonder what happen to this problem.

bortolotti_carl
New Contributor II

Re: Unable to get targetId from QPS ticket response

I'm had the same problem... Did you found a solution for this problem?

duzunic88
New Contributor

Re: Unable to get targetId from QPS ticket response

My colleague found the solution.

var jsonrequest = JSON.stringify({ 'UserDirectory': userdirectory.toString() , 'UserId': selecteduser.toString(), 'Attributes': [], 'TargetId':targetId });

This will get you a response from the TarketUri.

Community Browser