400 error in creating project using user impersonation in atlassian connect

I went through this link https://developer.atlassian.com/cloud/jira/platform/user-impersonation-for-connect-apps/ about user impersonation and try to use it for creating project in jira. I am getting the jwt bearer token. But when I am trying to post the data getting below error

Can not instantiate value of type [simple type, class com.atlassian.jira.rest.v2.issue.project.ProjectInputBean] from JSON String; no single-String constructor/factory method'

I am passing the below json object as request body for the POST

let bodyData = `{
            "notificationScheme": 10000,
            "description": "Sample Project description",
            "leadAccountId": "xxxxxxxxx",
            "url": "http://atlassian.com",
            "projectTemplateKey": "com.pyxis.greenhopper.jira:gh-simplified-basic",
            "avatarId": 10400,
            "issueSecurityScheme": 10000,
            "name": "Sample",
            "permissionScheme": 10000,
            "assigneeType": "PROJECT_LEAD",
            "projectTypeKey": "software",
            "key": "SAM",
            "categoryId": 10000
          }`;

Note: This is working using basic auth in a rest client. Also using the same format mentioned in the document https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-rest-api-2-project-post
What is it, that I’m doing wrong here?

1 Like

I found the solution to my problem. My post request was like this

request.post({
            url: '<baseurl>/rest/api/2/project',
            json: true
            headers: {
                "Authorization": "Bearer " + access_token,
                "Accept": "application/json",
                "Content-Type": "application/json"
            },
            body : bodyData
        }

I removed the

json: true

option and the rest call is working as expected.