๐Ÿค“
Users
This resource represent users.

Get user

Returns a user.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/v2"
"log"
"os"
)
โ€‹
func main() {
โ€‹
/*
----------- Set an environment variable in git bash -----------
export HOST="https://ctreminiom.atlassian.net/"
export MAIL="MAIL_ADDRESS"
export TOKEN="TOKEN_API"
โ€‹
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
*/
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
โ€‹
var (
accountID = "5b86be50b8e3cb5895860d6d"
expands = []string{"groups", "applicationRoles"}
)
โ€‹
user, response, err := atlassian.User.Get(context.Background(), accountID, expands)
if err != nil {
log.Fatal(err)
}
โ€‹
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(user)
โ€‹
}
๐Ÿงšโ€โ™€๏ธ Tips: You can extract the following struct tags
type UserScheme struct {
Self string `json:"self,omitempty"`
Key string `json:"key,omitempty"`
AccountID string `json:"accountId,omitempty"`
AccountType string `json:"accountType,omitempty"`
Name string `json:"name,omitempty"`
EmailAddress string `json:"emailAddress,omitempty"`
AvatarUrls *AvatarURLScheme `json:"avatarUrls,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Active bool `json:"active,omitempty"`
TimeZone string `json:"timeZone,omitempty"`
Locale string `json:"locale,omitempty"`
Groups *UserGroupsScheme `json:"groups,omitempty"`
ApplicationRoles *UserApplicationRolesScheme `json:"applicationRoles,omitempty"`
Expand string `json:"expand,omitempty"`
}
โ€‹
type UserApplicationRolesScheme struct {
Size int `json:"size,omitempty"`
Items []*UserApplicationRoleItemsScheme `json:"items,omitempty"`
MaxResults int `json:"max-results,omitempty"`
}
โ€‹
type UserApplicationRoleItemsScheme struct {
Key string `json:"key,omitempty"`
Groups []string `json:"groups,omitempty"`
Name string `json:"name,omitempty"`
DefaultGroups []string `json:"defaultGroups,omitempty"`
SelectedByDefault bool `json:"selectedByDefault,omitempty"`
Defined bool `json:"defined,omitempty"`
NumberOfSeats int `json:"numberOfSeats,omitempty"`
RemainingSeats int `json:"remainingSeats,omitempty"`
UserCount int `json:"userCount,omitempty"`
UserCountDescription string `json:"userCountDescription,omitempty"`
HasUnlimitedSeats bool `json:"hasUnlimitedSeats,omitempty"`
Platform bool `json:"platform,omitempty"`
}
โ€‹
type UserGroupsScheme struct {
Size int `json:"size,omitempty"`
Items []*UserGroupScheme `json:"items,omitempty"`
MaxResults int `json:"max-results,omitempty"`
}

Create user

Creates a user. This resource is retained for legacy compatibility. As soon as a more suitable alternative is available this resource will be deprecated.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
โ€‹
func main() {
โ€‹
/*
----------- Set an environment variable in git bash -----------
export HOST="https://ctreminiom.atlassian.net/"
export MAIL="MAIL_ADDRESS"
export TOKEN="TOKEN_API"
โ€‹
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
*/
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
โ€‹
payload := &models.UserPayloadScheme{
EmailAddress: "[email protected]",
DisplayName: "Example DisplayName",
Notification: false,
}
โ€‹
newUser, response, err := atlassian.User.Create(context.Background(), payload)
if err != nil {
log.Fatal(err)
}
โ€‹
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println("The new user has been created", newUser.AccountID)
}

Delete user

Deletes a user.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/v2"
"log"
"os"
)
โ€‹
func main() {
โ€‹
/*
----------- Set an environment variable in git bash -----------
export HOST="https://ctreminiom.atlassian.net/"
export MAIL="MAIL_ADDRESS"
export TOKEN="TOKEN_API"
โ€‹
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
*/
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
โ€‹
response, err := atlassian.User.Delete(context.Background(), "607b98df2ad11c0072664322")
if err != nil {
log.Fatal(err)
}
โ€‹
log.Println("HTTP Endpoint Used", response.Endpoint)
}

Bulk get users

Returns a paginated list of the users specified by one or more account IDs.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/v2"
"log"
"os"
)
โ€‹
func main() {
โ€‹
/*
----------- Set an environment variable in git bash -----------
export HOST="https://ctreminiom.atlassian.net/"
export MAIL="MAIL_ADDRESS"
export TOKEN="TOKEN_API"
โ€‹
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
*/
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
โ€‹
var (
accountIDs = []string{"5b86be50b8e3cb5895860d6d"}
startAt = 0
maxResults = 50
)
โ€‹
users, response, err := atlassian.User.Find(context.Background(), accountIDs, startAt, maxResults)
if err != nil {
log.Fatal(err)
}
โ€‹
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
for _, user := range users.Values {
log.Println(user.DisplayName)
}
}

Get user groups

Returns the groups to which a user belongs.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/v2"
"log"
"os"
)
โ€‹
func main() {
โ€‹
/*
----------- Set an environment variable in git bash -----------
export HOST="https://ctreminiom.atlassian.net/"
export MAIL="MAIL_ADDRESS"
export TOKEN="TOKEN_API"
โ€‹
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
*/
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
โ€‹
var accountID = "5b86be50b8e3cb5895860d6d"
groups, response, err := atlassian.User.Groups(context.Background(), accountID)
if err != nil {
log.Fatal(err)
}
โ€‹
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
for _, group := range groups {
log.Println(group)
}
โ€‹
}
โ€‹

Get all users

Returns a list of all (active and inactive) users.
package main
โ€‹
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/v2"
"log"
"os"
)
โ€‹
func main() {
โ€‹
/*
----------- Set an environment variable in git bash -----------
export HOST="https://ctreminiom.atlassian.net/"
export MAIL="MAIL_ADDRESS"
export TOKEN="TOKEN_API"
โ€‹
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
*/
โ€‹
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
โ€‹
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
โ€‹
atlassian.Auth.SetBasicAuth(mail, token)
โ€‹
var (
startAt = 0
maxResults = 50
)
โ€‹
users, response, err := atlassian.User.Gets(context.Background(), startAt, maxResults)
if err != nil {
log.Fatal(err)
}
โ€‹
log.Println("HTTP Endpoint Used", response.Endpoint)
โ€‹
for _, user := range users {
log.Println(user)
}
}
Export as PDF
Copy link
On this page
Get user
Create user
Delete user
Bulk get users
Get user groups
Get all users