Omer Javed
Omer Javed

Reputation: 161

Confluence REST API Authorization issue

I am having issues with Atlassian Confluence REST API authentication. Please take a look at following C# code :

private  string USERNAME = "test";
private  string PASSWORD = "test";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://xxx.atlassian.net/wiki/rest/api/content?os_authType=basic&spaceKey=DEV&Title=Development&expand=space,body.view,version,container");
request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(USERNAME + ":" + PASSWORD)));
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

But this always produces an error : {"The remote server returned an error: (401) Unauthorized."}.

I have tried the same code with in-house REST Services with Basic Authentication and it yields correct result. Please can someone point out what am I missing in this ? Thanks.

Upvotes: 1

Views: 5127

Answers (2)

Mosca Pt
Mosca Pt

Reputation: 527

just wanted to note that username/password authentication has been deprecated here, in favor of tokens. Please see here:

https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-basic-auth-and-cookie-based-auth/?_ga=2.139254321.363208783.1557187081-1066642471.1556199146

Upvotes: 0

Omer Javed
Omer Javed

Reputation: 161

For the benefit of anyone : I was using my email as username. I had to replace it with the username assigned by JIRA.

Upvotes: 7

Related Questions