# Create project REST API in Spring boot application for Jira Cloud Add-on gives 400 error

**URL:** <https://community.developer.atlassian.com/t/create-project-rest-api-in-spring-boot-application-for-jira-cloud-add-on-gives-400-error/29899>\
**Category:** Jira Cloud\
**Tags:** ac-spring-boot\
**Created:** [June 14, 2019, 12:33pm UTC](https://community.developer.atlassian.com/t/create-project-rest-api-in-spring-boot-application-for-jira-cloud-add-on-gives-400-error/29899 "2019-06-14T12:33:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![zuber](https://avatars.discourse-cdn.com/v4/letter/z/ed8c4c/32.png) [@zuber](https://community.developer.atlassian.com/u/zuber)\
**Post date:** [June 14, 2019, 12:33pm UTC](https://community.developer.atlassian.com/t/create-project-rest-api-in-spring-boot-application-for-jira-cloud-add-on-gives-400-error/29899/1 "2019-06-14T12:33:55Z")

</div>

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:

```auto
@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:

```auto
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

---

<div class="post-metadata">

**Author:** ![epehrson](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/epehrson/32/35813_2.png) [@epehrson](https://community.developer.atlassian.com/u/epehrson)\
**Post date:** [June 14, 2019, 1:52pm UTC](https://community.developer.atlassian.com/t/create-project-rest-api-in-spring-boot-application-for-jira-cloud-add-on-gives-400-error/29899/2 "2019-06-14T13:52:03Z")

</div>

Hi @zuber,

I assume that Jira is returning a detailed error message along with the 400 status code, so I suggest making sure that is printed first of all.

You can bump the log level of `RestTemplate` using `logging.level.org.springframework.web.client=DEBUG`, as described in [this StackOverflow post](https://stackoverflow.com/questions/7952154).

But I also recall coming across [SPR-9367](https://github.com/spring-projects/spring-framework/issues/14004), suggesting that the default `SimpleClientHttpRequestFactory` doesn’t support this, and that the best solution is switching the underlying HTTP client to Apache HttpComponents.

```auto
@Bean
public RestTemplateCustomizer httpComponentsRestTemplateRequestFactoryCustomizer() {
    return restTemplate -> restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
}

```

Once you’ve done that, you can also bump `logging.level.org.apache.http=DEBUG`.

---

<div class="post-metadata">

**Author:** ![zuber](https://avatars.discourse-cdn.com/v4/letter/z/ed8c4c/32.png) [@zuber](https://community.developer.atlassian.com/u/zuber)\
**Post date:** [June 17, 2019, 10:23am UTC](https://community.developer.atlassian.com/t/create-project-rest-api-in-spring-boot-application-for-jira-cloud-add-on-gives-400-error/29899/3 "2019-06-17T10:23:33Z")

</div>

Hi @epehrson,

Thanks for guiding how to debug the API request. I get the following error message in response:

```auto
"{"errorMessages":["'accountId' must be the only user identifying query parameter in GDPR strict mode."],"errors":{}}[\r][\n]"

```

I tried disabling gdpr under apiMigrations. I am still getting this error. Is there anything that I am missing?  
Thanks

---

<div class="post-metadata">

**Author:** ![epehrson](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/epehrson/32/35813_2.png) [@epehrson](https://community.developer.atlassian.com/u/epehrson)\
**Post date:** [June 17, 2019, 12:15pm UTC](https://community.developer.atlassian.com/t/create-project-rest-api-in-spring-boot-application-for-jira-cloud-add-on-gives-400-error/29899/4 "2019-06-17T12:15:08Z")

</div>

@zuber, see the documentation for the `lead` parameter to [POST /rest/api/3/project](https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-rest-api-3-project-post).

The GDPR deprecation period has officially ended, and the request you are making needs to satisfy the new contract.

---

<div class="post-metadata">

**Author:** ![zuber](https://avatars.discourse-cdn.com/v4/letter/z/ed8c4c/32.png) [@zuber](https://community.developer.atlassian.com/u/zuber)\
**Post date:** [June 17, 2019, 12:32pm UTC](https://community.developer.atlassian.com/t/create-project-rest-api-in-spring-boot-application-for-jira-cloud-add-on-gives-400-error/29899/5 "2019-06-17T12:32:09Z")

</div>

Hi @epehrson,

Do you mean the “lead” parameter is no longer available even when I use /rest/api/2/project ? I even tried using “leadAccountId” instead of “lead” but then that gave me unrecognized field error for it:

```auto
"{"errorMessages":["Unrecognized field \"leadAccountId \" (Class com.atlassian.jira.rest.v2.issue.project.ProjectInputBean), not marked as ignorable\n at [Source: com.atlassian.plugin.connect.plugin.auth.scope.InputConsumingHttpServletRequest$1@60dc487f; line: 1, column: 125] (through reference chain: com.atlassian.jira.rest.v2.issue.project.ProjectInputBean[\"leadAccountId \"])"]}[\r][\n]"

```

---

<div class="post-metadata">

**Author:** ![epehrson](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/epehrson/32/35813_2.png) [@epehrson](https://community.developer.atlassian.com/u/epehrson)\
**Post date:** [June 17, 2019, 1:42pm UTC](https://community.developer.atlassian.com/t/create-project-rest-api-in-spring-boot-application-for-jira-cloud-add-on-gives-400-error/29899/6 "2019-06-17T13:42:10Z")

</div>

@zuber the error message suggests you have a trailing space in the field name `"leadAccountId "`.

---

<div class="post-metadata">

**Author:** ![zuber](https://avatars.discourse-cdn.com/v4/letter/z/ed8c4c/32.png) [@zuber](https://community.developer.atlassian.com/u/zuber)\
**Post date:** [June 17, 2019, 1:47pm UTC](https://community.developer.atlassian.com/t/create-project-rest-api-in-spring-boot-application-for-jira-cloud-add-on-gives-400-error/29899/7 "2019-06-17T13:47:17Z")

</div>

Oops! I missed such a small thing here. Thanks @epehrson for pointing it! It works now!

---

<div class="post-metadata">

**Author:** ![ChakreshTiwari](https://avatars.discourse-cdn.com/v4/letter/c/c4cdca/32.png) [@ChakreshTiwari](https://community.developer.atlassian.com/u/ChakreshTiwari)\
**Post date:** [April 1, 2020, 10:00am UTC](https://community.developer.atlassian.com/t/create-project-rest-api-in-spring-boot-application-for-jira-cloud-add-on-gives-400-error/29899/8 "2020-04-01T10:00:10Z")

</div>

Hi @zuber  
I am also trying the same rest call and getting the same errors first thing how u passed this leadAccountId value in params and second thing for resolving this 400 status code. I added the @Bean in the main class and after that in yml file debug also but still same errors. Can u share your code or thoughts about how to fix these issues.  
It will be a great help. Thanks

---

<div class="post-metadata">

**Author:** ![ChakreshTiwari](https://avatars.discourse-cdn.com/v4/letter/c/c4cdca/32.png) [@ChakreshTiwari](https://community.developer.atlassian.com/u/ChakreshTiwari)\
**Post date:** [April 1, 2020, 11:00am UTC](https://community.developer.atlassian.com/t/create-project-rest-api-in-spring-boot-application-for-jira-cloud-add-on-gives-400-error/29899/9 "2020-04-01T11:00:55Z")

</div>

Hi @epehrson  
Can You Please tell me how to do that i have written this bean in my main class but still getiing same error.  
Any suggestions what i am doing wrong.  
Thanks
