Ask or search…
⌃K
🤓

Users

Get user

GET /rest/api/{2-3}/user
Returns a user.
package main
​
import (
"context"
_ "github.com/ctreminiom/go-atlassian/jira/v3"
"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)
​
}

Create user

POST /rest/api/{2-3}/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/v3"
"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

DELETE /rest/api/{2-3}/user
Deletes a user.
package main
​
import (
"context"
_ "github.com/ctreminiom/go-atlassian/jira/v3"
"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

GET /rest/api/{2-3}/user/bulk
Returns a paginated list of the users specified by one or more account IDs.
package main
​
import (
"context"
_ "github.com/ctreminiom/go-atlassian/jira/v3"
"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

GET /rest/api/{2-3}/user/groups
Returns the groups to which a user belongs.
package main
​
import (
"context"
_ "github.com/ctreminiom/go-atlassian/jira/v3"
"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

GET /rest/api/{2-3}/users/search
Returns a list of all (active and inactive) users.
package main
​
import (
"context"
_ "github.com/ctreminiom/go-atlassian/jira/v3"
"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)
}
}