Forums

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

Access Jira Rest api from Confluence

Salar Mumtaz
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 8, 2013

Hi,

I am trying to make a Confluence addon that will access Jira Rest api. I am a complete newbie in this and I have been having trouble to find a place to start.

Thanks for your help.

3 answers

1 vote
RambanamP
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.
December 8, 2013

you can try with jersy libraries as follows

package com.rest.client;
 
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
 
public class RESTclient {
 
    public static void main(String[] args) {
        try {
 
            Client client = Client.create();           
            client.addFilter(new HTTPBasicAuthFilter("username", "password"));
            WebResource webResource = client.resource("http://localhost:9090/rest/api/2/issue/JIRA-430");          
                String input="{\"fields\": {\"customfield_10156\": \"Testing through REST\"} }";       
            ClientResponse response = webResource.type("application/json").put(ClientResponse.class, input);   
            String output = response.getEntity(String.class);          
            System.out.println(output);
        } catch (Exception e) {
            e.printStackTrace();
 
        }
 
    }
}

add the following dependencies in pom.xml

<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>2.3</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>com.sun.jersey</groupId>
			<artifactId>jersey-client</artifactId>
			<version>${jersey.client.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>com.sun.jersey.contribs</groupId>
			<artifactId>jersey-multipart</artifactId>
			<version>${jersey.client.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>com.sun.jersey.contribs</groupId>
			<artifactId>jersey-apache-client</artifactId>
			<version>${jersey.client.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>com.sun.jersey</groupId>
			<artifactId>jersey-json</artifactId>
			<version>${jersey.client.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>com.sun.jersey</groupId>
			<artifactId>jersey-bundle</artifactId>
			<version>1.8</version>
			<scope>provided</scope>
		</dependency>

0 votes
Lukasz Gornicki February 11, 2014

If there is a SSO (I guess it is it, or magic Crowd, whatever) and I access both, Confluence and Jira with the same credentials. How to access Jira REST api from Confluence plugin, so a user doesn't have to provide credentials to jira, but the one from the currently logged in user are used?

0 votes
Nic Brough -Adaptavist-
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.
December 8, 2013

For writing a Confluence add on, start at https://developer.atlassian.com/display/CONFDEV/Confluence+Developer+Documentation

For the basics of using Jira's REST interface, I'd recommend a look through the tutorials - see https://developer.atlassian.com/display/JIRADEV/JIRA+REST+APIs

Salar Mumtaz
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 8, 2013

The main problem I am having right now is accessing Jira Api from a confluence addon.

Nic Brough -Adaptavist-
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.
December 8, 2013

There's not a lot we can tell you - you haven't defined the problem beyond "I can't access it", and the best answer to that is in the documentation.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events