🔐

Application Roles

Jira application roles are a way of managing user permissions and access in Jira. Jira comes with a set of predefined roles that define common types of users, such as administrators, developers, and project managers.
Each Jira application role has a set of permissions associated with it, which determine what actions a user in that role is allowed to perform. For example, the "Admin" role has permission to manage Jira system settings and users, while the "Developer" role has permission to create and edit issues and view source code.

Get all application roles

This Jira API endpoint is used to retrieve a list of all application roles that are defined in a Jira instance. This endpoint can be used to get information about the roles that are available in Jira, and to help manage user access and permissions.
The response from the API is a JSON object that contains information about all of the roles in Jira. The JSON object includes an array of roles, where each role is represented by an object with the following fields:
  • id: The unique identifier for the role.
  • name: The name of the role.
  • description: A description of the role.
For example, the response might look something like this:
Response Example
{
"size": 2,
"items": [
{
"id": 10002,
"name": "Administrators",
"description": "Jira administrators"
},
{
"id": 10001,
"name": "Users",
"description": "Jira users"
}
]
}
1
package main
2
3
import (
4
"context"
5
_ "github.com/ctreminiom/go-atlassian/jira/v2"
6
"github.com/ctreminiom/go-atlassian/jira/v3"
7
"log"
8
"os"
9
)
10
11
func main() {
12
13
var (
14
host = os.Getenv("HOST")
15
mail = os.Getenv("MAIL")
16
token = os.Getenv("TOKEN")
17
)
18
19
jira, err := v3.New(nil, host)
20
if err != nil {
21
return
22
}
23
24
jira.Auth.SetBasicAuth(mail, token)
25
jira.Auth.SetUserAgent("curl/7.54.0")
26
27
applicationRoles, response, err := jira.Role.Gets(context.Background())
28
if err != nil {
29
if response != nil {
30
log.Println("Response HTTP Response", response.Bytes.String())
31
}
32
log.Fatal(err)
33
}
34
35
log.Println("Response HTTP Code", response.Code)
36
log.Println("HTTP Endpoint Used", response.Endpoint)
37
38
for _, role := range applicationRoles {
39
log.Println(role.Key, role.Name)
40
}
41
42
return
43
}
44

Get application role

This method allows you to retrieve information about a specific application role in Jira using the key name as reference.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/jira/v2"
"github.com/ctreminiom/go-atlassian/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
role, response, err := jira.Role.Get(context.Background(), "jira-core")
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("Status HTTP Response", response.Status)
}
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("Application Role Name: %v", role.Name)
log.Printf("Application Role Key: %v", role.Key)
log.Printf("Application Role User Count: %v", role.UserCount)
return
}