ZAPI - 403 Forbidden Issue with Basic Authentication

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

This widget could not be displayed.

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

Cheers

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

		
	}

This widget could not be displayed.

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

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

}

}

Hi Kiran,

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

Avinash

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

This widget could not be displayed.

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.

This widget could not be displayed.

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

is it needs to be Trail license or Purchased license?

This widget could not be displayed.

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

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

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

232 views 3 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you