JIRA API Update User return STATUS CODE 404

RandyD September 19, 2019

Here is the code Im using in jquery
$.ajax({
url: "/rest/api/2/user/username",
type: 'PUT',
data:{emailAddress:"test@mail.com"},
dataType: 'json',
contentType:"application/json",
success: function(res) {
console.log(res);
}
});


and always return STATUS CODE 404

and also ive tried
$.ajax({
url: "/rest/api/2/user?username=username",
type: 'PUT',
data:{emailAddress:"test@mail.com"},
dataType: 'json',
contentType:"application/json",
success: function(res) {
console.log(res);
}
});

and returned status code 400

how could i edit user email in jira api?

1 answer

1 accepted

0 votes
Answer accepted
Rafael Pinto Sperafico
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.
September 19, 2019

Hi @RandyD ,

Before attempting on updating any user information, you have to identify against which Users Directory the information will be update. Depending you your Users Directory configuration, you will not be able to update user's information from within Jira, because Jira is Synchronizing data from external directories in Read-only mode.

If the user in which you are attempting to update comes from a directory configured as Read-only, then the change must be done on its source (location where user is being fetched from).

If it is not in Read-only mode, then based on your example, this Ajax call would be executed from Jira, as this will be the way for the Ajax call to append the url you have provided (/rest/api/2/user/username) in the command with Jira's Base URL. If you are running this from another application other than Jira, than the url could thrown the 404 HTTP status code because the application where the Ajax is called from does not have that endpoint.

Please, find below the Ajax call you could be using:

$.ajax({
url: "/rest/api/2/user?username=admin",
type: 'PUT',
data: '{"emailAddress":"admin@localhost.com"}',
dataType: 'json',
contentType:"application/json",
success: function(res) {
console.log(res);
}
});

The issue was in your data attribute, you were passing a JSON object and not a String version of it. For that purpose, keys must be surrounded by double-quotes.

If you want you use your version or provide a JSON object, then you should be calling JSON.stringify() passing your JSON object as a parameter:

$.ajax({
url: "/rest/api/2/user?username=admin",
type: 'PUT',
data: JSON.stringify({"emailAddress":"admin@localhost.com"}),
dataType: 'json',
contentType:"application/json",
success: function(res) {
console.log(res);
}
});
$.ajax({
url: "/rest/api/2/user?username=admin",
type: 'PUT',
data: JSON.stringify({emailAddress:"admin@localhost.com"}),
dataType: 'json',
contentType:"application/json",
success: function(res) {
console.log(res);
}
});

Here is an example on how to run the same endpoint using cURL:

# http://localhost:8080/jira is the base URL in this example

curl -k -u admin:admin \
-H 'Content-type: application/json' \
-d '{"emailAddress":"myuser@localhost.com"}' \
-X PUT http://localhost:8080/jira/rest/api/2/user?username=myuser

For more information, please review example in https://docs.atlassian.com/software/jira/docs/api/REST/8.4.1/#api/2/user-updateUser documentation:

Kind regards,
Rafael

RandyD September 20, 2019

thanks for the response we will check on this.

RandyD September 20, 2019

the solution is to json stringify the data thanks

Suggest an answer

Log in or Sign up to answer