Hello Comunity
Firs, I'm new to this API so assume no prior knowledge. I'm learning.
I intend to create a Confluence page programmatically via API using C#.
I have browsed internet for several days and found some examples aiding, but should there not be a description of the API somewhere?
My code includes "using Confluence.Client;" and I run it in Viaual Stusio Professional.
Based on examples I attempt log in to Confluence by:
public void loginToConfluence()
{
try
{
WebRequest request = WebRequest.Create(this.baseURL + this.loginAPI);
System.String postData = "{\"username\":\"" + this.loginUserName + "\",\"password\":\"" + this.loginPassWord + "\"}";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
System.String responseFromServer = reader.ReadToEnd();
reader.Close();
dataStream.Close();
response.Close();
this.loginResponse = responseFromServer;
Console.WriteLine("\nloginResopnse:");
Console.WriteLine(this.loginResponse);
}
catch (Exception ex)
{
Console.WriteLine("Error in loginToConfluence: " + ex);
this.errorsOccurred = true;
}
Responce:
Started
Error in loginToConfluence: System.Net.WebException: The remote server returned an error: (403) Forbidden.
at System.Net.HttpWebRequest.GetResponse()
at IntToConfluence.JiraRequest.loginToConfluence() in C:\MLL\C#\GetConfluencePage\Program.cs:line 154
Finished
I understand the access is refused although I can use the same url to open the page in a browser, using the same UI/PW.
Why does the exception refers to JiraRequest in error message?
Is there a different URL to use than the one used by browser to access the page via api?
Any recommended API documentation?
Any simple C# example recommended are greatly appreciated and will aid my learning!