Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

rest/api/2/user error "can not instantiate value of type issue.UserWriteBean"

Brian Craigie February 2, 2023

Trying to create a user in Jira DataCentre 8.20 using the API rest/api/2/user listed as "experimental" using Python Requests

I'm sending a POST with the header 'Content-Type': 'application/json;charset=UTF-8'

data as follows (redacted):

{"name": "username","emailAddress": "forename.surname@domain.co.uk","displayName": "Forename Surname","applicationKeys": ["jira-software-users"]}

And it gives me back the error:

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

Have I made a mistake with the JSON string, or some other error?

I'm assuming applicationKeys corresponds to the Jira user group to add the user to.

Thanks

Brian

2 answers

1 vote
Brian Craigie February 3, 2023

Aha!  I found the answer. I guess the clue was the "single string" part of the error.

I was using Python Requests, and in the call:

session.post(hostURL, json=my_data) 

I was already passing json data as my_data.  So it was encoding it twice.

I changed it to 

session.headers['Content-Type'] = 'application/json'
session.post(hostURL, data=my_data)

It now works!

It didn't add the user to the group "jira-software-users" so I guess the applicationKeys parameter is for something else.  I guess I can just add the user to the group in a later call to update the user.

I hope that helps others who come across this. :-)

Brian Craigie February 3, 2023

I found if I omit the applicationKeys section, the user is created in the correct group anyway.

Vamsi Kandala
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 3, 2023

Hi @Brian Craigie

Glad that you are able to resolve the issue.

Regards,
Vamsi

Saurabh Kejriwal January 26, 2024

Hi @Brian Craigie I faced the exact same issue. This solution of passing data=my_data really helped me. It solved my problem. Many many thanks.

0 votes
Vamsi Kandala
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 2, 2023

Hi @Brian Craigie

Welcome to the community!

Can you update the JSON data like below and try?  I have enclosed everything within 'fields' section:

 

{

    "fields": {

       "name""username",

       "emailAddress""forename.surname@domain.co.uk",

       "displayName""Forename Surname",

       "applicationKeys": ["jira-software-users"]

    }

}
Hope this helps.
Thanks,
Vamsi
Brian Craigie February 2, 2023

@Vamsi Kandala Thank you for your kind welcome and your reply.  However, that gives me the same error message.

I was using the example in the API documentation, albeit the documentation is for 9.5, not 8.20.

The example shows:

{
"
name": "charlie",
"
password": "abracadabra",
"
emailAddress": "charlie@atlassian.com",
"
displayName": "Charlie of Atlassian",
"
applicationKeys": [ "jira-core" ]
}

I am omitting the password as the documentation says "If password field is not set then password will be randomly generated." 

I tried adding the password, but still get the same error.

I've also confirmed I get the same error using Jira DataCentre 9.4

Thanks again.

Brian

Suggest an answer

Log in or Sign up to answer