Run REST API on behalf of another user
General information
Since v. 1.7.0 - changes in supported endpoint URLs - JIRA_URL/rest/*
Available for:
JIRA administrator - includes all of the following REST API:
JIRA_URL/rest/*
dedicated user groups (since v. 1.7.0 - please check REST API Configuration page)
How it’s works
It’s simple, just add into REST API request new header parameter contextUser containing username in the context of which we want to execute REST API.
CURL example
See how use contextUser in unix curl command
Create CURL command (admin credential, new header contextUser set to user) and run it.
curl -u admin:admin -H "Content-Type: application/json" -H "contextUser: user" --data '{"body":"REST API Extender works good :) - CURL Example"}' -X POST http://localhost:2990/jira/rest/api/2/issue/PROJA-1/comment |
Response in terminal
"self":"http://localhost:2990/jira/rest/api/2/issue/10000/comment/10102","id":"10102","author":{"self":"http://localhost:2990/jira/rest/api/2/user?username=user","name":"user","key":"JIRAUSER10100","emailAddress":"user@jira.user.pl","avatarUrls":{"48x48":"https://www.gravatar.com/avatar/34c897cf89d2c13ed8dad7ca51ea0edf?d=mm&s=48","24x24":"https://www.gravatar.com/avatar/34c897cf89d2c13ed8dad7ca51ea0edf?d=mm&s=24","16x16":"https://www.gravatar.com/avatar/34c897cf89d2c13ed8dad7ca51ea0edf?d=mm&s=16","32x32":"https://www.gravatar.com/avatar/34c897cf89d2c13ed8dad7ca51ea0edf?d=mm&s=32"},"displayName":"user","active":true,"timeZone":"Europe/Warsaw"},"body":"test","updateAuthor":{"self":"http://localhost:2990/jira/rest/api/2/user?username=user","name":"user","key":"JIRAUSER10100","emailAddress":"user@jira.user.pl","avatarUrls":{"48x48":"https://www.gravatar.com/avatar/34c897cf89d2c13ed8dad7ca51ea0edf?d=mm&s=48","24x24":"https://www.gravatar.com/avatar/34c897cf89d2c13ed8dad7ca51ea0edf?d=mm&s=24","16x16":"https://www.gravatar.com/avatar/34c897cf89d2c13ed8dad7ca51ea0edf?d=mm&s=16","32x32":"https://www.gravatar.com/avatar/34c897cf89d2c13ed8dad7ca51ea0edf?d=mm&s=32"},"displayName":"user","active":true,"timeZone":"Europe/Warsaw"},"created":"2019-11-01T15:10:25.658+0100","updated":"2019-11-01T15:10:25.658+0100"} |
Jira view
Postman example
See how use contextUser in Postman
Use in authorization section a user with administrator privileges
In context section add new header contextUser. Enter in value another user name, for example i used user named user
Set body for specific REST and click Send
Comment was added to issue for user user. Response body looks like this:
{
    "self": "http://localhost:2990/jira/rest/api/2/issue/10000/comment/10125",
    "id": "10125",
    "author": {
        "self": "http://localhost:2990/jira/rest/api/2/user?username=user",
        "name": "user",
        "key": "user",
        ...
    },
    "body": "REST API Extender works good :)",
    "updateAuthor": {
        "self": "http://localhost:2990/jira/rest/api/2/user?username=user",
        "name": "user",
        "key": "user",
        "emailAddress": "user@user.user",
        ...
    },
    "created": "2017-08-04T20:50:23.351+0200",
    "updated": "2017-08-04T20:50:23.351+0200"
} |
Jira view