JIRA upgrade & Jira rest api

Colin McCudden September 19, 2017

Hello - we are currently looking at upgrading from Jira 6.3.12 to Jira 7.4.2. Currently we have written some custom code that accesses the Jira rest apis.

As far as I can see - looking through the documentation - there should be no affect on the api's we are calling - currently the CreateIssue api - POST /rest/api/2/issue . Please see below for the code:-

/* these variables are hardcoded for this example, in ION most are passed in from the user interface */ String jiraHost = "http://jira.fsi:8080/"
String jiraProject = "IURI";
String messageWithVersion = "ION Version 1.0.38.2807: ION is not saving my research"; String summ = "<p> ION is not saving my research, see below. <br /> <img src='/api/file/12232' ></img> </p>"
String uname = "Daniel.shaw@firststateinvestments.com";
String issueType = "Bug";
Uri address = new Uri(JiraHost + "rest/api/2/issue"); dynamic remoteMessage = new
{
fields = new
{
project = new { key = jiraProject },
summary = summ,
description = messageWithVersion,
issuetype = new { name = issueType },
customfield_10000 = uname
}
};

String json = Newtonsoft.Json.JsonConvert.SerializeObject(remoteMessage);
byte[] byteData = UTF8Encoding.UTF8.GetBytes(json);
HttpWebRequest JIRARequest = WebRequest.Create(address) as HttpWebRequest;
// Set type to POST 
JIRARequest.Method = "POST";

// Set the content length in the request headers 
JIRARequest.ContentLength = byteData.Length;
JIRARequest.ContentType = "application/json";

/* code block for the GetEncodedCredentials function below private string GetEncodedCredentials()
{
string mergedCredentials = string.Format("{0}:{1}", "ionuser", "F1rststate");
byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
return Convert.ToBase64String(byteCredentials);
}
*/
string base64Credentials = GetEncodedCredentials();

JIRARequest.Headers.Add("Authorization", "Basic " + base64Credentials);
// Write data 
using (Stream postStream = JIRARequest.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}

try
{
HttpWebResponse response = JIRARequest.GetResponse() as HttpWebResponse;
// Get the response stream 
StreamReader reader = new StreamReader(response.GetResponseStream());
string resString = reader.ReadToEnd();
log.DebugFormat("Response Received for JSON POST: {0}", resString);

//.... [Bunch of irrelavent stuff]

catch (Exception ex)
{
log.Error("Error Posting JIRA ", ex);
return;
}

1 answer

1 accepted

0 votes
Answer accepted
Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 19, 2017

Hi Colin

You never actually asked a question, but i'm assuming it is whether the REST API code you've got will still work after upgrading Jira?

If so, the answer would be yes. Generally APIs would be compatible going forward in releases, so you shouldn't have any problem with it. 

See the API documentation here for the latest Server version. Near the top there is a link to all other versions as well, but the latest version still has api/2/issue so I don't foresee any issues

Colin McCudden September 19, 2017

Thanks Warren - yes that was my question.  I had looked at that documentation, so was hoping it would be okay.  Thanks for your informative and prompt reply

Suggest an answer

Log in or Sign up to answer