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!
Hi @HH ,
The way to authenticate REST API calls in Cloud is to use the email address associated to your Atlassian Account and the API Token.
Now, in order to check that you are using the right credentials and/or if your auth requests are failing since you need to complete the captcha, can you kindly run below command and paste the output masking the sensitive data:
curl -D- -u <email_address>:<api_token> -X GET https://<hostname>/rest/api/2/project
If everything goes fine the above call will return the list of all the projects the Atlassian Account you used to authenticate the REST API call has access to (plus, the -D- option will print the full response header).
Cheers,
Dario
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.