1

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Omer Javed
  • 161
  • 2
  • 12
  • first of all check for username and password,401 often comes when your username and password are right,if these are right then try online site to generate encode64 string and pass it to header directly. – Akash Shinde Apr 09 '15 at 06:32
  • @Omer - did you ever figure this out? – leora Oct 08 '15 at 02:20

1 Answers1

7

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

Omer Javed
  • 161
  • 2
  • 12
  • 1
    I just did the same, and found your comment. Saved me some debugging, thanks :) – Larsbj Nov 20 '15 at 13:05
  • I don't have JIRA, and therfore don't have a JIRA assigned username either. I was also using the full email address (admin@admin.com) and password, but got this working by just using the name (admin). Awful API documentation on this, nowhere on the confluence docs website does it state this. – Detail Oct 23 '18 at 10:38