ZAPI - 403 Forbidden Issue with Basic Authentication

kirankanumuri June 6, 2014

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

5 answers

0 votes
ahsanakhtar April 27, 2017

Hi Guys,

i am doing configuration of Zephyr plugin into jekins but i don't understand from where to get Zephyr Base URL 

Screenshot : zapi-configuration2.jpg

Henry October 18, 2017

@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 :(

0 votes
kiran kumar kanumuri July 23, 2014

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

Vighnesh V Pai April 17, 2018

is it needs to be Trail license or Purchased license?

0 votes
Joseph Van Der Wee June 24, 2014

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.

0 votes
Joseph Van Der Wee June 23, 2014

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

kirankanumuri June 23, 2014

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);

}

}

Avinash July 23, 2014

Hi Kiran,

Were you able to resolve this issue? Please let me know as I am also facing the same issue.

Avinash

kiran kumar kanumuri July 23, 2014

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

0 votes
Tiago Comasseto
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 11, 2014

Hi Kiran, you may try the ZAPI Python examples with 'Basic' authorization here: http://community.yourzephyr.com/viewforum.php?f=21

Cheers

kirankanumuri June 16, 2014

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());

		
	}

Suggest an answer

Log in or Sign up to answer