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
Hi Jeff, welcome to the Atlassian Community,
Difficult for me to debug this for you as we do not know the variables you are using. I can also see you are using some "App ID" in the request URL. I'm not sure what that is.
You tagged your question as Jira Cloud. Here is the documentation on how to get project information like the project description :https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-projects/#api-rest-api-3-project-projectidorkey-get
An example:
https://<subdomain>.atlassian.net/rest/api/3/project/<project_key>
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.