Post

2 followers Follow
0
Avatar

API 2.0 is not authorization for Login service

I am using the API 2.0 for login but it is not authorizing, It shows the remote servers given unauthorized error.

Sourabh Malani Answered

Please sign in to leave a comment.

5 comments

0
Avatar

Hi Sourabh,
This is a bit unclear. Can you elaborate? Are you using SOAP or REST API? Which platform, programming language? Did you call the Login service with a valid user name & password?
Another question, which edition of Clarizen are you using? (Professional or enterprise/unlimited?)

Thanks,
Ophir

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

Hello,

We are using REST API, We are using ASP.Net and C# language for code. We are using below code for Login. The GetServerLocation function run properly, but when Login code run then it show the error message. (the remote servers given unauthorized error). It was working properly with previous version.

private void GetServerLocation(string _UserName, string _Password)
{

string UserName = _UserName;
string Password = _Password;

string data = "{'UserName': '" + UserName + "','Password': '" + Password + "'}";
string uri = "https://api2.clarizen.com/v2.0/services/authentication/getServerDefinition";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json";
request.ContentLength = data.Length;
//   request.Accept = "application/json";
try
{
    using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
    {
        writer.Write(data);
    }

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
    {
        string tmp = reader.ReadToEnd();

        //TextBox1.Text = doc.ToString();
        //  lblMessage.Text = tmp.ToString();
        ServerLocation_member p = new JavaScriptSerializer().Deserialize<ServerLocation_member>(tmp);
        Login(p.serverLocation,UserName,Password);
    }
}
catch (Exception ex) { }

}

private void Login(string ServerLocation, string UserName, string Password)
{

string data = "{'UserName': '" + UserName + "','Password': '" + Password + "'}";
string uri = ServerLocation + "/authentication/login";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/json";
request.ContentLength = data.Length;
//   request.Accept = "application/json";
try
{
    using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
    {
        writer.Write(data);
    }

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
    {
        string tmp = reader.ReadToEnd();
        Login_member p = new JavaScriptSerializer().Deserialize<Login_member>(tmp);
        GetEntityQuery(ServerLocation, p.sessionId, p.organizationId);
    }
}
catch (Exception ex) { }

}

Please assist regarding this.

Thank You.

Sourabh Malani 0 votes
Comment actions Permalink
0
Avatar

Hi Sourabh,
I tried your code and it does work with my user name & password, so the services seem to work and your code seems to be fine.
Please notice that you can probably find more information in the exception itself. When I entered wrong credentials or used credentials for Professional edition I did get an HTTP 401 exception but this block of code showed me the reason:

catch (WebException wex) {
var streamReader = new StreamReader(wex.Response.GetResponseStream());
string s = streamReader.ReadToEnd();
MessageBox.Show(s);
}
Please try it, and post again if you need further assistance.
Hope this helps,
Ophir

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

Hello,

I have added the given catch block code and now I am getting below error.

{ "errorCode": "LoginFailure", "message": "API access is not supported in your current edition", "referenceId": "1gXuL8mHkZSIAVeEAj1Ssc" }

Please assist regarding this.

Thank You.

Sourabh Malani 0 votes
Comment actions Permalink
1
Avatar

Hi Sourabh,
I suppose you have Clarizen Professional edition.
API is not supported in Clarizen Professional edition.
If that is the case, please contact your customer success manager or your Clarizen sales representative to discuss an upgrade.

Hope this helps,
Ophir

Ophir Kenig 1 vote
Comment actions Permalink