Hello,
I am trying to make POST requests to the Jira REST API, however when I try to create an issue, it gives me a 400 error with:
{"errorMessages":[],"errors":{"summary":"Field 'summary' cannot be set. It is not on the appropriate screen, or unknown.","description":"Field 'description' cannot be set. It is not on the appropriate screen, or unknown."}}
My JSON is exactly like the example ones Atlassian provides, so I checked my user permissions through the REST API. It returns that the account does not have permission to create an issue, but the account Im using is a site admin and has full access to do anything in my instance of Jira.
When I try to get session info, it returns this:
{"errorMessages":["You are not authenticated. Authentication required to perform this operation."],"errors":{}}
I am confused as to why I'm not getting authenticated when I have a basic auth header in my request. Here is a snippet of my code in Java:
HttpHost proxy = new HttpHost("host", port);
Credentials credentials = new UsernamePasswordCredentials("user","password");
AuthScope authScope = new AuthScope("host", port);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(authScope, credentials);
HttpClient client = HttpClientBuilder.create().setProxy(proxy).setDefaultCredentialsProvider(credsProvider).build();
HttpPost request = new HttpPost("https://myinstance.net/rest/auth/latest/session");
String headerVal = USERNAME + ":" + API_TOKEN;
String authorizationHeader = "Basic " + Base64.getEncoder().encodeToString(headerVal.getBytes("utf-8"));
request.addHeader("Content-Type", "application/json");
request.addHeader("Accept", "application/json");
StringEntity params = new StringEntity(testIssue.toString());
request.setEntity(params);
request.addHeader("Authorization", authorizationHeader);
HttpResponse response = client.execute(request);
The first bit of authentication is for my company proxy, for some reason Eclipse wouldn't hit the proxy so I had to force my code to go through it, hence the proxy stuff and authentication. The second bit of authentication is in the header for the Jira request.
I have a feeling my proxy procedures are messing with my authentication, because I know this account has access to everything, as I have used it before for another project using the rest api and it worked.
Can anyone offer any suggestions or ideas? I have been stuck on this for a day or two.
Hi @fza
What is going into the variable USERNAME? As from early June, you need to use your Jira e-mail address and token not username and token - hopefully it is as simple as that
You might want to try running this API call through Postman to ensure that the issue really is your authentication
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I read that for HttpClient in java, it waits for an authentication challenge before it sends the basic auth credentials, however Jira doesnt send basic auth challenges. It was sending me OAuth challenges to which my basic auth credentials were being used and failed.
I just implemented OAuth now and it seems to be authenticating, however I am facing some new issues. I am now getting a 403 error when I try to GET an issue from a project with this error message:
{"errorMessages":["OAuth 2.0 is not enabled for this method."]}
I dont know why it would do this because i requested scopes for creating/modifying issues as well as read issues.
Sorry for changing the topic now, but do you have any ideas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.