๐Ÿ›‚
Organization

Get organizations

This method returns a list of organizations in the Jira Service Management instance. Use this method when you want to present a list of organizations or want to locate an organization by name.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/sm"
"log"
"os"
)
โ€‹
func main() {
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := sm.New(nil, host)
if err != nil {
return
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var (
accountID = ""
start = 0
limit = 50
)
โ€‹
organizations, response, err := atlassian.Organization.Gets(context.Background(), accountID, start, limit)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("HTTP Endpoint Used", response.Endpoint)
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
for _, organization := range organizations.Values {
log.Println(organization)
}
}
๐Ÿงšโ€โ™€๏ธ Tips: You can extract the following struct tags
type OrganizationPageScheme struct {
Size int `json:"size,omitempty"`
Start int `json:"start,omitempty"`
Limit int `json:"limit,omitempty"`
IsLastPage bool `json:"isLastPage,omitempty"`
Values []*OrganizationScheme `json:"values,omitempty"`
Expands []string `json:"_expands,omitempty"`
Links *OrganizationPageLinkScheme `json:"_links,omitempty"`
}
โ€‹
type OrganizationPageLinkScheme struct {
Self string `json:"self,omitempty"`
Base string `json:"base,omitempty"`
Context string `json:"context,omitempty"`
Next string `json:"next,omitempty"`
Prev string `json:"prev,omitempty"`
}

Create organization

This method creates an organization by passing the name of the organization.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/sm"
"log"
"os"
)
โ€‹
func main() {
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := sm.New(nil, host)
if err != nil {
return
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var organizationName = "Organization Name"
โ€‹
newOrganization, response, err := atlassian.Organization.Create(context.Background(), organizationName)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("HTTP Endpoint Used", response.Endpoint)
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("The organization has been created: %v", newOrganization.ID)
}

Get organization

package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/sm"
"log"
"os"
)
โ€‹
func main() {
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := sm.New(nil, host)
if err != nil {
return
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
โ€‹
organization, response, err := atlassian.Organization.Get(context.Background(), 2)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("HTTP Endpoint Used", response.Endpoint)
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(organization.ID, organization.Name, organization.Links.Self)
}

Delete Organization

Get organizations

This method returns a list of all organizations associated with a service desk.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/sm"
"log"
"os"
)
โ€‹
func main() {
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := sm.New(nil, host)
if err != nil {
return
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var (
accountID = ""
projectID = 1
start = 0
limit = 50
)
โ€‹
organizations, response, err := atlassian.Organization.Project(
context.Background(),
accountID,
projectID,
start,
limit,
)
โ€‹
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("HTTP Endpoint Used", response.Endpoint)
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
for _, organization := range organizations.Values {
log.Printf(organization.ID)
}
โ€‹
}

Associate organization

This method adds an organization to a service desk. If the organization ID is already associated with the service desk, no change is made and the resource returns a 204 success code.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/sm"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := sm.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
var (
projectID = 1
organizationID = 2
)
response, err := atlassian.Organization.Associate(context.Background(), projectID, organizationID)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("HTTP Endpoint Used", response.Endpoint)
}
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}

Detach organization

This method removes an organization from a service desk. If the organization ID does not match an organization associated with the service desk, no change is made and the resource returns a 204 success code.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/sm"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := sm.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
var (
projectID = 1
organizationID = 2
)
response, err := atlassian.Organization.Detach(context.Background(), projectID, organizationID)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("HTTP Endpoint Used", response.Endpoint)
}
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}

Get Project Organizations

Get users in organization

This method returns all the users associated with an organization. Use this method where you want to provide a list of users for an organization or determine if a user is associated with an organization.w
package main
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/sm"
"log"
"os"
)
โ€‹
func main() {
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := sm.New(nil, host)
if err != nil {
return
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var (
organizationID = 2
start = 0
limit = 50
)
โ€‹
users, response, err := atlassian.Organization.Users(context.Background(), organizationID, start, limit)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("HTTP Endpoint Used", response.Endpoint)
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
for _, user := range users.Values {
log.Printf(user.DisplayName, user.EmailAddress)
}
โ€‹
}

Add users to organization

This method adds users to an organization.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/sm"
"log"
"os"
)
โ€‹
func main() {
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := sm.New(nil, host)
if err != nil {
return
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var (
accountIDs = []string{"5b86be50b8e3cb5895860d6d"}
organizationID = 2
)
โ€‹
response, err := atlassian.Organization.Add(context.Background(), organizationID, accountIDs)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("HTTP Endpoint Used", response.Endpoint)
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}

Remove users from organization

This method removes users from an organization.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/sm"
"log"
"os"
)
โ€‹
func main() {
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := sm.New(nil, host)
if err != nil {
return
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
โ€‹
var (
accountIDs = []string{"5b86be50b8e3cb5895860d6d"}
organizationID = 2
)
โ€‹
response, err := atlassian.Organization.Remove(context.Background(), organizationID, accountIDs)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("HTTP Endpoint Used", response.Endpoint)
}
log.Fatal(err)
}
โ€‹
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
}
Export as PDF
Copy link
On this page
Get organizations
Create organization
Get organization
Delete Organization
Get organizations
Associate organization
Detach organization
Get Project Organizations
Get users in organization
Add users to organization
Remove users from organization