Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Getting responses in HTML, not JSON

JeffArmstrong
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 5, 2022

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

 

1 answer

0 votes
Charlie Misonne
Community Champion
December 5, 2022

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>

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events