๐Ÿ“”
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).
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/admin"
"log"
"os"
)
โ€‹
func main() {
โ€‹
//https://support.atlassian.com/organization-administration/docs/manage-an-organization-with-the-admin-apis/
var apiKey = os.Getenv("ATLASSIAN_ADMIN_TOKEN")
โ€‹
cloudAdmin, err := admin.New(nil)
if err != nil {
log.Fatal(err)
}
โ€‹
cloudAdmin.Auth.SetBearerToken(apiKey)
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
โ€‹
organizations, response, err := cloudAdmin.Organization.Gets(context.Background(), "")
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
for _, organization := range organizations.Data {
log.Println(organization.ID, organization.Attributes.Name)
}
}
โ€‹
๐Ÿงšโ€โ™€๏ธ Tips: You can extract the following struct tags
type OrganizationPageScheme struct {
Data []*OrganizationModelScheme `json:"data,omitempty"`
Links *OrganizationLinkPageModelScheme `json:"links,omitempty"`
}
โ€‹
type OrganizationLinkPageModelScheme struct {
Self string `json:"self,omitempty"`
Prev string `json:"prev,omitempty"`
Next string `json:"next,omitempty"`
}
โ€‹
type OrganizationModelScheme struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Attributes *OrganizationModelAttribute `json:"attributes,omitempty"`
Relationships *OrganizationModelRelationships `json:"relationships,omitempty"`
Links *OrganizationLinkSelfModelScheme `json:"links,omitempty"`
}
โ€‹
type OrganizationModelAttribute struct {
Name string `json:"name,omitempty"`
}
โ€‹
type OrganizationModelRelationships struct {
Domains *OrganizationModelSchemes `json:"domains,omitempty"`
Users *OrganizationModelSchemes `json:"users,omitempty"`
}
โ€‹
type OrganizationModelSchemes struct {
Links struct {
Related string `json:"related,omitempty"`
} `json:"links,omitempty"`
}
โ€‹
type OrganizationLinkSelfModelScheme struct {
Self string `json:"self,omitempty"`
}

Get an organization by ID

Returns information about a single organization by ID
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/admin"
"log"
"os"
)
โ€‹
func main() {
โ€‹
//ATLASSIAN_ADMIN_TOKEN
var apiKey = os.Getenv("ATLASSIAN_ADMIN_TOKEN")
โ€‹
cloudAdmin, err := admin.New(nil)
if err != nil {
log.Fatal(err)
}
โ€‹
cloudAdmin.Auth.SetBearerToken(apiKey)
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var organizationID = "9a1jj823-jac8-123d-jj01-63315k059cb2"
โ€‹
organization, response, err := cloudAdmin.Organization.Get(context.Background(), organizationID)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", string(response.BodyAsBytes))
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.StatusCode)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(organization.Data.ID)
}
โ€‹
๐Ÿงšโ€โ™€๏ธ Tips: You can extract the following struct tags
type OrganizationScheme struct {
Data *OrganizationModelScheme `json:"data,omitempty"`
}

Get users in an organization

Returns a list of users in an organization.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/admin"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"net/url"
"os"
)
โ€‹
func main() {
โ€‹
//ATLASSIAN_ADMIN_TOKEN
var apiKey = os.Getenv("ATLASSIAN_ADMIN_TOKEN")
โ€‹
cloudAdmin, err := admin.New(nil)
if err != nil {
log.Fatal(err)
}
โ€‹
cloudAdmin.Auth.SetBearerToken(apiKey)
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var (
organizationID = "9a1jj823-jac8-123d-jj01-63315k059cb2"
cursor string
userChunks []*models.OrganizationUserPageScheme
)
โ€‹
for {
โ€‹
users, response, err := cloudAdmin.Organization.Users(context.Background(), organizationID, cursor)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
userChunks = append(userChunks, users)
โ€‹
if len(users.Links.Next) == 0 {
break
}
โ€‹
//extract the next cursor pagination
nextAsURL, err := url.Parse(users.Links.Next)
if err != nil {
log.Fatal(err)
}
โ€‹
cursor = nextAsURL.Query().Get("cursor")
}
โ€‹
for _, chunk := range userChunks {
โ€‹
for _, user := range chunk.Data {
log.Println(user.Email, user.Name)
}
โ€‹
}
โ€‹
}
๐Ÿงšโ€โ™€๏ธ Tips: You can extract the following struct tags
type OrganizationUserPageScheme struct {
Data []*AdminOrganizationUserScheme `json:"data,omitempty"`
Links *LinkPageModelScheme `json:"links,omitempty"`
Meta struct {
Total int `json:"total,omitempty"`
} `json:"meta,omitempty"`
}
โ€‹
ttype AdminOrganizationUserScheme struct {
AccountID string `json:"account_id,omitempty"`
AccountType string `json:"account_type,omitempty"`
AccountStatus string `json:"account_status,omitempty"`
Name string `json:"name,omitempty"`
Picture string `json:"picture,omitempty"`
Email string `json:"email,omitempty"`
AccessBillable bool `json:"access_billable,omitempty"`
LastActive string `json:"last_active,omitempty"`
ProductAccess []*OrganizationUserProductScheme `json:"product_access,omitempty"`
Links *LinkSelfModelScheme `json:"links,omitempty"`
}
โ€‹
type OrganizationUserProductScheme struct {
Key string `json:"key,omitempty"`
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
LastActive string `json:"last_active,omitempty"`
}

Get domains in an organization

Returns a list of domains in an organization one page at a time.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/admin"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"net/url"
"os"
)
โ€‹
func main() {
โ€‹
//ATLASSIAN_ADMIN_TOKEN
var apiKey = os.Getenv("ATLASSIAN_ADMIN_TOKEN")
โ€‹
cloudAdmin, err := admin.New(nil)
if err != nil {
log.Fatal(err)
}
โ€‹
cloudAdmin.Auth.SetBearerToken(apiKey)
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var (
organizationID = "9a1jj823-jac8-123d-jj01-63315k059cb2"
cursor string
domainChunks []*models.OrganizationDomainPageScheme
)
โ€‹
for {
โ€‹
domains, response, err := cloudAdmin.Organization.Domains(context.Background(), organizationID, cursor)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
domainChunks = append(domainChunks, domains)
โ€‹
if len(domains.Links.Next) == 0 {
break
}
โ€‹
//extract the next cursor pagination
nextAsURL, err := url.Parse(domains.Links.Next)
if err != nil {
log.Fatal(err)
}
โ€‹
cursor = nextAsURL.Query().Get("cursor")
}
โ€‹
for _, chunk := range domainChunks {
โ€‹
for _, domain := range chunk.Data {
log.Println(domain.ID, domain.Attributes.Name, domain.Attributes.Claim.Status)
}
โ€‹
}
โ€‹
}
๐Ÿงšโ€โ™€๏ธ Tips: You can extract the following struct tags
type OrganizationDomainPageScheme struct {
Data []*OrganizationDomainModelScheme `json:"data,omitempty"`
Links *LinkPageModelScheme `json:"links,omitempty"`
}
โ€‹
type OrganizationDomainModelScheme struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Attributes struct {
Name string `json:"name,omitempty"`
Claim struct {
Type string `json:"type,omitempty"`
Status string `json:"status,omitempty"`
} `json:"claim,omitempty"`
} `json:"attributes,omitempty"`
Links *LinkSelfModelScheme `json:"links,omitempty"`
}

Get domain by ID

Returns information about a single verified domain by ID.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/admin"
"log"
"os"
)
โ€‹
func main() {
โ€‹
//ATLASSIAN_ADMIN_TOKEN
var apiKey = os.Getenv("ATLASSIAN_ADMIN_TOKEN")
โ€‹
cloudAdmin, err := admin.New(nil)
if err != nil {
log.Fatal(err)
}
โ€‹
cloudAdmin.Auth.SetBearerToken(apiKey)
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var (
organizationID = "9a1jj823-jac8-123d-jj01-63315k059cb2"
domainID = "go-atlassian.io"
)
โ€‹
domain, response, err := cloudAdmin.Organization.Domain(context.Background(), organizationID, domainID)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(domain.Data.Attributes.Name, domain.Data.Attributes.Claim.Status)
}
๐Ÿงšโ€โ™€๏ธ Tips: You can extract the following struct tags
type OrganizationDomainScheme struct {
Data *OrganizationDomainDataScheme `json:"data"`
}
โ€‹
type OrganizationDomainDataScheme struct {
ID string `json:"id"`
Type string `json:"type"`
Attributes struct {
Name string `json:"name"`
Claim struct {
Type string `json:"type"`
Status string `json:"status"`
} `json:"claim"`
} `json:"attributes"`
Links struct {
Self string `json:"self"`
} `json:"links"`
}

Get an audit log of events

Returns an audit log of events from an organization one page at a time.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/admin"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"net/url"
"os"
"time"
)
โ€‹
func main() {
โ€‹
//ATLASSIAN_ADMIN_TOKEN
var apiKey = os.Getenv("ATLASSIAN_ADMIN_TOKEN")
โ€‹
cloudAdmin, err := admin.New(nil)
if err != nil {
log.Fatal(err)
}
โ€‹
cloudAdmin.Auth.SetBearerToken(apiKey)
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var (
organizationID = "9a1jj823-jac8-123d-jj01-63315k059cb2"
cursor string
eventChunks []*models.OrganizationEventPageScheme
)
โ€‹
for {
โ€‹
opts := &models.OrganizationEventOptScheme{
Q: "",
From: time.Now().Add(time.Duration(-24) * time.Hour),
To: time.Time{},
Action: "",
}
โ€‹
events, response, err := cloudAdmin.Organization.Events(context.Background(), organizationID, opts, cursor)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
eventChunks = append(eventChunks, events)
โ€‹
if len(events.Links.Next) == 0 {
break
}
โ€‹
//extract the next cursor pagination
nextAsURL, err := url.Parse(events.Links.Next)
if err != nil {
log.Fatal(err)
}
โ€‹
cursor = nextAsURL.Query().Get("cursor")
}
โ€‹
for _, chunk := range eventChunks {
โ€‹
for _, event := range chunk.Data {
log.Println(event.ID, event.Attributes.Action, event.Attributes.Time)
}
โ€‹
}
โ€‹
}
๐Ÿงšโ€โ™€๏ธ Tips: You can extract the following struct tags
type OrganizationEventPageScheme struct {
Data []*OrganizationEventModelScheme `json:"data,omitempty"`
Links *LinkPageModelScheme `json:"links,omitempty"`
Meta struct {
Next string `json:"next,omitempty"`
PageSize int `json:"page_size,omitempty"`
} `json:"meta,omitempty"`
}
โ€‹
type OrganizationEventModelScheme struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Attributes *OrganizationEventModelAttributesScheme `json:"attributes,omitempty"`
Links *LinkSelfModelScheme `json:"links,omitempty"`
}
โ€‹
type OrganizationEventModelAttributesScheme struct {
Time string `json:"time,omitempty"`
Action string `json:"action,omitempty"`
Actor *OrganizationEventActorModel `json:"actor,omitempty"`
Context []*OrganizationEventObjectModel `json:"context,omitempty"`
Container []*OrganizationEventObjectModel `json:"container,omitempty"`
Location *OrganizationEventLocationModel `json:"location,omitempty"`
}
โ€‹
type OrganizationEventActorModel struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Links *LinkSelfModelScheme `json:"links,omitempty"`
}
โ€‹
type OrganizationEventObjectModel struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Links struct {
Self string `json:"self,omitempty"`
Alt string `json:"alt,omitempty"`
} `json:"links,omitempty"`
}
โ€‹
type OrganizationEventLocationModel struct {
IP string `json:"ip,omitempty"`
Geo string `json:"geo,omitempty"`
}

Get an event by ID

Returns information about a single event by ID.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/admin"
"log"
"os"
)
โ€‹
func main() {
โ€‹
//ATLASSIAN_ADMIN_TOKEN
var apiKey = os.Getenv("ATLASSIAN_ADMIN_TOKEN")
โ€‹
cloudAdmin, err := admin.New(nil)
if err != nil {
log.Fatal(err)
}
โ€‹
cloudAdmin.Auth.SetBearerToken(apiKey)
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var (
organizationID = "9a1jj823-jac8-123d-jj01-63315k059cb2"
eventID = "002ca68b-50b6-47c7-b985-566944bc89e8"
)
โ€‹
event, response, err := cloudAdmin.Organization.Event(context.Background(), organizationID, eventID)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", string(response.BodyAsBytes))
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.StatusCode)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(event.Data.ID, event.Data.Attributes.Action, event.Data.Attributes.Time)
}
โ€‹

Get list of event actions

Returns information localized event actions
package main
โ€‹
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/admin"
"github.com/kr/pretty"
"log"
"os"
)
โ€‹
func main() {
โ€‹
//https://support.atlassian.com/organization-administration/docs/manage-an-organization-with-the-admin-apis/
var apiKey = os.Getenv("ATLASSIAN_ADMIN_TOKEN")
โ€‹
cloudAdmin, err := admin.New(nil)
if err != nil {
log.Fatal(err)
}
โ€‹
cloudAdmin.Auth.SetBearerToken(apiKey)
cloudAdmin.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var organizationID = "9a1jj823-jac8-123d-jj01-63315k059cb2"
โ€‹
actions, response, err := cloudAdmin.Organization.Actions(context.Background(), organizationID)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
for _, action := range actions.Data {
fmt.Printf("%# v\n", pretty.Formatter(action))
}
}
โ€‹
๐Ÿงšโ€โ™€๏ธ Tips: You can extract the following struct tags
type OrganizationEventActionScheme struct {
Data []*OrganizationEventActionModelScheme `json:"data,omitempty"`
}
โ€‹
type OrganizationEventActionModelScheme struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Attributes *OrganizationEventActionModelAttributesScheme `json:"attributes,omitempty"`
}
โ€‹
type OrganizationEventActionModelAttributesScheme struct {
DisplayName string `json:"displayName,omitempty"`
GroupDisplayName string `json:"groupDisplayName,omitempty"`
}
Export as PDF
Copy link
On this page
Get organizations
Get an organization by ID
Get users in an organization
Get domains in an organization
Get domain by ID
Get an audit log of events
Get an event by ID
Get list of event actions