I want to create issue in existing project in jira using java program. please suggest me how to do.
Hi Vineet,
You should have a look at the following Developer Resource: Java APIs. Or have a look at an older question which could give you something to start: Create issue via REST API useing Java
Hope this helps.
Best,
Maarten
In the above link attached program i am getting 401 error
401 means something is not right with the authentication. Have a look at the following line of code and make sure to adjust it to your credentials:
conn.setRequestProperty("Authorization", "Basic " + Base64.encode("vzverev:Gromozavr".getBytes(), 0));
inputstream variable is not used
package NewPost;import com.sun.org.apache.xml.internal.security.utils.Base64;import java.io.*;import java.net.*;import javax.json.*;public class testREST_CreateIssue {public static void main(String[] args) {try {URL jiraREST_URL = new URL("http://localhost:8080/rest/api/2/issue/");URLConnection urlConnection = jiraREST_URL.openConnection();urlConnection.setDoInput(true);HttpURLConnection conn = (HttpURLConnection) jiraREST_URL.openConnection();conn.setDoOutput(true);conn.setDoInput(true);String encodedData = URLEncoder.encode(getJSON_Body(),"UTF-8");System.out.println(getJSON_Body() + "/" + encodedData);conn.setRequestMethod("POST");conn.setRequestProperty("Authorization", "Basic " + Base64.encode("vineet1492:742762".getBytes(), 0));conn.setRequestProperty("Content-Type", "application/json");conn.setRequestProperty("Content-Length", String.valueOf(encodedData.length()));conn.getOutputStream().write(encodedData.getBytes());try {InputStream inputStream = conn.getInputStream();}catch (IOException e){System.out.println(e.getMessage());}} catch (MalformedURLException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}private static String getJSON_Body(){JsonObject createIssue = Json.createObjectBuilder().add("fields",Json.createObjectBuilder().add("project",Json.createObjectBuilder().add("key","USC")).add("summary", "sum").add("description", "descr").add("issuetype",Json.createObjectBuilder().add("id", "10105"))).build();return createIssue.toString();}}
It looks like you're new here. Sign in or register to get started.