Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,365,180
Community Members
 
Community Events
168
Community Groups

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

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

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

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events