Hi All,
I would like to create version in my plugin using jira rest version creation API.
I am new to these rest calls.
Please point me to the right direction of how to implement it.
Thanks,
Vinutha
Community moderators have prevented the ability to post new answers.
We're developing an application called ConnectAll that interfaces with many applications like JIRA, QC, TFS, TTP, Rally, etc. We stick with the basic technologies like XML and Json as it seems to be easier to support upcoming versions of these products. Check it out at http://www.go2group.com.
Hi Vinutha,
You can refer to this page on how to start with JIRA REST API:
An example using curl to create a version:
curl -i -H "Content-Type: application/json" -X POST -d '{"description": "An excellent version","name": "New Version 1","userReleaseDate": "5/Jul/2010","project": "TEST","archived": false,"released": true}' -u username:password https://domain.jira.com/rest/api/latest/version
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Azwandi,
Thanks for your links.
I am trying to make REST call through a java class. Its failing with HTTP response code: 401. user authentication is failing.
Please find the below piece of code
public class Version_REST {
private static String USERNAME = "admin";
private static String PASSWORD = "admin";
private static String ENDPOINT = "http://localhost:2990/jira/rest/api/2.0.alpha1/version";
private Version_REST() {
}
public static String callMethod(String data) throws IOException {
URL url = new URL(ENDPOINT);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
String userpass = USERNAME + ":" + PASSWORD;
connection.setRequestProperty("Authorization", userpass);
connection.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(connection
.getOutputStream());
wr.write(data);
wr.flush();
InputStream in = connection.getInputStream();
BufferedReader res = new BufferedReader(new InputStreamReader(in,
"UTF-8"));
StringBuffer sBuffer = new StringBuffer();
String inputLine;
while ((inputLine = res.readLine()) != null)
sBuffer.append(inputLine);
res.close();
return sBuffer.toString();
}
public static void main(String[] args) throws IOException {
Map map = new LinkedHashMap();
map.put("description", "An excellent version");
map.put("name", "New Version 1");
map.put("userReleaseDate", "5/Jul/2010");
map.put("project", "IPP");
map.put("archived", "false");
map.put("released", "true");
map.put("releaseDate", "2010-07-05");
String response = Version_REST.callMethod(JSONObject.fromObject(map)
.toString());
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
After executing i am getting below error response,
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 401 for URL: http://localhost:2990/jira/rest/api/2.0.alpha1/version
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at reader.Version_REST.callMethod(Version_REST.java:39)
at reader.Version_REST.main(Version_REST.java:65)
I am not understanding what is wrong i am doing while setting user credentials to the header.
Please let me know if you have any clue.
Thanks,
Vinutha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vinutha
You are trying to do a basic authentication. Hence your header should be "Authorization:Basic <username:password> The point to note is that, <username:password> should be encoded in base64. You can do it easily using the below method
public String encodeToBase64(String value) { String retString = ""; byte[] encodedBytes = Base64.encodeBase64(value.getBytes()); try { retString = new String(encodedBytes); } catch(Exception exception) { retString = "NA"; } return retString; }
This is the main error i see in your code.
Thanks
Arun
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks.
So I'm using JRJC 1.0 library (along with it's dependy jars) and here's a example on how to get all
the Issue Key using the jql search client.
import com.atlassian.jira.rest.client.domain.SearchResult;
.................
final SearchResult search_Result = YR.restClient.getSearchClient().searchJql("reporter=ttt", 100, 0, pm);
for (BasicIssue issue : search_Result.getIssues()) {
System.out.println("issue.getKey(): " + issue.getKey());
}
You'll need to get the Keys and then get the "Issue" objects using the JiraRestClient to extract the Issue's
information.
Hope this helps any one.
TRX
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
jql would be something similar to:
final SearchResult searchResult = restClient.getSearchClient().searchJql("some kind of string here", pm);
for (BasicIssue issue : searchResult.getIssues()) {
System.out.println(issue.getKey());
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Following is some example code to get the project in JIRA. Hope this helps.
String auth = new String(Base64.encode(userName + ":" + password)); Client client = Client.create(); WebResource webResource = client.resource(url + "/rest/api/2/project"); ClientResponse response = webResource.header("Authorization", "Basic " + auth).type("application/json") .accept("application/json").get(ClientResponse.class); int statusCode = response.getResponseStatus().getStatusCode(); if (statusCode == 401) { throw new AuthenticationException("Invalid Username or Password"); } String s = response.getEntity(String.class); log.error("The project rcvd from JIRA are: " + s);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks. Just got it working. Any ideas on if the put method works, but the field only changes on certain values?
ex) Severity field uses id "10021" and usea s drop down of "High", "Medium", and "Low".
When on low are the put method is done and returns a 204, the Issue Severity drop down is set to "High". But if I try to change it back to "Low" or "Medium", it returns 204 but does NOT set the Severity value correctly.
Any thoughts on why this may be happening?
TRX
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.