Hello Experts,
I'm trying to access JIRA project using ZAPI , I'm getting the 403 forbidden error .Below is the code which fetches project list. Below is the code. Any help is highly appreciated. This is completely blocking me to integrate our test automation framework into JIRA
// TODO Auto-generated method stub DefaultHttpClient defaultHttpClient = new DefaultHttpClient(); StringWriter writer = new StringWriter(); // Define a postRequest request HttpPost postRequest = new HttpPost("http://jira.serverservices.com/rest/zapi/latest/util/project-list"); // Set the content-type header postRequest.addHeader("content-type", "application/json"); postRequest.addHeader("Authorization", "Basic a2thbnVtdXJpOmFsbGl*****zJA=="); try { // Set the request post body StringEntity userEntity = new StringEntity(writer.getBuffer() .toString()); postRequest.setEntity(userEntity); // Send the request; return the response in HttpResponse object if // any HttpResponse response = defaultHttpClient.execute(postRequest); // verify if any error code first int statusCode = response.getStatusLine().getStatusCode(); System.out.println("Response code received is : +" + statusCode); BufferedReader r = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuilder total = new StringBuilder(); String line = null; while ((line = r.readLine()) != null) { total.append(line); } System.out.println(total.toString()); // is.close(); } finally { // Important: Close the connect defaultHttpClient.getConnectionManager().shutdown(); }
Regards,
Kiran
Hi Guys,
i am doing configuration of Zephyr plugin into jekins but i don't understand from where to get Zephyr Base URL
Screenshot :
@ahsanakhtar if you click "?" beside Zephyr, it will tel you Zephyr Base URL is https://prod-api.zephyr4jiracloud.com/connect.
Good luck to you. I have not got it working :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Avinish,
I lately realized the i should have valid ZAPI license inorder to access Zephyr plugin from API.
Installed ZAPI and every thing started working :)
Thanks everyone in this post for your prompt responses
Regards,
Kiran
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.
The call to BASE_URL will not be erroring because you do not need to log in to view that page. However you do for ZAPI_URL. Are your credentials definitely correct?
If all else fails try using the HTTP request methods in my helper class.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kiran,
If have uploaded a Java helper class for calling ZAPI here: https://gist.github.com/jvanderwee/4758a13dded223f51bba
Hope it can be of use.
Joe
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Joe,
Thanks you very much for your response. I tried Helper class, But still i run into same Forbidden error.In below code I had added main method which calls the methods httpCon() and get() for both I get the same forbidden error.
If I am using ZAPI_URL then i'm getting This error. With BASE_URL, i'm able to get connection response. I'm battling with this issue from the past 1week and am completely blocked in exploring the ZAPI.
Appreciate if could throw some light on where I'm doing wrong
/** Helper class for calling ZAPI */
publicclass ZAPI {
/** Status IDs */
privatestaticfinalintZAPI_STATUS_PASS = 1;
privatestaticfinalintZAPI_STATUS_FAIL = 2;
privatestaticfinalintZAPI_STATUS_WIP = 3;
privatestaticfinalintZAPI_STATUS_BLOCKED = 4;
/** URLS */
privatestaticfinal String BASE_URL = "http://jira.allianceglobalservices.com";
privatestaticfinal String ZAPI_URL = BASE_URL + "/rest/zapi/latest/execution/topDefects";
/** JIRA credentials */
privatestaticfinal String CREDENTIALS = "kkanumuri:password";
public static void main(String[] args) {
//Below call throws Forbidden
try {
String response = httpCon(ZAPI_URL, CREDENTIALS).getResponseMessage();
System.out.println(response);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Below code throws forbidden exception for ZAPI_URL
get(ZAPI_URL);
//Below code works for well Base URL
try {
String response = httpCon(BASE_URL, CREDENTIALS).getResponseMessage();
System.out.println(response);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Below code throws forbidden exception
get(BASE_URL);
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Avinish,
I got this fixed. I lately realized the i should have valid ZAPI license inorder to access Zephyr plugin from API.
Installed ZAPI and every thing started working :)
Thanks everyone in this post for your prompt responses
Regards,
Kiran
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kiran, you may try the ZAPI Python examples with 'Basic' authorization here: http://community.yourzephyr.com/viewforum.php?f=21
Cheers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tiago,
I tried as per the python example, I still get the 403 error
public static void main(String[] args) { URL url; DefaultHttpClient defaultHttpClient = null; try { String username = "kkanumuri"; String password = "12****456$"; String userpass = username + ":" + password; String basicAuth = "Basic " + new String(new Base64().encode(userpass.getBytes())); defaultHttpClient = new DefaultHttpClient(); StringWriter writer = new StringWriter(); // Define a postRequest request HttpPost postRequest = new HttpPost( "http://jira.allianceglobalservices.com/rest/zapi/latest/util/project-list"); // HttpPost postRequest = new // HttpPost("http://getzephyr.apiary-mock.com/jira_server/rest/zapi/latest/execution"); // Set the content-type header postRequest.addHeader("content-type", "application/json"); postRequest.addHeader("Authorization", basicAuth); // url = new // URL("http://jira.allianceglobalservices.com/rest/zapi/latest/cycle"); // // URLConnection conn = url.openConnection(); // System.setProperty("http.proxyHost", "proxyhostname"); // System.setProperty("http.proxyPort", "8080"); // conn.setRequestProperty ("Authorization", basicAuth); // conn.setRequestProperty ("Token", Token); HttpResponse response = defaultHttpClient.execute(postRequest); // verify if any error code first int statusCode = response.getStatusLine().getStatusCode(); System.out.println("Response code received is : +" + statusCode); BufferedReader r = new BufferedReader(new InputStreamReader( response.getEntity().getContent())); StringBuilder total = new StringBuilder(); String line = null; while ((line = r.readLine()) != null) { total.append(line); } System.out.println(total.toString()); }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.