java - How to login in JIRA using REST API and POST issue -
actually task post bug in jira excel sheet.
now able post bugs in bugzilla. please 1 me java code how login , post bug using rest api. have example in perl, in java.
i tried following code, i'm able login perform tasks using jira rest api.
httppost httpost = new httppost("https://id.atlassian.com/login?continue=https://jira.atlassian.com/secure/dashboard.jspa&application=jac"); list<namevaluepair> nvps = new arraylist<namevaluepair>(); nvps.add(new basicnamevaluepair("username", "sxxxxxxx@live.com")); nvps.add(new basicnamevaluepair("password", "xxxxxxxxxn")); nvps.add(new basicnamevaluepair("csrftoken", xcrftokenval)); nvps.add(new basicnamevaluepair("continue", "https://jira.atlassian.com/secure/dashboard.jsp")); nvps.add(new basicnamevaluepair("application", "jac")); httpost.setentity(new urlencodedformentity(nvps)); response = httpclient.execute(httpost); system.out.println("response " + response.tostring()); entity = response.getentity(); //system.out.println("double check we've got right page " + entityutils.tostring(entity)); system.out.println("response : " + response.getstatusline());
you have post "http://jira_url/rest/auth/1/session", set cookie jsessionid other requests. in jersey, do:
jsonparameters = "{\"username\":\"usernamevalue\", \"password\": \"passwordvalue\"}"; webresource webresource = client.resource("http://<jira_url>/rest/auth/1/session"); clientresponse response = webresource.type(mediatype.application_json).post(clientresponse.class, jsonparameters);
in response have jsessionid, have save in cookie , use it. in jersey:
import javax.ws.rs.core.cookie; ... cookie cookie = new cookie(jsession.getname(), jsession.getvalue()); response = webresource.type(mediatype.application_json).cookie(cookie) .post(clientresponse.class, jsonparameters);
jira rest doc:
Comments
Post a Comment