Jump to content
Welcome to our new Citrix community!
  • 0

Get CwsAuth Token through C#

Antonio Vargas


Hello everyone,

I'm having authentication issues when I try to get the Sites IDs through its API. As far as I can understand it is because of the Token I'm obtaining. Originally I used to get the token from the following URL: "https://trust.citrixworkspacesapi.net/root/tokens/clients" when I used to use it for monitoring queries only.  But recently I checked the developer portal and I get two different addresses;

The frist one: "https://api.cloud.com/cctrustoauth2/{{customerid}}/tokens/clients" according to: https://developer.cloud.com/citrixworkspace/virtual-apps-and-desktops/citrix-daas-rest-apis/docs/learning-journey

And the second one: "https://api-us.cloud.com/cctrustoauth2/root/tokens/clients" according to: https://developer.cloud.com/citrix-cloud/citrix-cloud-api-overview/docs/citrix-cloud-api-walkthrough#troubleshooting


Now, I have tried the following piece of code for the both URLs:

            var hc = new HttpClient();
            hc.DefaultRequestHeaders.Add("Citrix-CustomerId", Globals.CustomerID);
            string body = "{ \"grant_type\": \"client_credentials\", \"client_id\": \"" + Globals.ClientID + "\", \"client_secret\": \"" + Globals.ClientSecret + " \" }";
            var cont = JsonConvert.SerializeObject(body);
            var buff = Encoding.UTF8.GetBytes(cont);
            var bcont = new ByteArrayContent(buff);
            bcont.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            var resp = hc.PostAsync(new Uri("{URL addresses}"), bcont);
            string json = resp.Result.ToString();


And the response I obtain is Status Code 400, Invalid Request.


I hope you can help me with this issue. Thanks in advance!


PS: the URL "https://trust.citrixworkspacesapi.net/root/tokens/clients" does get me a token but when I use it to query the Sites IDs, I get an unauthenticated error.

Link to comment

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...