πŸ‘₯
User
The user management REST API lets you manage users (managed accounts) in an organization. Only an organization admin can edit the details of a managed account. As an organization admin with verified domains, you can use the user management REST API to perform operations including:
  • Get a list of your permissions to manage a user
  • Get information about a user
  • Update a user profile or set a user's email address
  • Enable or disable a user

Get user management permissions

Returns the set of permissions you have for managing the specified Atlassian account
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/admin"
6
"log"
7
"os"
8
)
9
​
10
func main() {
11
​
12
//ATLASSIAN_ADMIN_TOKEN
13
var apiKey = os.Getenv("ATLASSIAN_ADMIN_TOKEN")
14
​
15
cloudAdmin, err := admin.New(nil)
16
if err != nil {
17
log.Fatal(err)
18
}
19
​
20
cloudAdmin.Auth.SetBearerToken(apiKey)
21
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
22
​
23
var accountID = "606a7ff396e8d60068a5c652"
24
​
25
permissions, response, err := cloudAdmin.User.Permissions(context.Background(), accountID, nil)
26
if err != nil {
27
if response != nil {
28
log.Println("Response HTTP Response", string(response.BodyAsBytes))
29
}
30
log.Fatal(err)
31
}
32
​
33
log.Println("Response HTTP Code", response.StatusCode)
34
log.Println("HTTP Endpoint Used", response.Endpoint)
35
​
36
log.Println(permissions.APITokenDelete.Allowed)
37
log.Println(permissions.EmailSet.Allowed)
38
}
39
​
Copied!

Get profile

Returns information about a single Atlassian account by ID
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/admin"
6
"log"
7
"os"
8
)
9
​
10
func main() {
11
​
12
//ATLASSIAN_ADMIN_TOKEN
13
var apiKey = os.Getenv("ATLASSIAN_ADMIN_TOKEN")
14
​
15
cloudAdmin, err := admin.New(nil)
16
if err != nil {
17
log.Fatal(err)
18
}
19
​
20
cloudAdmin.Auth.SetBearerToken(apiKey)
21
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
22
​
23
var accountID = "606a7ff396e8d60068a5c652"
24
​
25
user, response, err := cloudAdmin.User.Get(context.Background(), accountID)
26
if err != nil {
27
if response != nil {
28
log.Println("Response HTTP Response", string(response.BodyAsBytes))
29
}
30
log.Fatal(err)
31
}
32
​
33
log.Println("Response HTTP Code", response.StatusCode)
34
log.Println("HTTP Endpoint Used", response.Endpoint)
35
​
36
log.Println(user.Account.Name, user.Account.AccountType)
37
}
38
​
Copied!
πŸ§šβ€β™€οΈ Tips: You can extract the following struct tags
1
type UserScheme struct {
2
Account struct {
3
AccountID string `json:"account_id"`
4
Name string `json:"name"`
5
Nickname string `json:"nickname"`
6
Zoneinfo string `json:"zoneinfo"`
7
Locale string `json:"locale"`
8
Email string `json:"email"`
9
Picture string `json:"picture"`
10
ExtendedProfile struct {
11
JobTitle string `json:"job_title"`
12
TeamType string `json:"team_type"`
13
} `json:"extended_profile"`
14
AccountType string `json:"account_type"`
15
AccountStatus string `json:"account_status"`
16
EmailVerified bool `json:"email_verified"`
17
PrivacySettings struct {
18
Name string `json:"name"`
19
Nickname string `json:"nickname"`
20
Picture string `json:"picture"`
21
ExtendedProfileJobTitle string `json:"extended_profile.job_title"`
22
ExtendedProfileDepartment string `json:"extended_profile.department"`
23
ExtendedProfileOrganization string `json:"extended_profile.organization"`
24
ExtendedProfileLocation string `json:"extended_profile.location"`
25
ZoneInfo string `json:"zoneinfo"`
26
Email string `json:"email"`
27
ExtendedProfilePhoneNumber string `json:"extended_profile.phone_number"`
28
ExtendedProfileTeamType string `json:"extended_profile.team_type"`
29
} `json:"privacy_settings"`
30
} `json:"account"`
31
}
Copied!

Update profile

Updates fields in a user account. The profile.write privilege details which fields you can change.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/admin"
6
"log"
7
"os"
8
)
9
​
10
func main() {
11
​
12
//ATLASSIAN_ADMIN_TOKEN
13
var apiKey = os.Getenv("ATLASSIAN_ADMIN_TOKEN")
14
​
15
cloudAdmin, err := admin.New(nil)
16
if err != nil {
17
log.Fatal(err)
18
}
19
​
20
cloudAdmin.Auth.SetBearerToken(apiKey)
21
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
22
​
23
var accountID = "5e5f6a63157ed50cd2b9eaca"
24
​
25
/*
26
-------------- NOTE --------------
27
The fields the endpoint can edit depends how you configured the user provisioning, for example:
28
If the provisioning is made using the GSuite integration or the SCIM connector, you won't be able to
29
edit that field using this endpoint because that field is blocked.
30
​
31
You can check the availability using the Permission method and searching on the tag permissions.EmailSet.Allowed
32
-------------- NOTE --------------
33
*/
34
var payload = make(map[string]interface{})
35
payload["nickname"] = "marshmallow"
36
​
37
userUpdated, response, err := cloudAdmin.User.Update(context.Background(), accountID, payload)
38
if err != nil {
39
if response != nil {
40
log.Println("Response HTTP Response", string(response.BodyAsBytes))
41
}
42
log.Fatal(err)
43
}
44
​
45
log.Println("Response HTTP Code", response.StatusCode)
46
log.Println("HTTP Endpoint Used", response.Endpoint)
47
log.Println("New NickName, ", userUpdated.Account.Nickname)
48
​
49
}
50
​
Copied!

Disable a user

Disables the specified user account. The permission to make use of this resource is exposed by the lifecycle.enablement privilege. You can optionally set a message associated with the block that will be shown to the user on attempted authentication. If none is supplied, a default message will be used.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/admin"
6
"log"
7
"os"
8
)
9
​
10
func main() {
11
​
12
//ATLASSIAN_ADMIN_TOKEN
13
var apiKey = os.Getenv("ATLASSIAN_ADMIN_TOKEN")
14
​
15
cloudAdmin, err := admin.New(nil)
16
if err != nil {
17
log.Fatal(err)
18
}
19
​
20
cloudAdmin.Auth.SetBearerToken(apiKey)
21
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
22
​
23
/*
24
--------- NOTE ---------
25
You can only disable an account if it's not related to a SCIM integration (GSUITE)
26
--------- NOTE ---------
27
*/
28
​
29
var accountID = "5e5f6a63157ed50cd2b9eaca"
30
​
31
response, err := cloudAdmin.User.Disable(context.Background(), accountID, "Sample message")
32
if err != nil {
33
if response != nil {
34
log.Println("Response HTTP Response", string(response.BodyAsBytes))
35
}
36
log.Fatal(err)
37
}
38
​
39
log.Println("Response HTTP Code", response.StatusCode)
40
log.Println("HTTP Endpoint Used", response.Endpoint)
41
}
42
​
Copied!

Enable a user

Enables the specified user account. The permission to make use of this resource is exposed by the lifecycle.enablement privilege. You can optionally set a message associated with the block that will be shown to the user on attempted authentication. If none is supplied, a default message will be used.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/admin"
6
"log"
7
"os"
8
)
9
​
10
func main() {
11
​
12
//ATLASSIAN_ADMIN_TOKEN
13
var apiKey = os.Getenv("ATLASSIAN_ADMIN_TOKEN")
14
​
15
cloudAdmin, err := admin.New(nil)
16
if err != nil {
17
log.Fatal(err)
18
}
19
​
20
cloudAdmin.Auth.SetBearerToken(apiKey)
21
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
22
​
23
/*
24
--------- NOTE ---------
25
You can only enable an account if it's not related to a SCIM integration (GSUITE)
26
--------- NOTE ---------
27
*/
28
​
29
var accountID = "5e5f6a63157ed50cd2b9eaca"
30
​
31
response, err := cloudAdmin.User.Enable(context.Background(), accountID)
32
if err != nil {
33
if response != nil {
34
log.Println("Response HTTP Response", string(response.BodyAsBytes))
35
}
36
log.Fatal(err)
37
}
38
​
39
log.Println("Response HTTP Code", response.StatusCode)
40
log.Println("HTTP Endpoint Used", response.Endpoint)
41
​
42
}
43
​
Copied!
Last modified 7mo ago