I am a newbie Jira user and am trying to familiarize myself with the basics of importing and exporting project information to and from Jira via a C# application. Following is my current code for retrieving project descriptions:
public String RunQuery(String sBaseURL, String sQuery = null, String data = null, String method = "GET")
{
String result = String.Empty;
try
{
String sAppID = "2c53539c-0f27-4b2c-9bfc-8ddc9fbb91a7";
String sRequest = String.Format("{0}/{1}/rest/api/2/{2}", sBaseURL, sAppID, sQuery);
HttpWebRequest newRequest = (HttpWebRequest)WebRequest.Create(sRequest);
newRequest.ContentType = "application/json";
newRequest.Method = method;
if (data != null)
{
using (StreamWriter writer = new StreamWriter(newRequest.GetRequestStream()))
{
writer.Write(data);
}
}
String base64Credentials = GetEncodedCredentials();
newRequest.Headers.Add("Authorization", "Basic " + base64Credentials);
using (HttpWebResponse response = newRequest.GetResponse() as HttpWebResponse)
{
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
result = reader.ReadToEnd();
}
newRequest = null;
}
}
catch (Exception ex)
{
// MessageBox.Show(String.Format("There is a problem getting data from Jira :\n{0}\n{1}", ex.Message, query), "Jira Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
result = ex.Message;
}
return result;
}
// API Token: WSH5PJRLlbrXhuqp7xhi9C42
private String GetEncodedCredentials()
{
String mergedCredentials = String.Format("{0}:{1}", txtEMail.Text, txtAPIToken.Text);
byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
return Convert.ToBase64String(byteCredentials);
}
However, when I run this query, I get back a fully loaded HTML page with the project description embedded inside it. I was hoping for a way to get the data back in JSON. What am I doing wrong?
Thanks in advance.
Jeff Armstrong
Sr. Developer, Deltek Corporation