Basic Authentication with Rest (RestSharp API)

Post Reply
Eruadan
Posts: 4
Joined: Fri Feb 13, 2015 4:08 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2010

Basic Authentication with Rest (RestSharp API)

Post by Eruadan »

Hello everyone,

I'm trying to use C# with the RestSharp API to pull data from the admin server and individual TM1 servers. I've managed to successfully get a list of online TM1 Servers from the admin server by sending a get request to "http://localhost:5895/api/v1/Servers"

This returns:

Code: Select all

.....

{"Name":"GO_New_Stores","IPAddress":"192.168.141.131","IPv6Address":"","PortNumber":45557,"ClientMessagePortNumber":49173,"HTTPPortNumber":45558,"UsingSSL":true,"AcceptingClients":true}

......
Based on this info I next try to send a get request to "http://192.168.141.131:45558/api/v1/Cubes?$select=Name" by using the following code:

Code: Select all

            RestClient WebClient = new RestClient();
            WebClient.BaseUrl = new Uri("http://192.168.141.131:45558/");
            RestRequest CurrentRequest = new RestRequest();

            WebClient.Authenticator = new HttpBasicAuthenticator("admin", "apple"); // Neither work
            CurrentRequest = new RestRequest("api/v1/Cubes?$select=Name", Method.GET);
            //CurrentRequest.AddHeader("Authorization", "Basic YWRtaW46YXBwbGU="); // Neither work
            var queryresult = WebClient.Execute(CurrentRequest);
            Console.WriteLine(queryresult.ResponseUri);
            Console.WriteLine(queryresult.ErrorMessage); // returns "The operation has timed out"
            Console.WriteLine(queryresult.ResponseStatus); // returns "TimedOut"
            Console.WriteLine(queryresult.StatusDescription);
            Console.WriteLine(queryresult.Content);
            Console.WriteLine("Done writing.... :(");
            Console.ReadLine();

So my question is... Does anyone know the proper way to use basic authentication? I'm doing something wrong, but I can't figure out what exactly. If someone could help put me on the right track, that would help a lot! :D

Thanks in advance.
Eruadan
Posts: 4
Joined: Fri Feb 13, 2015 4:08 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2010

Re: Basic Authentication with Rest (RestSharp API)

Post by Eruadan »

Fixed!

For those that are curious about the solution... if UsingSSL is true you need to use https://localhost:HTTPPortNumber/RelativeAPI-Path
Post Reply