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?
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
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.