Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

Recognition

  • Give kudos
  • My kudos

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

JIRA API Update User return STATUS CODE 404 Edited

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

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

thanks for the response we will check on this.

the solution is to json stringify the data thanks

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Software

How to create Jira issus from Excel file?

When to use CSV importer When managing your processes in Jira, there are many occasions where you need to create a lot of tasks. Creating them one by one will cost you a lot of time and effort and i...

4,549 views 22 32
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you