Hopefully someone can help me as this is driving me insane!!
Via the REST API I'm attempting to make a POST request to our Service Desk from a C# web form.
I have tried to make the connection with my username and password. I am an administrator and so have access to the full system.
I have also tried it the following ways:
All of these return the same error:
The remote server returned an error: (401) Unauthorized.
This is my code:
try
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
WebRequest req = WebRequest.Create(@"https://myurl.co.uk/rest/servicedeskapi/request");
req.Method = "POST";
req.Headers["Authorization"] = "Basic " +
Convert.ToBase64String(
Encoding.Default.GetBytes("username:password"));
req.ContentType = "application/json";
var json = JObject.Parse(
"{\"serviceDeskId\": \"4\",\"requestTypeId\": \"30\",\"requestFieldValues\": {\"summary\": \"" +
summary.Value + "\",\"description\": \"" + description.Value + "\"}}");
using (var streamWriter = new StreamWriter(req.GetRequestStream()))
{
streamWriter.Write(json);
}
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
}
catch (Exception ex)
{
error.InnerText = ex.Message;
}
Any help would be appreciated!