Skip to main content

ToolWatch API: Authorization

Get a ToolWatch API authorization token with your username, password, and access key, with responses and C# sample code.

Your application must get an authorization token before it sends any other ToolWatch API request. For what you need before you start, see ToolWatch API: Getting Started.

Request

URI

https://api.{cluster}.toolwatch.net/authorization

Http Method

POST

Headers

Not needed

Request Body

username:password:accesskey

Response

200 Ok

Response body will contain a 44 character authorization token similar to:

UzwDutjW0yeu9yjcGyfp+KJ4FFbMaEdBE+baSh0XWFU=

401 Unauthorized

Triggered when username and password combination fail

401 Unauthorized

Triggered when access key is invalid or is not associated with username and password


Sample Code

This code can be cut and pasted into a new Console application and run immediately. All you need to do is set the appropriate email and password.

using System;

using System.IO;

using System.Net;

namespace Align.API.Samples
{
class Program
{
static void Main(string[] args)
{
string token = GetAuthToken();

Console.WriteLine(token);

Console.ReadLine();

}

public static string GetAuthToken()
{

HttpWebResponse response = null;

string token;

string url = "https://api.{cluster}.toolwatch.net/authorization";

HttpWebRequest request =
(HttpWebRequest)WebRequest.Create(url);

request.Method = "POST";

// set request body
using (StreamWriter writer =
new StreamWriter(request.GetRequestStream()))
writer.Write("email:password:accesskey");

// GetResponse raises an exception on http status code 400
// We can pull response out of the exception and continue on our way
try
{
response = (HttpWebResponse)request.GetResponse();

}
catch (WebException ex)
{
response = (HttpWebResponse)ex.Response;

}
finally
{
using (StreamReader reader =
new StreamReader(response.GetResponseStream()))
token = reader.ReadToEnd();

}
return token;

}

}
}
Did this answer your question?