Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

UserKey are required to perform operations on behalf of a user, I couldn't find any documented api to retrieve userKey, but luckily the deprecated (but still available) prototype API allows to retrieve the userKey for a given user. The information returned is very verbose so I am filtering it down.

Code Block
// get a userkeyfind userKey for username
var username = "patrick";

result.promise = httpClient.get({
  url: '/rest/prototype/1/search/user.json?query=patrick' + }username
).then(function (body) {
	return
    var result = JSON.parse(body).result.mapfilter(function (user) {
      return user.username === username;
    });
  	if(result.length !== 1) {"name": user.username,  "key": user.userKey}
      throw new Error("user " + username  +" not found");
    } else {
      return result[0].userKey;
    });
});