I am trying to hit API from C# code using HTTP client but I am getting the result as unauthorized. If I try with postman it's working fine. what will the issue ?
Hello,
It mean you provide invalid credentials or you do not provide credentials at all.
No, I am giving the creadentials.
string authCredentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(Username + ":" + Password));client.DefaultRequestHeaders.Add("Authorization", "Basic " + authCredentials);client.DefaultRequestHeaders.Add("Accept", "application/json");var result = JsonConvert.SerializeObject(model);var response = await client.PostAsync($"https://hrbotdev.atlassian.net/rest/api/latest/issue", new StringContent(result, Encoding.UTF8, "application/json"));
Could you somehow to see, what request is sent from your program? I usually use Fiddler for it.
It's working in postman fine. In program only it's not working
It means that your request, which is sent from your program, is different from postman. You need to see your request.
Hi Vamsi
My C# application has the following 2 lines before the Convert.ToBase64String :
string mergedCredentials = string.Format("{0}:{1}", m_Username, m_Password);byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);return Convert.ToBase64String(byteCredentials);
Try to see if that helps
Thanks Warren for responding.
I am getting the AuthCredentials in the perfect way. I think it's problem with the permissions. Do we need to enable any permission ?
If I'm correct, the call you're doing (https://hrbotdev.atlassian.net/rest/api/latest/issue) isn't valid, because it needs a further /ABC-123 passing in the issue key.
I tried your call but with my Jira name instead of hrbotdev and I received an error. I added a key and it worked, so I think you need
https://hrbotdev.atlassian.net/rest/api/latest/issue/ABC-1234
Yeah, that is for getting the issue which has been already created. I want create the issue using the API.
It looks like you're new here. Sign in or register to get started.