Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

403 error when using /rest/atm/1.0/testresult only via the code

Ifatsharifi December 13, 2018

Hi all,

I'm trying to use the adaptavist API for updating test results from my automation code.

I've managed to create the post request and run it successfully using Postman BUT when I use the same request with the same headers, body etc. in the code - I get a 403 error.

That's the code I'm using:

public static void sendPOST(String testKey, String status) throws IOException {
String POST_PARAMS = buildRequestBody(testKey,status);
URL obj = new URL(POST_URL);
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Cache-Control", "no-cache");
con.setRequestProperty("Authorization", "Basic *********");

// For POST only - START
con.setDoOutput(true);
OutputStream os = con.getOutputStream();
os.write(POST_PARAMS.getBytes());
System.out.println(os);
os.flush();
os.close();
// For POST only - END

int responseCode = con.getResponseCode();
System.out.println("POST Response Code :: " + responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) { //success
BufferedReader in = new BufferedReader(new InputStreamReader(
con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();

// print result
System.out.println(response.toString());
} else {
System.out.println("POST request didn't work.");
}
}

Please help.

Thanks,
Ifat. 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Vitor Pelizza December 13, 2018

Hi @Ifatsharifi,

If you are getting a 403 that's surely an authentication problem. Actually, Jira handles authentication even before the request reaches the add-on.

How are you building the user/pass parameter? It should be:

Authorization: Basic user:password
TAGS
AUG Leaders

Atlassian Community Events