πŸ“”
Organization
The organizations REST API lets you get information about your organizations, including:
  • A list of organizations
  • Information about an organization
  • Users or domains associated with an organization
  • An audit log of events from an organization

Get organizations

Returns a list of your organizations (based on your API key).
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
//https://support.atlassian.com/organization-administration/docs/manage-an-organization-with-the-admin-apis/
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
organizations, response, err := cloudAdmin.Organization.Gets(context.Background(), "")
24
if err != nil {
25
if response != nil {
26
log.Println("Response HTTP Response", response.Bytes.String())
27
}
28
log.Fatal(err)
29
}
30
​
31
log.Println("Response HTTP Code", response.Code)
32
log.Println("HTTP Endpoint Used", response.Endpoint)
33
​
34
for _, organization := range organizations.Data {
35
log.Println(organization.ID, organization.Attributes.Name)
36
}
37
}
38
​
Copied!
πŸ§šβ€β™€οΈ Tips: You can extract the following struct tags
1
type OrganizationPageScheme struct {
2
Data []*OrganizationModelScheme `json:"data,omitempty"`
3
Links *OrganizationLinkPageModelScheme `json:"links,omitempty"`
4
}
5
​
6
type OrganizationLinkPageModelScheme struct {
7
Self string `json:"self,omitempty"`
8
Prev string `json:"prev,omitempty"`
9
Next string `json:"next,omitempty"`
10
}
11
​
12
type OrganizationModelScheme struct {
13
ID string `json:"id,omitempty"`
14
Type string `json:"type,omitempty"`
15
Attributes *OrganizationModelAttribute `json:"attributes,omitempty"`
16
Relationships *OrganizationModelRelationships `json:"relationships,omitempty"`
17
Links *OrganizationLinkSelfModelScheme `json:"links,omitempty"`
18
}
19
​
20
type OrganizationModelAttribute struct {
21
Name string `json:"name,omitempty"`
22
}
23
​
24
type OrganizationModelRelationships struct {
25
Domains *OrganizationModelSchemes `json:"domains,omitempty"`
26
Users *OrganizationModelSchemes `json:"users,omitempty"`
27
}
28
​
29
type OrganizationModelSchemes struct {
30
Links struct {
31
Related string `json:"related,omitempty"`
32
} `json:"links,omitempty"`
33
}
34
​
35
type OrganizationLinkSelfModelScheme struct {
36
Self string `json:"self,omitempty"`
37
}
Copied!

Get an organization by ID

Returns information about a single organization 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 organizationID = "9a1jj823-jac8-123d-jj01-63315k059cb2"
24
​
25
organization, response, err := cloudAdmin.Organization.Get(context.Background(), organizationID)
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
log.Println(organization.Data.ID)
36
}
37
​
Copied!
πŸ§šβ€β™€οΈ Tips: You can extract the following struct tags
1
type OrganizationScheme struct {
2
Data *OrganizationModelScheme `json:"data,omitempty"`
3
}
Copied!

Get users in an organization

Returns a list of users in an organization.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/admin"
6
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
7
"log"
8
"net/url"
9
"os"
10
)
11
​
12
func main() {
13
​
14
//ATLASSIAN_ADMIN_TOKEN
15
var apiKey = os.Getenv("ATLASSIAN_ADMIN_TOKEN")
16
​
17
cloudAdmin, err := admin.New(nil)
18
if err != nil {
19
log.Fatal(err)
20
}
21
​
22
cloudAdmin.Auth.SetBearerToken(apiKey)
23
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
24
​
25
var (
26
organizationID = "9a1jj823-jac8-123d-jj01-63315k059cb2"
27
cursor string
28
userChunks []*models.OrganizationUserPageScheme
29
)
30
​
31
for {
32
​
33
users, response, err := cloudAdmin.Organization.Users(context.Background(), organizationID, cursor)
34
if err != nil {
35
if response != nil {
36
log.Println("Response HTTP Response", response.Bytes.String())
37
}
38
log.Fatal(err)
39
}
40
​
41
log.Println("Response HTTP Code", response.Code)
42
log.Println("HTTP Endpoint Used", response.Endpoint)
43
​
44
userChunks = append(userChunks, users)
45
​
46
if len(users.Links.Next) == 0 {
47
break
48
}
49
​
50
//extract the next cursor pagination
51
nextAsURL, err := url.Parse(users.Links.Next)
52
if err != nil {
53
log.Fatal(err)
54
}
55
​
56
cursor = nextAsURL.Query().Get("cursor")
57
}
58
​
59
for _, chunk := range userChunks {
60
​
61
for _, user := range chunk.Data {
62
log.Println(user.Email, user.Name)
63
}
64
​
65
}
66
​
67
}
Copied!
πŸ§šβ€β™€οΈ Tips: You can extract the following struct tags
1
type OrganizationUserPageScheme struct {
2
Data []*AdminOrganizationUserScheme `json:"data,omitempty"`
3
Links *LinkPageModelScheme `json:"links,omitempty"`
4
Meta struct {
5
Total int `json:"total,omitempty"`
6
} `json:"meta,omitempty"`
7
}
8
​
9
ttype AdminOrganizationUserScheme struct {
10
AccountID string `json:"account_id,omitempty"`
11
AccountType string `json:"account_type,omitempty"`
12
AccountStatus string `json:"account_status,omitempty"`
13
Name string `json:"name,omitempty"`
14
Picture string `json:"picture,omitempty"`
15
Email string `json:"email,omitempty"`
16
AccessBillable bool `json:"access_billable,omitempty"`
17
LastActive string `json:"last_active,omitempty"`
18
ProductAccess []*OrganizationUserProductScheme `json:"product_access,omitempty"`
19
Links *LinkSelfModelScheme `json:"links,omitempty"`
20
}
21
​
22
type OrganizationUserProductScheme struct {
23
Key string `json:"key,omitempty"`
24
Name string `json:"name,omitempty"`
25
URL string `json:"url,omitempty"`
26
LastActive string `json:"last_active,omitempty"`
27
}
Copied!

Get domains in an organization

Returns a list of domains in an organization one page at a time.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/admin"
6
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
7
"log"
8
"net/url"
9
"os"
10
)
11
​
12
func main() {
13
​
14
//ATLASSIAN_ADMIN_TOKEN
15
var apiKey = os.Getenv("ATLASSIAN_ADMIN_TOKEN")
16
​
17
cloudAdmin, err := admin.New(nil)
18
if err != nil {
19
log.Fatal(err)
20
}
21
​
22
cloudAdmin.Auth.SetBearerToken(apiKey)
23
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
24
​
25
var (
26
organizationID = "9a1jj823-jac8-123d-jj01-63315k059cb2"
27
cursor string
28
domainChunks []*models.OrganizationDomainPageScheme
29
)
30
​
31
for {
32
​
33
domains, response, err := cloudAdmin.Organization.Domains(context.Background(), organizationID, cursor)
34
if err != nil {
35
if response != nil {
36
log.Println("Response HTTP Response", response.Bytes.String())
37
}
38
log.Fatal(err)
39
}
40
​
41
log.Println("Response HTTP Code", response.Code)
42
log.Println("HTTP Endpoint Used", response.Endpoint)
43
domainChunks = append(domainChunks, domains)
44
​
45
if len(domains.Links.Next) == 0 {
46
break
47
}
48
​
49
//extract the next cursor pagination
50
nextAsURL, err := url.Parse(domains.Links.Next)
51
if err != nil {
52
log.Fatal(err)
53
}
54
​
55
cursor = nextAsURL.Query().Get("cursor")
56
}
57
​
58
for _, chunk := range domainChunks {
59
​
60
for _, domain := range chunk.Data {
61
log.Println(domain.ID, domain.Attributes.Name, domain.Attributes.Claim.Status)
62
}
63
​
64
}
65
​
66
}
Copied!
πŸ§šβ€β™€οΈ Tips: You can extract the following struct tags
1
type OrganizationDomainPageScheme struct {
2
Data []*OrganizationDomainModelScheme `json:"data,omitempty"`
3
Links *LinkPageModelScheme `json:"links,omitempty"`
4
}
5
​
6
type OrganizationDomainModelScheme struct {
7
ID string `json:"id,omitempty"`
8
Type string `json:"type,omitempty"`
9
Attributes struct {
10
Name string `json:"name,omitempty"`
11
Claim struct {
12
Type string `json:"type,omitempty"`
13
Status string `json:"status,omitempty"`
14
} `json:"claim,omitempty"`
15
} `json:"attributes,omitempty"`
16
Links *LinkSelfModelScheme `json:"links,omitempty"`
17
}
Copied!

Get domain by ID

Returns information about a single verified domain 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 (
24
organizationID = "9a1jj823-jac8-123d-jj01-63315k059cb2"
25
domainID = "go-atlassian.io"
26
)
27
​
28
domain, response, err := cloudAdmin.Organization.Domain(context.Background(), organizationID, domainID)
29
if err != nil {
30
if response != nil {
31
log.Println("Response HTTP Response", response.Bytes.String())
32
}
33
log.Fatal(err)
34
}
35
​
36
log.Println("Response HTTP Code", response.Code)
37
log.Println("HTTP Endpoint Used", response.Endpoint)
38
log.Println(domain.Data.Attributes.Name, domain.Data.Attributes.Claim.Status)
39
}
Copied!
πŸ§šβ€β™€οΈ Tips: You can extract the following struct tags
1
type OrganizationDomainScheme struct {
2
Data *OrganizationDomainDataScheme `json:"data"`
3
}
4
​
5
type OrganizationDomainDataScheme struct {
6
ID string `json:"id"`
7
Type string `json:"type"`
8
Attributes struct {
9
Name string `json:"name"`
10
Claim struct {
11
Type string `json:"type"`
12
Status string `json:"status"`
13
} `json:"claim"`
14
} `json:"attributes"`
15
Links struct {
16
Self string `json:"self"`
17
} `json:"links"`
18
}
Copied!

Get an audit log of events

Returns an audit log of events from an organization one page at a time.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/admin"
6
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
7
"log"
8
"net/url"
9
"os"
10
"time"
11
)
12
​
13
func main() {
14
​
15
//ATLASSIAN_ADMIN_TOKEN
16
var apiKey = os.Getenv("ATLASSIAN_ADMIN_TOKEN")
17
​
18
cloudAdmin, err := admin.New(nil)
19
if err != nil {
20
log.Fatal(err)
21
}
22
​
23
cloudAdmin.Auth.SetBearerToken(apiKey)
24
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
25
​
26
var (
27
organizationID = "9a1jj823-jac8-123d-jj01-63315k059cb2"
28
cursor string
29
eventChunks []*models.OrganizationEventPageScheme
30
)
31
​
32
for {
33
​
34
opts := &models.OrganizationEventOptScheme{
35
Q: "",
36
From: time.Now().Add(time.Duration(-24) * time.Hour),
37
To: time.Time{},
38
Action: "",
39
}
40
​
41
events, response, err := cloudAdmin.Organization.Events(context.Background(), organizationID, opts, cursor)
42
if err != nil {
43
if response != nil {
44
log.Println("Response HTTP Response", response.Bytes.String())
45
}
46
log.Fatal(err)
47
}
48
​
49
log.Println("Response HTTP Code", response.Code)
50
log.Println("HTTP Endpoint Used", response.Endpoint)
51
eventChunks = append(eventChunks, events)
52
​
53
if len(events.Links.Next) == 0 {
54
break
55
}
56
​
57
//extract the next cursor pagination
58
nextAsURL, err := url.Parse(events.Links.Next)
59
if err != nil {
60
log.Fatal(err)
61
}
62
​
63
cursor = nextAsURL.Query().Get("cursor")
64
}
65
​
66
for _, chunk := range eventChunks {
67
​
68
for _, event := range chunk.Data {
69
log.Println(event.ID, event.Attributes.Action, event.Attributes.Time)
70
}
71
​
72
}
73
​
74
}
Copied!
πŸ§šβ€β™€οΈ Tips: You can extract the following struct tags
1
type OrganizationEventPageScheme struct {
2
Data []*OrganizationEventModelScheme `json:"data,omitempty"`
3
Links *LinkPageModelScheme `json:"links,omitempty"`
4
Meta struct {
5
Next string `json:"next,omitempty"`
6
PageSize int `json:"page_size,omitempty"`
7
} `json:"meta,omitempty"`
8
}
9
​
10
type OrganizationEventModelScheme struct {
11
ID string `json:"id,omitempty"`
12
Type string `json:"type,omitempty"`
13
Attributes *OrganizationEventModelAttributesScheme `json:"attributes,omitempty"`
14
Links *LinkSelfModelScheme `json:"links,omitempty"`
15
}
16
​
17
type OrganizationEventModelAttributesScheme struct {
18
Time string `json:"time,omitempty"`
19
Action string `json:"action,omitempty"`
20
Actor *OrganizationEventActorModel `json:"actor,omitempty"`
21
Context []*OrganizationEventObjectModel `json:"context,omitempty"`
22
Container []*OrganizationEventObjectModel `json:"container,omitempty"`
23
Location *OrganizationEventLocationModel `json:"location,omitempty"`
24
}
25
​
26
type OrganizationEventActorModel struct {
27
ID string `json:"id,omitempty"`
28
Name string `json:"name,omitempty"`
29
Links *LinkSelfModelScheme `json:"links,omitempty"`
30
}
31
​
32
type OrganizationEventObjectModel struct {
33
ID string `json:"id,omitempty"`
34
Type string `json:"type,omitempty"`
35
Links struct {
36
Self string `json:"self,omitempty"`
37
Alt string `json:"alt,omitempty"`
38
} `json:"links,omitempty"`
39
}
40
​
41
type OrganizationEventLocationModel struct {
42
IP string `json:"ip,omitempty"`
43
Geo string `json:"geo,omitempty"`
44
}
Copied!

Get an event by ID

Returns information about a single event 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 (
24
organizationID = "9a1jj823-jac8-123d-jj01-63315k059cb2"
25
eventID = "002ca68b-50b6-47c7-b985-566944bc89e8"
26
)
27
​
28
event, response, err := cloudAdmin.Organization.Event(context.Background(), organizationID, eventID)
29
if err != nil {
30
if response != nil {
31
log.Println("Response HTTP Response", string(response.BodyAsBytes))
32
}
33
log.Fatal(err)
34
}
35
​
36
log.Println("Response HTTP Code", response.StatusCode)
37
log.Println("HTTP Endpoint Used", response.Endpoint)
38
log.Println(event.Data.ID, event.Data.Attributes.Action, event.Data.Attributes.Time)
39
}
40
​
Copied!

Get list of event actions

Returns information localized event actions
1
package main
2
​
3
import (
4
"context"
5
"fmt"
6
"github.com/ctreminiom/go-atlassian/admin"
7
"github.com/kr/pretty"
8
"log"
9
"os"
10
)
11
​
12
func main() {
13
​
14
//https://support.atlassian.com/organization-administration/docs/manage-an-organization-with-the-admin-apis/
15
var apiKey = os.Getenv("ATLASSIAN_ADMIN_TOKEN")
16
​
17
cloudAdmin, err := admin.New(nil)
18
if err != nil {
19
log.Fatal(err)
20
}
21
​
22
cloudAdmin.Auth.SetBearerToken(apiKey)
23
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
24
​
25
var organizationID = "9a1jj823-jac8-123d-jj01-63315k059cb2"
26
​
27
actions, response, err := cloudAdmin.Organization.Actions(context.Background(), organizationID)
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 _, action := range actions.Data {
39
fmt.Printf("%# v\n", pretty.Formatter(action))
40
}
41
}
42
​
Copied!
πŸ§šβ€β™€οΈ Tips: You can extract the following struct tags
1
type OrganizationEventActionScheme struct {
2
Data []*OrganizationEventActionModelScheme `json:"data,omitempty"`
3
}
4
​
5
type OrganizationEventActionModelScheme struct {
6
ID string `json:"id,omitempty"`
7
Type string `json:"type,omitempty"`
8
Attributes *OrganizationEventActionModelAttributesScheme `json:"attributes,omitempty"`
9
}
10
​
11
type OrganizationEventActionModelAttributesScheme struct {
12
DisplayName string `json:"displayName,omitempty"`
13
GroupDisplayName string `json:"groupDisplayName,omitempty"`
14
}
Copied!