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.
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
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.