πŸ€“
Users
This resource represent users.

Get user

Returns a user.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/jira/v2"
6
"log"
7
"os"
8
)
9
​
10
func main() {
11
​
12
/*
13
----------- Set an environment variable in git bash -----------
14
export HOST="https://ctreminiom.atlassian.net/"
15
export MAIL="MAIL_ADDRESS"
16
export TOKEN="TOKEN_API"
17
​
18
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
19
*/
20
​
21
var (
22
host = os.Getenv("HOST")
23
mail = os.Getenv("MAIL")
24
token = os.Getenv("TOKEN")
25
)
26
​
27
atlassian, err := v2.New(nil, host)
28
if err != nil {
29
log.Fatal(err)
30
}
31
​
32
atlassian.Auth.SetBasicAuth(mail, token)
33
​
34
var (
35
accountID = "5b86be50b8e3cb5895860d6d"
36
expands = []string{"groups", "applicationRoles"}
37
)
38
​
39
user, response, err := atlassian.User.Get(context.Background(), accountID, expands)
40
if err != nil {
41
log.Fatal(err)
42
}
43
​
44
log.Println("HTTP Endpoint Used", response.Endpoint)
45
log.Println(user)
46
​
47
}
Copied!
πŸ§šβ€β™€οΈ Tips: You can extract the following struct tags
1
type UserScheme struct {
2
Self string `json:"self,omitempty"`
3
Key string `json:"key,omitempty"`
4
AccountID string `json:"accountId,omitempty"`
5
AccountType string `json:"accountType,omitempty"`
6
Name string `json:"name,omitempty"`
7
EmailAddress string `json:"emailAddress,omitempty"`
8
AvatarUrls *AvatarURLScheme `json:"avatarUrls,omitempty"`
9
DisplayName string `json:"displayName,omitempty"`
10
Active bool `json:"active,omitempty"`
11
TimeZone string `json:"timeZone,omitempty"`
12
Locale string `json:"locale,omitempty"`
13
Groups *UserGroupsScheme `json:"groups,omitempty"`
14
ApplicationRoles *UserApplicationRolesScheme `json:"applicationRoles,omitempty"`
15
Expand string `json:"expand,omitempty"`
16
}
17
​
18
type UserApplicationRolesScheme struct {
19
Size int `json:"size,omitempty"`
20
Items []*UserApplicationRoleItemsScheme `json:"items,omitempty"`
21
MaxResults int `json:"max-results,omitempty"`
22
}
23
​
24
type UserApplicationRoleItemsScheme struct {
25
Key string `json:"key,omitempty"`
26
Groups []string `json:"groups,omitempty"`
27
Name string `json:"name,omitempty"`
28
DefaultGroups []string `json:"defaultGroups,omitempty"`
29
SelectedByDefault bool `json:"selectedByDefault,omitempty"`
30
Defined bool `json:"defined,omitempty"`
31
NumberOfSeats int `json:"numberOfSeats,omitempty"`
32
RemainingSeats int `json:"remainingSeats,omitempty"`
33
UserCount int `json:"userCount,omitempty"`
34
UserCountDescription string `json:"userCountDescription,omitempty"`
35
HasUnlimitedSeats bool `json:"hasUnlimitedSeats,omitempty"`
36
Platform bool `json:"platform,omitempty"`
37
}
38
​
39
type UserGroupsScheme struct {
40
Size int `json:"size,omitempty"`
41
Items []*UserGroupScheme `json:"items,omitempty"`
42
MaxResults int `json:"max-results,omitempty"`
43
}
Copied!

Create user

Creates a user. This resource is retained for legacy compatibility. As soon as a more suitable alternative is available this resource will be deprecated.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/jira/v2"
6
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
7
"log"
8
"os"
9
)
10
​
11
func main() {
12
​
13
/*
14
----------- Set an environment variable in git bash -----------
15
export HOST="https://ctreminiom.atlassian.net/"
16
export MAIL="MAIL_ADDRESS"
17
export TOKEN="TOKEN_API"
18
​
19
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
20
*/
21
​
22
var (
23
host = os.Getenv("HOST")
24
mail = os.Getenv("MAIL")
25
token = os.Getenv("TOKEN")
26
)
27
​
28
atlassian, err := v2.New(nil, host)
29
if err != nil {
30
log.Fatal(err)
31
}
32
​
33
atlassian.Auth.SetBasicAuth(mail, token)
34
​
35
payload := &models.UserPayloadScheme{
36
EmailAddress: "[email protected]",
37
DisplayName: "Example DisplayName",
38
Notification: false,
39
}
40
​
41
newUser, response, err := atlassian.User.Create(context.Background(), payload)
42
if err != nil {
43
log.Fatal(err)
44
}
45
​
46
log.Println("HTTP Endpoint Used", response.Endpoint)
47
log.Println("The new user has been created", newUser.AccountID)
48
}
Copied!

Delete user

Deletes a user.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/jira/v2"
6
"log"
7
"os"
8
)
9
​
10
func main() {
11
​
12
/*
13
----------- Set an environment variable in git bash -----------
14
export HOST="https://ctreminiom.atlassian.net/"
15
export MAIL="MAIL_ADDRESS"
16
export TOKEN="TOKEN_API"
17
​
18
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
19
*/
20
​
21
var (
22
host = os.Getenv("HOST")
23
mail = os.Getenv("MAIL")
24
token = os.Getenv("TOKEN")
25
)
26
​
27
atlassian, err := v2.New(nil, host)
28
if err != nil {
29
log.Fatal(err)
30
}
31
​
32
atlassian.Auth.SetBasicAuth(mail, token)
33
​
34
response, err := atlassian.User.Delete(context.Background(), "607b98df2ad11c0072664322")
35
if err != nil {
36
log.Fatal(err)
37
}
38
​
39
log.Println("HTTP Endpoint Used", response.Endpoint)
40
}
Copied!

Bulk get users

Returns a paginated list of the users specified by one or more account IDs.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/jira/v2"
6
"log"
7
"os"
8
)
9
​
10
func main() {
11
​
12
/*
13
----------- Set an environment variable in git bash -----------
14
export HOST="https://ctreminiom.atlassian.net/"
15
export MAIL="MAIL_ADDRESS"
16
export TOKEN="TOKEN_API"
17
​
18
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
19
*/
20
​
21
var (
22
host = os.Getenv("HOST")
23
mail = os.Getenv("MAIL")
24
token = os.Getenv("TOKEN")
25
)
26
​
27
atlassian, err := v2.New(nil, host)
28
if err != nil {
29
log.Fatal(err)
30
}
31
​
32
atlassian.Auth.SetBasicAuth(mail, token)
33
​
34
var (
35
accountIDs = []string{"5b86be50b8e3cb5895860d6d"}
36
startAt = 0
37
maxResults = 50
38
)
39
​
40
users, response, err := atlassian.User.Find(context.Background(), accountIDs, startAt, maxResults)
41
if err != nil {
42
log.Fatal(err)
43
}
44
​
45
log.Println("HTTP Endpoint Used", response.Endpoint)
46
​
47
for _, user := range users.Values {
48
log.Println(user.DisplayName)
49
}
50
}
Copied!

Get user groups

Returns the groups to which a user belongs.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/jira/v2"
6
"log"
7
"os"
8
)
9
​
10
func main() {
11
​
12
/*
13
----------- Set an environment variable in git bash -----------
14
export HOST="https://ctreminiom.atlassian.net/"
15
export MAIL="MAIL_ADDRESS"
16
export TOKEN="TOKEN_API"
17
​
18
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
19
*/
20
​
21
var (
22
host = os.Getenv("HOST")
23
mail = os.Getenv("MAIL")
24
token = os.Getenv("TOKEN")
25
)
26
​
27
atlassian, err := v2.New(nil, host)
28
if err != nil {
29
log.Fatal(err)
30
}
31
​
32
atlassian.Auth.SetBasicAuth(mail, token)
33
​
34
var accountID = "5b86be50b8e3cb5895860d6d"
35
groups, response, err := atlassian.User.Groups(context.Background(), accountID)
36
if err != nil {
37
log.Fatal(err)
38
}
39
​
40
log.Println("HTTP Endpoint Used", response.Endpoint)
41
​
42
for _, group := range groups {
43
log.Println(group)
44
}
45
​
46
}
47
​
Copied!

Get all users

Returns a list of all (active and inactive) users.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/jira/v2"
6
"log"
7
"os"
8
)
9
​
10
func main() {
11
​
12
/*
13
----------- Set an environment variable in git bash -----------
14
export HOST="https://ctreminiom.atlassian.net/"
15
export MAIL="MAIL_ADDRESS"
16
export TOKEN="TOKEN_API"
17
​
18
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
19
*/
20
​
21
var (
22
host = os.Getenv("HOST")
23
mail = os.Getenv("MAIL")
24
token = os.Getenv("TOKEN")
25
)
26
​
27
atlassian, err := v2.New(nil, host)
28
if err != nil {
29
log.Fatal(err)
30
}
31
​
32
atlassian.Auth.SetBasicAuth(mail, token)
33
​
34
var (
35
startAt = 0
36
maxResults = 50
37
)
38
​
39
users, response, err := atlassian.User.Gets(context.Background(), startAt, maxResults)
40
if err != nil {
41
log.Fatal(err)
42
}
43
​
44
log.Println("HTTP Endpoint Used", response.Endpoint)
45
​
46
for _, user := range users {
47
log.Println(user)
48
}
49
}
Copied!