Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

how to create Jira rest module for creating issue.

Prashant Mali June 2, 2016

plz give me step by step description.

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Prashant Mali June 12, 2016

It is not working for me. Please explain in detail

Vasiliy Zverev
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.
June 13, 2016

Try to get list of all project from brouser. Namely you need to go here: <JIRA base URL>/rest/api/2/project

You should get list of all projects into JSON format. Are you able to do this?

0 votes
Vasiliy Zverev
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.
June 2, 2016

Here is my code to do this. Try it:

package ru.phosagro.jira.rest;

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("jiraURL/rest/api/2/issue/");
            URLConnection urlConnection = jiraREST_URL.openConnection();
            urlConnection.setDoInput(true);

            HttpURLConnection conn = (HttpURLConnection) jiraREST_URL.openConnection();
            conn.setDoOutput(true);
            conn.setDoInput(true);

            System.out.println(getJSON_Body());

            conn.setRequestMethod("POST");
            conn.setRequestProperty("Authorization", "Basic " + Base64.encode("user:password".getBytes(), 0));
            conn.setRequestProperty("Content-Type", "application/json");
            conn.getOutputStream().write(getJSON_Body().getBytes());
            //conn.getOutputStream().write("{\"fields\":{\"project\":{\"id\":16512},\"summary\":\"Weekly report (12)\",\"duedate\":\"2016-03-25\",\"issuetype\":{\"id\":\"10903\"}}}".getBytes());

            String toBeEncoded = "vzverev:Gromozavr";
            System.out.println(toBeEncoded + ": " + Base64.encode(toBeEncoded.getBytes(),0));
            System.out.println(toBeEncoded + ": " + new String(java.util.Base64.getEncoder().encode(toBeEncoded.getBytes())));

            try {
                InputStream inputStream = conn.getInputStream();
                for(int iByte = 0; iByte &lt; inputStream.available(); ++iByte ){

                }
               // System.out.print(inputStream.toString());
                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", "IC38"))
                            .add("summary", "Weekly report (11) А вот так")
                            .add("duedate", "2016-03-18")
                            .add("issuetype",
                                    Json.createObjectBuilder().add("id", "10903"))
            ).build();

        return createIssue.toString();
    }

}
Prashant Mali June 3, 2016

Hi,

Its not working for me.

Some thing was wrong in my Project building steps.

Can you please share with me steps from the scrap.

Prashant Mali June 3, 2016

Hi Vasiliy Zvere ,

Plz guide me.

Thanks

Vasiliy Zverev
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.
June 7, 2016

First, are you able to create a plugin skeleton and add it into JIRA?

TAGS
AUG Leaders

Atlassian Community Events