Hello,
I am creating a Jira Cloud Add-on on Spring Boot. In that I have an endpoint which creates a project. It gives me an error with 400 status always. Here is my code:
@GetMapping(value = "/createproject", produces = "application/json")
public ResponseEntity<Object> createProject(@AuthenticationPrincipal AtlassianHostUser hostUser) {
String baseURL = hostUser.getHost().getBaseUrl();
StringBuffer url = new StringBuffer(baseURL);
url.append("/rest/api/2/project");
String params = "{\"projectTemplateKey\":\"com.atlassian.jira-core-project-templates:jira-core-simplified-project-management\""
+ ",\"notificationScheme\":10000"
+ ",\"name\":\"My Test Project B\""
+ ",\"permissionScheme\":0"
+ ",\"assigneeType\":\"UNASSIGNED\""
+ ",\"projectTypeKey\":\"business\""
+ ",\"key\":\"TPB\""
+ ",\"lead\":\"admin\""
+ "}";
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", "application/json");
headers.set("Content-Type", "application/json");
headers.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36");
HttpEntity<String> request = null;
try {
request = new HttpEntity<>(params, headers);
} catch (JsonProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ResponseEntity<Object> responseEntity = atlassianHostRestClients.authenticatedAsAddon().exchange(url.toString(), HttpMethod.POST, request, Object.class);
return ResponseEntity.ok().build();
}
I get following exception:
2019-06-12 19:09:44.184 ERROR 8608 --- [nio-8080-exec-6] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.HttpClientErrorException: 400 ] with root cause
org.springframework.web.client.HttpClientErrorException: 400
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:63) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:700) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:653) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:531) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at war.ProjectController.createProject(ProjectController.java:76) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
..........
The request body works using a curl command.
In my app descriptor I have provided scopes as [“ADMIN”]. I also checked that a Get Project API does work in my add-on. Any ideas what am I doing wrong?
Some help would be really appreciated.
Thanks