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.
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
GET /rest/servicedeskapi/organization/{organizationId}
Get returns details of an organization. Use this method to get organization details whenever your application component is passed an organization ID but needs to display other organization details.
This method deletes an organization. Note that the organization is deleted regardless of other associations it may have. For example, associations with service desks.
POST /rest/servicedeskapi/servicedesk/{serviceDeskId}/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.
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.
GET /rest/servicedeskapi/organization/{organizationId}/user
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.
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
POST /rest/servicedeskapi/organization/{organizationId}/user