Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
In this article, I would be showing you how to upload an attachment in a Confluence content using the "go-atlassian" library.
Create a new directory for your project.
Open a terminal and navigate to the project directory.
Initialize a new Go module using the following command:
go mod init <module-name>
In the terminal, run the following command to install the "go-atlassian" library:
go get -v github.com/ctreminiom/go-atlassian
Create a new Go file (e.g., main.go
) in your project directory.
Open the file and import the required packages:
package main
import (
"github.com/ctreminiom/go-atlassian/confluence"
"log"
"os"
)
In the main
function, create a new Confluence client and authenticate using your Atlassian URL, username, and API token:
func main() {
atlassianHost := "https://<_jira_instance_>.atlassian.net"
mailAddress := "<your_mail>"
apiToken := "<your_api_token>"
client, err := confluence.New(nil, atlassianHost )
if err != nil {
log.Fatal(err)
}
client.Auth.SetBasicAuth(mailAddress, apiToken)
}
Define the necessary variables for the page ID, file path, and file name:
pageID := "76513281"
filePath := "confluence/mocks/mock.png"
fileName := "mock-00.png"
Open the file using the provided file path:
absolutePath, err := filepath.Abs(filePath)
if err != nil {
log.Fatal(err)
}
log.Println("Using the path", absolutePath)
reader, err := os.Open(absolutePath)
if err != nil {
log.Fatal(err)
}
defer reader.Close()
Upload the attachment using the Content.Attachment.Create()
method and provide the page ID, file name, and file content:
attachmentsPage, response, err := client.Content.Attachment.Create(context.Background(), pageID, "current", fileName, reader)
if err != nil {
if response != nil {
if response.Code == http.StatusBadRequest {
log.Println(response.Code)
}
}
log.Println(response.Endpoint)
log.Fatal(err)
}
log.Println("Endpoint:", response.Endpoint)
log.Println("Status Code:", response.Code)
for _, attachment := range attachmentsPage.Results {
log.Println(attachment.ID, attachment.Title)
}
Save the main.go
file.
In the terminal, navigate to your project directory.
Execute the following command to run the program:
go run main.go
This will upload the specified file as an attachment to the Confluence page with the provided page ID.
GET /rest/api/{2-3}/myself
Returns details for the current user.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
currentUser, response, err := atlassian.MySelf.Details(context.Background(), nil)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(currentUser.DisplayName, currentUser.Active, currentUser.AccountID)
}
In this article, I would be showing you how to create a Jira issue using the "go-atlassian" library.
Create a new directory for your project.
Open a terminal and navigate to the project directory.
Initialize a new Go module using the following command:
go mod init <module-name>
In the terminal, run the following command to install the "go-atlassian" library:
go get -v github.com/ctreminiom/go-atlassian
Create a new Go file (e.g., main.go
) in your project directory.
Open the file and import the required packages:
package main
import (
"fmt"
"log"
"os"
jira "github.com/ctreminiom/go-atlassian/jira/v2"
)
You can use the V2 and V3 Jira endpoint versions.
In the main
function, create a new Jira client and authenticate using your Jira URL, username, and API token:
func main() {
jiraHost := "https://<_jira_instance_>.atlassian.net"
mailAddress := "<your_mail>"
apiToken := "<your_api_token>"
client, err := jira.New(nil, jiraHost)
if err != nil {
log.Fatal(err)
}
client.Auth.SetBasicAuth(mailAddress, apiToken)
}
OPTIONAL, you can define custom-fields values you want to set on the issue creation. This library supports the following custom-fields types:
var customFields = models.CustomFields{}
err = customFields.Groups("customfield_10052", []string{"jira-administrators", "jira-administrators-system"})
if err != nil {
log.Fatal(err)
}
err = customFields.Number("customfield_10043", 1000.3232)
if err != nil {
log.Fatal(err)
}
Create a new issue using the Create
method and set the custom fields:
payload := &models.IssueSchemeV2{
Fields: &models.IssueFieldsSchemeV2{
Summary: "New summary test",
Project: &models.ProjectScheme{ID: "10000"},
IssueType: &models.IssueTypeScheme{Name: "Story"},
},
}
newIssue, _, err := client.Issue.Create(context.Background(), payload, &customFields)
if err != nil {
log.Fatal(err)
}
Save the main.go
file.
In the terminal, navigate to your project directory.
Execute the following command to run the program:
This will create a new issue in Jira with the specified custom field values. Please note that you may need to modify the code according to your specific Jira configuration and custom field types.
The go-atlassian jira
module provides a set of functions and types for interacting with the Jira REST API. It is designed to make it easy for developers to build powerful integrations and automations that leverage the capabilities of the Jira platform.
The module is available in two versions: v2
and v3
. These versions correspond to different versions of the Jira REST API, with v2
supporting Jira versions 6.4 to 7.2, and v3
supporting Jira versions 7.3 and later.
The Atlassian Document Format (ADF) is a JSON-based format used by Atlassian products, including Jira, to represent rich content such as text, tables, and lists. The jira
module in go-atlassian provides support for working with ADF content in both the v3
package.
In v3
, the IssueService
and related services like CommentService
provide functions that allow you to interact with ADF content. For example, the CreateIssue
function in v3
includes a parameter for Fields
, which is a struct that includes fields for specifying various attributes of the new issue, including the issue summary, description, and any custom fields. The Fields
struct includes a field for Description
, which can be set to a struct representing ADF content.
To search issues using a JQL query, use the Issue.Search service function.
The go-atlassian agile
module provides a set of functions and types for interacting with the Jira Agile REST API. It is designed to allows developers to interact with and automate various aspects of agile project management within Jira, such as boards, sprints, and issues.
Here's a brief introduction to some key concepts in Jira Agile Rest API:
Boards: A board in Jira represents a visual representation of a project, typically in the form of a Kanban board or a Scrum board. It helps teams track and manage their work. The API provides endpoints to create, retrieve, update, and delete boards, as well as to manage the configuration and settings associated with them.
Sprints: Sprints are time-boxed iterations in agile development, typically used in Scrum methodology. They represent a fixed duration during which a team works on a set of prioritized issues. The API allows you to create, retrieve, update, and delete sprints, as well as manage the issues associated with them.
Issues: Issues in Jira represent tasks, bugs, user stories, or any other unit of work that needs to be tracked. The API provides endpoints to create, retrieve, update, and delete issues. You can also perform operations such as assigning issues to users, transitioning between workflow statuses, adding comments, and more.
Agile Boards API: This API allows you to manage the boards in Jira, including retrieving information about boards, creating new boards, updating board settings, and managing board filters.
Agile Sprints API: With the Agile Sprints API, you can interact with sprints, including creating new sprints, retrieving sprint details, updating sprint properties, and managing the issues associated with sprints.
Agile Issues API: This API allows you to perform operations on issues within the context of agile boards and sprints. You can retrieve issues assigned to a board or sprint, create new issues, update issue details, transition issues between workflow statuses, and more.
In this article, I would be showing you how to extract the boards associated with a Jira project using go-atlassian
Create a new directory for your project and navigate to it in your terminal or command prompt. Initialize a new Go module using the following command:
go mod init your-module-name
To use the "go-atlassian" library, you need to install it as a dependency in your project. Run the following command:
go get github.com/ctreminiom/go-atlassian
Create a new Go file, e.g., main.go
, and import the necessary packages:
package main
import (
"fmt"
"log"
jira "github.com/ctreminiom/go-atlassian/agile"
)
Initialize the Jira Agile API client with your Jira base URL and API token:
func main() {
jiraClient, err := jira.New(nil, "https://your-jira-instance.atlassian.net")
if err != nil {
log.Fatal(err)
}
// Set API token for authentication
jiraClient.Auth.SetBasicAuth(mail, token)
}
In this step, you're going to use the Jira Agile API, more specifically, the Board service, Gets() method. This methods supports multiple query parameters, but in this example, we're going to use the ProjectKeyOrID
param to filter the board linked to a Jira project.
The following example iterates the Board.Gets() method and appends the boards into a slice.
options := &models.GetBoardsOptions{
ProjectKeyOrID: "KP",
}
var boards []*models.BoardScheme
var startAt int
for {
fmt.Println("Pagination #", startAt)
page, response, err := instance.Board.Gets(context.Background(), options, startAt, 50)
if err != nil {
if response != nil {
log.Fatal(response.Bytes.String())
}
log.Fatal(err)
}
boards = append(boards, page.Values...)
if page.IsLast {
break
}
startAt = +50
}
Use it to obtain JQL search auto-complete data and suggestions for use in programmatic construction of queries or custom query builders. It also provides operations to:
convert one or more JQL queries with user identifiers (username or user key) to equivalent JQL queries with account IDs.
convert readable details in one or more JQL queries to IDs where a user doesn't have permission to view the entity whose details are readable.
POST /rest/api/{2-3}/jql/parse
Parses and validates JQL queries. The validation is performed in context of the current user.
package main
import (
"context"
"fmt"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
queries, response, err := jira.JQL.Parse(context.Background(), "", []string{"project = KP"})
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
for _, query := range queries.Queries {
fmt.Println(query)
}
}
This resource represents available labels. Use it to get available labels for the global label field.
GET /rest/api/{2-3}/label
Returns a paginated list of labels.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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)
labels, response, err := atlassian.Issue.Label.Gets(context.Background(), 0, 50)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, label := range labels.Values {
log.Println(label)
}
}
commentBody := jira.CommentNodeScheme{}
commentBody.Version = 1
commentBody.Type = "doc"
//Append Header
commentBody.AppendNode(&jira.CommentNodeScheme{
Type: "heading",
Attrs: map[string]interface{}{"level": 1},
Content: []*jira.CommentNodeScheme{
{
Type: "text",
Text: "Header 1",
},
},
})
var (
jql = "order by created DESC"
fields = []string{"status"}
expand = []string{"changelog", "renderedFields", "names", "schema", "transitions", "operations", "editmeta"}
)
issues, response, err := atlassian.Issue.Search.Post(context.Background(), jql, fields, expand, 0, 50, "")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(issues.Total)
body
in comments, including where comments are used in issue, issue link, and transition resources.
comment
in worklogs
description
and environment
fields in issues.
ppackage 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 (
email = "[email protected]"
displayName = "Example Customer 1"
)
newCustomer, response, err := atlassian.Customer.Create(context.Background(), email, displayName)
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("The new customer has been created!!")
log.Println("-------------------------")
log.Println(newCustomer.Name)
log.Println(newCustomer.DisplayName)
log.Println(newCustomer.AccountID)
log.Println(newCustomer.EmailAddress)
log.Println(newCustomer.Links)
log.Println(newCustomer)
log.Println("-------------------------")
}
go-atlassian is a Go library that provides a simple and convenient way to interact with various Atlassian products' REST APIs. Atlassian is a leading provider of software and tools for software development, project management, and collaboration. Some of the products that go-atlassian supports include Jira, Confluence, Jira Service Management, and more.
The go-atlassian library is designed to simplify the process of building Go applications that interact with Atlassian products. It provides a set of functions and data structures that can be used to easily send HTTP requests to the Atlassian APIs, parse the responses, and work with the data returned.
Easy-to-use functions and data structures that abstract away much of the complexity of working with the APIs.
Comprehensive support for various Atlassian products' APIs.
Support for common operations like creating, updating, and deleting entities in Atlassian products.
Active development and maintenance by the community, with regular updates and bug fixes.
Comprehensive documentation and examples to help developers get started with using the library.
If you do not have Go installed yet, you can find installation instructions here. Please note that the package requires Go version 1.20 or later for module support.
To pull the most recent version of go-atlassian, use go get
.
go get github.com/ctreminiom/go-atlassian/v2
Then import the package into your project as you normally would. You can import the following packages:
Jira v2
github.com/ctreminiom/go-atlassian/v2/jira/v2
Jira v3
github.com/ctreminiom/go-atlassian/v2/jira/v3
Jira Software Agile
github.com/ctreminiom/go-atlassian/v2/jira/agile
Jira Service Management
github.com/ctreminiom/go-atlassian/v2/jira/sm
Jira Assets
github.com/ctreminiom/go-atlassian/v2/assets
Confluence
github.com/ctreminiom/go-atlassian/v2/confluence
Confluence v2
github.com/ctreminiom/go-atlassian/v2/confluence/v2
Admin Cloud
github.com/ctreminiom/go-atlassian/v2/admin
Bitbucket Cloud (In Progress)
github.com/ctreminiom/go-atlassian/v2/bitbucket
Before using the go-atlassian package, you need to have an Atlassian API key. If you do not have a key yet, you can sign up here.
Create a client with your instance host and access token to start communicating with the Atlassian API's. In this example, we're going to instance a new Confluence Cloud client.
instance, err := confluence.New(nil, "INSTANCE_HOST")
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth("YOUR_CLIENT_MAIL", "YOUR_APP_ACCESS_TOKEN")
If you need to use a preconfigured HTTP client, simply pass its address to the New
function.
transport := http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
// Modify the time to wait for a connection to establish
Timeout: 1 * time.Second,
KeepAlive: 30 * time.Second,
}).Dial,
TLSHandshakeTimeout: 10 * time.Second,
}
client := http.Client{
Transport: &transport,
Timeout: 4 * time.Second,
}
instance, err := confluence.New(&client, "INSTANCE_HOST")
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth("YOUR_CLIENT_MAIL", "YOUR_APP_ACCESS_TOKEN")
For detailed examples and usage of the go-atlassian library, please refer to our Cookbook. This section provides step-by-step guides and code samples for common tasks and scenarios.
The library uses the services interfaces to provide a modular and flexible way to interact with Atlassian products' REST APIs. It defines a set of services interfaces that define the functionality of each API, and then provides implementations of those interfaces that can be used to interact with the APIs.
// BoardConnector represents the Jira boards.
// Use it to search, get, create, delete, and change boards.
type BoardConnector interface {
Get(ctx context.Context, boardID int) (*model.BoardScheme, *model.ResponseScheme, error)
Create(ctx context.Context, payload *model.BoardPayloadScheme) (*model.BoardScheme, *model.ResponseScheme, error)
Filter(ctx context.Context, filterID, startAt, maxResults int) (*model.BoardPageScheme, *model.ResponseScheme, error)
Backlog(ctx context.Context, boardID int, opts *model.IssueOptionScheme, startAt, maxResults int) (*model.BoardIssuePageScheme, *model.ResponseScheme, error)
Configuration(ctx context.Context, boardID int) (*model.BoardConfigurationScheme, *model.ResponseScheme, error)
Epics(ctx context.Context, boardID, startAt, maxResults int, done bool) (*model.BoardEpicPageScheme, *model.ResponseScheme, error)
IssuesWithoutEpic(ctx context.Context, boardID int, opts *model.IssueOptionScheme, startAt, maxResults int) (
*model.BoardIssuePageScheme, *model.ResponseScheme, error)
IssuesByEpic(ctx context.Context, boardID, epicID int, opts *model.IssueOptionScheme, startAt, maxResults int) (
*model.BoardIssuePageScheme, *model.ResponseScheme, error)
Issues(ctx context.Context, boardID int, opts *model.IssueOptionScheme, startAt, maxResults int) (*model.BoardIssuePageScheme,
*model.ResponseScheme, error)
Move(ctx context.Context, boardID int, payload *model.BoardMovementPayloadScheme) (*model.ResponseScheme, error)
Projects(ctx context.Context, boardID, startAt, maxResults int) (*model.BoardProjectPageScheme, *model.ResponseScheme, error)
Sprints(ctx context.Context, boardID, startAt, maxResults int, states []string) (*model.BoardSprintPageScheme,
*model.ResponseScheme, error)
IssuesBySprint(ctx context.Context, boardID, sprintID int, opts *model.IssueOptionScheme, startAt, maxResults int) (
*model.BoardIssuePageScheme, *model.ResponseScheme, error)
Versions(ctx context.Context, boardID, startAt, maxResults int, released bool) (*model.BoardVersionPageScheme,
*model.ResponseScheme, error)
Delete(ctx context.Context, boardID int) (*model.ResponseScheme, error)
Gets(ctx context.Context, opts *model.GetBoardsOptions, startAt, maxResults int) (*model.BoardPageScheme,
*model.ResponseScheme, error)
}
Each service interface includes a set of methods that correspond to the available endpoints in the corresponding API. For example, the IssueService
interface includes methods like Create
, Update
, and Get
that correspond to the POST
, PUT
, and GET
endpoints in the Jira Issues API.
Behind the scenes, the Create
method on the IssueService
interface is implemented by the issueService.Create
function in the go-atlassian library. This function sends an HTTP request to the relevant endpoint in the Jira Issues API, using the credentials and configuration provided by the client, and then parses the response into a usable format.
Here's a little example about how to get the issue transitions using the Issue service.
ctx := context.Background()
issueKey := "KP-2"
expand := []string{"transitions"}
issue, response, err := atlassian.Issue.Get(ctx,issueKey, nil, expand)
if err != nil {
log.Fatal(err)
}
log.Println(issue.Key)
for _, transition := range issue.Transitions {
log.Println(transition.Name, transition.ID, transition.To.ID, transition.HasScreen)
}
The rest of the service functions work much the same way; they are concise and behave as you would expect. The documentation contains several examples on how to use each service function.
If you need to interact with an Atlassian API endpoint that hasn't been implemented in the go-atlassian
library yet, you can make a custom API request using the built-in Client.Call
method to execute raw HTTP requests.
Please raise an issue in order to implement the endpoint
package main
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"net/http"
"os"
)
type IssueTypeMetadata struct {
IssueTypes []struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
} `json:"issueTypes"`
}
func main() {
var (
host = os.Getenv("SITE")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v3.New(nil, host)
if err != nil {
log.Fatal(err)
}
atlassian.Auth.SetBasicAuth(mail, token)
// Define the RAW endpoint
apiEndpoint := "rest/api/3/issue/createmeta/KP/issuetypes"
request, err := atlassian.NewRequest(context.Background(), http.MethodGet, apiEndpoint, "", nil)
if err != nil {
log.Fatal(err)
}
customResponseStruct := new(IssueTypeMetadata)
response, err := atlassian.Call(request, &customResponseStruct)
if err != nil {
log.Fatal(err)
}
fmt.Println(response.Status)
}
If you would like to contribute to this project, please adhere to the following guidelines.
Submit an issue describing the problem.
Fork the repo and add your contribution.
Follow the basic Go conventions found here.
Create a pull request with a description of your changes.
Again, contributions are greatly appreciated!
The project was created with the purpose to provide a unique point to provide an interface for interacting with Atlassian products.
This module is highly inspired by the Go library https://github.com/andygrunwald/go-jira but focused on Cloud solutions.
The library shares many similarities with go-jira, including its use of service interfaces to define the functionality of each API, its modular and flexible approach to working with Atlassian products' API's. However, go-atlassian also adds several new features and improvements that are not present in go-jira.
Despite these differences, go-atlassian remains heavily inspired by go-jira, and many of the core design principles and patterns used in go-jira can be found in go-atlassian as well.
Copyright © 2023 Carlos Treminio. This project is MIT licensed.
We would like to extend our sincere thanks to the following sponsors for their generous support:
Atlassian for providing us Atlassian Admin/Jira/Confluence Standard licenses.
GitBook for providing us non-profit / open-source plan so hence I would like to express my thanks here.
The Jira audit logs are a set of records that document all the activities and changes made in Jira. These logs provide a detailed record of who did what, when, and where within Jira. Here are a few examples of the type of activities that are logged in the Jira audit logs:
The audit logs are useful for several reasons. For example, they can be used to track changes made to sensitive data, to identify who made specific changes to issues or projects, or to diagnose issues with Jira.
GET /rest/api/{2-3}/auditing/record
This method allows you to retrieve the audit records for specific activities that have occurred within Jira.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
"time"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
auditRecordOption := &models.AuditRecordGetOptions{
//Filter the records by a word, in that case, the custom field history
Filter: "",
//Filter the records by the last month
From: time.Now().AddDate(0, -1, 0),
// Today
To: time.Now(),
}
auditRecords, response, err := jira.Audit.Get(context.Background(), auditRecordOption, 0, 500)
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 _, record := range auditRecords.Records {
log.Printf("Record ID: %v", record.ID)
log.Printf("Record Category: %v", record.Category)
log.Printf("Record Created: %v", record.Created)
log.Printf("Record RemoteAddress: %v", record.RemoteAddress)
log.Printf("Record Summary: %v", record.Summary)
log.Printf("Record AuthorKey: %v", record.AuthorKey)
log.Printf("\n")
}
}
In this article, I would be showing you how to extract the Jira history information using a JQL query and saves it into a .csv file.
Create a new directory for your project.
Open a terminal and navigate to the project directory.
Initialize a new Go module using the following command:
In the terminal, run the following command to install the "go-atlassian" library:
Create a new Go file (e.g., main.go
) in your project directory.
Open the file and import the required packages:
In the main
function, create a new Jira client and authenticate using your Jira URL, username, and API token:
Add the following code inside the main
function to execute the JQL query and retrieve the issues:
Iterate over the retrieved issues and extract the changelog information.
Create a new CSV file and write the issue history data to it:
Save the main.go
file.
In the terminal, navigate to your project directory
Jira application roles are a way of managing user permissions and access in Jira. Jira comes with a set of predefined roles that define common types of users, such as administrators, developers, and project managers.
Each Jira application role has a set of permissions associated with it, which determine what actions a user in that role is allowed to perform. For example, the "Admin" role has permission to manage Jira system settings and users, while the "Developer" role has permission to create and edit issues and view source code.
GET /rest/api/{2-3}/applicationrole
This endpoint is used to retrieve a list of all application roles that are defined in a Jira instance. This endpoint can be used to get information about the roles that are available in Jira, and to help manage user access and permissions.
GET /rest/api/{2-3}/applicationrole/{key}
This method allows you to retrieve information about a specific application role in Jira using the key name as reference.
This resource represents issue resolution values. Use it to obtain a list of all issue resolution values and the details of individual resolution values.
GET /rest/api/{2-3}/resolution
Returns a list of all issue resolution values, the method returns the following information:
GET /rest/api/{2-3}/resolution/{id}
Returns an issue resolution value
No implemented, yet, feel free to open a PR or issue
No implemented, yet, feel free to open a PR or issue
No implemented, yet, feel free to open a PR or issue
No implemented, yet, feel free to open a PR or issue
No implemented, yet, feel free to open a PR or issue
No implemented, yet, feel free to open a PR or issue
In this article, I would be showing you how to edit a Jira issue with the VERB operation using the "go-atlassian" library.
Create a new directory for your project.
Open a terminal and navigate to the project directory.
Initialize a new Go module using the following command:
In the terminal, run the following command to install the "go-atlassian" library:
Create a new Go file (e.g., main.go
) in your project directory.
Open the file and import the required packages:
You can use the V2 and V3 Jira endpoint versions.
In the main
function, create a new Jira client and authenticate using your Jira URL, username, and API token:
The fields of an issue may also be updated in more flexible ways using the SET, ADD and REMOVE operations. Not all fields support all operations, but as a general rule single value fields support SET, whereas multi-value fields support SET, ADD and REMOVE, where SET replaces the field contents while ADD and REMOVE add or remove one or more values from the the current list of values.
Finally, call the Issue.Update() method and update the issue
Save the main.go
file.
In the terminal, navigate to your project directory.
Execute the following command to run the program:
The go-atlassian sm
module provides a set of functions and types for interacting with the Jira Service Management REST API. It provides a programmatic interface to interact with Jira Service Management, enabling developers to automate various aspects of service management.
Here are some key components and concepts related to the Jira Service Management REST API:
Request Types: Request types represent different types of service requests or issue types within Jira Service Management. Examples include "Incident," "Change Request," "Service Request," etc. Request types define the fields and workflows associated with each type of request.
Queues: Queues in Jira Service Management are used to organize and prioritize service requests. Requests are assigned to specific queues based on their attributes or criteria, such as request type, status, or assignee. Queues help teams manage and process incoming requests efficiently.
Approvers: Approvers are individuals or groups responsible for reviewing and approving certain actions or changes within Jira Service Management. For example, an approver might need to approve a change request before it can be implemented. The REST API allows you to retrieve and manage approvers associated with requests or specific workflows.
Customers: Customers in Jira Service Management represent the end-users or customers who raise service requests. These can be individuals or groups within an organization. The REST API enables you to create, update, and manage customer accounts, as well as retrieve information about customers and their associated requests.
Workflows: Workflows define the stages and transitions that a request goes through during its lifecycle in Jira Service Management. Workflows determine how requests move from one status to another, who can perform certain actions, and what actions are available at each stage. The REST API allows you to interact with workflows, including creating, updating, and transitioning requests between workflow states.
Service Level Agreements (SLAs): SLAs define the expected response and resolution times for different request types. They help teams prioritize and meet service-level targets. The REST API allows you to manage SLAs associated with requests, retrieve SLA information, and track SLA performance.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
resolutions, response, err := atlassian.Issue.Resolution.Gets(context.Background())
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for pos, resolution := range resolutions {
log.Println(pos, resolution)
}
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var resolutionID = "10000"
resolution, response, err := atlassian.Issue.Resolution.Get(context.Background(), resolutionID)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(resolution)
}
go mod init <module-name>
go get -v github.com/ctreminiom/go-atlassian
package main
import (
"fmt"
"log"
"os"
jira "github.com/ctreminiom/go-atlassian/jira/v2"
)
func main() {
jiraHost := "https://<_jira_instance_>.atlassian.net"
mailAddress := "<your_mail>"
apiToken := "<your_api_token>"
client, err := jira.New(nil, jiraHost)
if err != nil {
log.Fatal(err)
}
client.Auth.SetBasicAuth(mailAddress, apiToken)
}
var operations = &models.UpdateOperations{}
err = operations.AddStringOperation("summary", "set", "Big block Chevy")
if err != nil {
log.Fatal(err)
}
err = operations.AddArrayOperation("components", map[string]string{
"name": "Trans/A",
})
err = operations.AddArrayOperation("labels", map[string]string{
"triaged": "remove",
"triaged-2": "add",
})
// If the need to add multi-array customfields, you can the following method:
// In this particular example, we're going to the manipulate the fixVersions field.
operations.AddMultiRawOperation("fixVersions", []map[string]interface{}{
{
"remove": map[string]interface{}{
"name": "Version 00",
},
},
{
"remove": map[string]interface{}{
"name": "Version 101",
},
},
{
"add": map[string]interface{}{
"name": "Version 301",
},
},
})
var payload = models.IssueSchemeV2{
Fields: &models.IssueFieldsSchemeV2{
Summary: "New summary test",
Priority: &models.PriorityScheme{Name: "Minor"},
},
}
_, err = client.Issue.Update(context.Background(), "KP-2", false, &payload, nil, operations)
if err != nil {
log.Fatal(err)
}
go run main.go
go mod init <module-name>
go get -v github.com/ctreminiom/go-atlassian
package main
import (
"encoding/csv"
"fmt"
"log"
"os"
jira "github.com/ctreminiom/go-atlassian/jira/v2"
)
func main() {
jiraHost := "https://<_jira_instance_>.atlassian.net"
mailAddress := "<your_mail>"
apiToken := "<your_api_token>"
client, err := jira.New(nil, jiraHost)
if err != nil {
log.Fatal(err)
}
client.Auth.SetBasicAuth(mailAddress, apiToken)
}
jql := "order by created DESC"
var startAt int
var issues []*models.IssueSchemeV2
for {
log.Printf("Executing the pagination #%v", startAt)
issuePage, _, err := client.Issue.Search.Post(
context.Background(),
jql,
nil,
[]string{"changelog"},
startAt,
50,
"")
if err != nil {
log.Fatal(err)
}
issues = append(issues, issuePage.Issues...)
if len(issuePage.Issues) == 0 {
break
}
startAt += 50
}
var changelogs [][]string
for _, issue := range issues {
for _, history := range issue.Changelog.Histories {
for _, item := range history.Items {
var from string
if item.From == "" {
from = item.FromString
} else {
from = item.From
}
var to string
if item.To == "" {
to = item.ToString
} else {
to = item.To
}
changelogs = append(changelogs, []string{
issue.Key,
issue.Fields.Project.Name,
issue.Fields.Summary,
item.Field,
from,
to,
history.Created,
history.Author.EmailAddress,
})
}
}
}
file, err := os.Create("issue_history.csv")
if err != nil {
log.Fatal(err)
}
defer file.Close()
writer := csv.NewWriter(file)
defer writer.Flush()
// Write header
if err := writer.Write([]string{"Issue Key", "Project Name", "Issue Summary", "Issue Field", "From", "To", "When", "Who?"}); err != nil {
log.Fatal(err)
}
// Write the information
if err := writer.WriteAll(changelogs); err != nil {
log.Fatal(err)
}
log.Println("Issue history saved to issue_history.csv")
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
applicationRoles, response, err := jira.Role.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 _, role := range applicationRoles {
log.Println(role.Key, role.Name)
}
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
role, response, err := jira.Role.Get(context.Background(), "jira-core")
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("Status HTTP Response", response.Status)
}
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("Application Role Name: %v", role.Name)
log.Printf("Application Role Key: %v", role.Key)
log.Printf("Application Role User Count: %v", role.UserCount)
}
User login and logout events
Issue creation, modification, and deletion events
Workflow transition events
Project creation, modification, and deletion events
User management events such as user creation, modification, and deletion
User management events such as user creation, modification, and deletion
GET /rest/api/{2-3}/field/search/trashed
Search returns a paginated list of fields in the trash. The list may be restricted to fields whose field name or description partially match a string.
Only custom fields can be queried, type
must be set to custom
.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
options := &models.FieldSearchOptionsScheme{
IDs: nil,
//Query: "Application Name",
OrderBy: "name",
Expand: []string{"name", "-trashDate"},
}
fields, response, err := atlassian.Issue.Field.Trash.Search(context.Background(), options, 0, 50)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, field := range fields.Values {
log.Println(field)
}
}
POST /rest/api/{2-3}/field/{id}/trash
Move moves a custom field to trash
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Issue.Field.Trash.Move(context.Background(), "customfield_10020")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
POST /rest/api/{2-3}/field/{id}/restore
POST /rest/api/3/field/{id}/restoreRestore restores a custom field from trash
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Issue.Field.Trash.Restore(context.Background(), "customfield_10020")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
GET /rest/api/{2-3}/fieldconfiguration/{id}/fields
Returns a paginated list of all fields for a configuration.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
fieldConfigurationID, startAt, maxResults := 10000, 0, 50
items, response, err := atlassian.Issue.Field.Configuration.Item.Gets(context.Background(), fieldConfigurationID, startAt, maxResults)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, item := range items.Values {
log.Println("----------------------")
log.Println(item.ID)
log.Println(item.Description)
log.Println(item.IsRequired)
log.Println(item.IsRequired)
log.Println(item.Renderer)
log.Println("----------------------")
}
}
PUT /rest/api/{2-3}/fieldconfiguration/{id}/fields
Updates fields in a field configuration. The properties of the field configuration fields provided override the existing values.
The operation can set the renderer for text fields to the default text renderer (text-renderer
) or wiki style renderer (wiki-renderer
). However, the renderer cannot be updated for fields using the autocomplete renderer (autocomplete-renderer
).
package main
import (
"context"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
payload := &models.UpdateFieldConfigurationItemPayloadScheme{
FieldConfigurationItems: []*models.FieldConfigurationItemScheme{
{
ID: "components",
IsRequired: true,
},
},
}
response, err := atlassian.Issue.Field.Configuration.Item.Update(context.Background(), 10000, payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
This resource represents permissions. Use it to obtain details of all permissions and determine whether the user has certain permissions.
GET /rest/api/{2-3}/mypermissions
Returns a list of permissions indicating which permissions the user has. Details of the user's permissions can be obtained in a global, project, or issue context.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
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)
permissions, response, err := atlassian.Permission.Gets(context.Background())
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, permission := range permissions {
log.Println(permission)
}
}
POST /rest/api/{2-3}/permissions/check
for a list of global permissions, the global permissions are granted to a user.
for a list of project permissions and lists of projects and issues, for each project permission a list of the projects and issues a user can access or manipulate.
If no account ID is provided, the operation returns details for the logged-in user.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.PermissionCheckPayload{
GlobalPermissions: []string{"ADMINISTER"},
AccountID: "", //
ProjectPermissions: []*models.BulkProjectPermissionsScheme{
{
Issues: nil,
Projects: []int{10000},
Permissions: []string{"EDIT_ISSUES"},
},
},
}
grants, response, err := atlassian.Permission.Check(context.Background(), payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, permission := range grants.ProjectPermissions {
log.Println(permission.Permission, permission.Issues)
}
}
POST /rest/api/{2-3}/permissions/project
Returns all the projects where the user is granted a list of project permissions.
This operation can be accessed anonymously.
CREATE THE CODE SAMPLE
This resource represents the users assigned to project roles. Use this resource to get, add, and remove default users from project roles. Also use this resource to add and remove users from a project
POST /rest/api/{2-3}/project/{projectIdOrKey}/role/{id}
Adds actors to a project role for the project.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 (
projectKeyOrID = "KP"
projectRoleID = 10005
accountIDs = []string{"5b86be50b8e3cb5895860d6d"}
groupsNames = []string{"scrum-masters"}
)
role, response, err := atlassian.Project.Role.Actor.Add(context.Background(),
projectKeyOrID, projectRoleID, accountIDs, groupsNames)
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 _, actor := range role.Actors {
log.Println(actor)
}
}
DELETE /rest/api/{2-3}/project/{projectIdOrKey}/role/{id}
Deletes actors from a project role for the project.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 (
projectKeyOrID = "KP"
projectRoleID = 10005
accountID = "5b86be50b8e3cb5895860d6d"
groupName = "scrum-masters"
)
response, err := atlassian.Project.Role.Actor.Delete(context.Background(),
projectKeyOrID,
projectRoleID,
accountID,
groupName,
)
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)
}
GET /rest/api/{2-3}/project/{projectIdOrKey}/features
Returns the list of features for a project.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
v2 "github.com/ctreminiom/go-atlassian/v2/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)
features, response, err := atlassian.Project.Feature.Gets(context.Background(), "KP")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, feature := range features.Features {
log.Printf("%#v", feature)
}
}
PUT /rest/api/{2-3}/project/{projectIdOrKey}/features/{featureKey}
Sets the state of a project feature.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
v2 "github.com/ctreminiom/go-atlassian/v2/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)
projectKeyOrID := "KP"
featureKey := "jsw.classic.deployments"
state := "DISABLED"
features, response, err := atlassian.Project.Feature.Set(context.Background(), projectKeyOrID, featureKey, state)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, feature := range features.Features {
log.Printf("%#v", feature)
}
}
GET /rest/servicedeskapi/knowledgebase/article
Returns articles that match the given query string across all service desks.
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 (
query = "login"
start = 0
limit = 50
)
articles, response, err := atlassian.Knowledgebase.Search(
context.Background(),
query,
false,
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 _, article := range articles.Values {
log.Println(article)
}
}
GET /rest/servicedeskapi/servicedesk/{serviceDeskId}/knowledgebase/article
Returns articles that match the given query and belong to the knowledge base linked to the 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 (
serviceDeskID = 1
query = "login"
start = 0
limit = 50
)
articles, response, err := atlassian.Knowledgebase.Gets(
context.Background(),
serviceDeskID,
query,
false,
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 _, article := range articles.Values {
log.Println(article)
}
}
This resource provides information about the Jira instance.
GET /rest/api/{2-3}/serverInfo
Returns information about the Jira instance.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
info, response, err := atlassian.Server.Info(context.Background())
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(info)
}
In this article, I would be showing you how to extract user last-activity information from the Atlassian Admin API's using go-atlassian
Create a new directory for your project and navigate to it in your terminal or command prompt. Initialize a new Go module using the following command:
go mod init your-module-name
To use the "go-atlassian" library, you need to install it as a dependency in your project. Run the following command:
go get github.com/ctreminiom/go-atlassian
Create a new Go file, e.g., main.go
, and import the necessary packages:
package main
import (
"fmt"
"log"
"github.com/ctreminiom/go-atlassian/admin"
)
Initialize the Atlassian Admin client with your API token:
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")
}
It's required to extract the ID of the organization you're using, the organization ID can be extract on the admin URL, as the image below:
In this step, we're going to extract the organization users and store them into an array variable, please use the following code block to extract them.
// Extract the organization users
var (
organizationID = "9a1jj823-jac8-123d-jj01-63315k059cb2"
cursor string
users []*models.AdminOrganizationUserScheme
)
for {
page, 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)
}
users = append(users, page.Data...)
if len(page.Links.Next) == 0 {
break
}
//extract the next cursor pagination
nextAsURL, err := url.Parse(page.Links.Next)
if err != nil {
log.Fatal(err)
}
cursor = nextAsURL.Query().Get("cursor")
}
for _, user := range users {
log.Println("Name:", user.Name, " -- ID:", user.AccountID)
}
With the organization users extracted, we need to iterate each user and extract the last-login information, you can use the following code to do that:
for _, user := range users {
lastLogin, response, err := cloudAdmin.Organization.Directory.Activity(context.Background(), organizationID, user.AccountID)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
// The products are iterated because an Atlassian user may contain multiple products
// If you're looking to a specific product, you can modify the loop logic and extract
// the last-login for Jira or Confluence
for _, product := range lastLogin.Data.ProductAccess {
fmt.Println(lastLogin.Data.AddedToOrg, product)
}
}
This is an experimental API,
Teams in Advanced Roadmaps are different from the teams found in the rest of Jira Software Cloud. In Advanced Roadmaps, they act as a label applied to issues that designates which team will eventually pick up the work on your timeline. By adding the Team field to your Jira issues, you can save this value back to your Jira issues, which makes sprint planning easier.
Since Advanced Roadmaps is a planning tool, the Team field is a way to use features like capacity management without assigning issues to individuals, which happens in sprint grooming or planning sessions.
You can also use Advanced Roadmaps' view settings to focus on work assigned to a specific team. For example, you can choose to color issues based on the team to which they’re assigned, group issues by team on your timeline, or hide teams from your view.
POST /rest/teams/1.0/teams/find
Gets returns the Teams information from the Jira Advanced Roadmaps application.
Teams in Advanced Roadmaps are different from the teams found in the rest of Jira Software Cloud. In Advanced Roadmaps, they act as a label applied to issues that designates which team will eventually pick up the work on your timeline.
By adding the Team field to your Jira issues, you can save this value back to your Jira issues, which makes sprint planning easier
POST /rest/teams/1.0/teams/create
Create create creates a team on the Advanced Roadmaps.
package main
import (
"context"
"fmt"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
teams, response, err := atlassian.Team.Gets(context.Background(), 1000)
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 _, team := range teams.Teams {
fmt.Println(team.Title, team.Id, team.ExternalId, team.Shareable)
}
for _, person := range teams.Persons {
fmt.Println(person.PersonId, person.JiraUser)
}
}
package main
import (
"context"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"github.com/davecgh/go-spew/spew"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
payload := &models.JiraTeamCreatePayloadScheme{
Title: "Team Voldemort",
Shareable: true,
Resources: nil,
}
team, response, err := atlassian.Team.Create(context.Background(), payload)
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)
spew.Dump(team)
}
GET /rest/api/{2-3}/projectvalidate/key
Validates a project key by confirming the key is a valid string and not in use.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
message, response, err := atlassian.Project.Valid.Validate(context.Background(), "KP")
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(message)
}
GET /rest/api/{2-3}/projectvalidate/validProjectKey
Validates a project key and, if the key is invalid or in use, generates a valid random string for the project key.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
message, response, err := atlassian.Project.Valid.Key(context.Background(), "KP")
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(message)
}
GET /rest/api/{2-3}/projectvalidate/validProjectName
Checks that a project name isn't in use. If the name isn't in use, the passed string is returned. If the name is in use, this operation attempts to generate a valid project name based on the one supplied, usually by adding a sequence number. If a valid project name cannot be generated, a 404 response is returned.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
message, response, err := atlassian.Project.Valid.Name(context.Background(), "KP")
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(message)
}
PUT /rest/api/{2-3}/issue/archive
Preserve archives the given issues based on their issue IDs or keys.
package main
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
fmt.Println(host)
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
atlassian.Auth.SetBasicAuth(mail, token)
archivalResult, response, err := atlassian.Archive.Preserve(context.Background(), []string{"KP-2"})
if err != nil {
if response != nil {
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}
log.Fatal(err)
}
fmt.Println(archivalResult.NumberOfIssuesUpdated)
}
POST /rest/api/{2-3}/issue/archive
PreserveByJQL archives issues than match the provided JQL query.
package main
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
fmt.Println(host)
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
atlassian.Auth.SetBasicAuth(mail, token)
taskID, response, err := atlassian.Archive.PreserveByJQL(context.Background(), "project = WORK")
if err != nil {
if response != nil {
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}
log.Fatal(err)
}
fmt.Println(taskID)
}
PUT /rest/api/{2-3}/issue/unarchive
Restore brings back the given archived issues using their issue IDs or keys.
package main
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/v2/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=""
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")
)
fmt.Println(host)
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
atlassian.Auth.SetBasicAuth(mail, token)
archivalResult, response, err := atlassian.Archive.Restore(context.Background(), []string{"KP-2"})
if err != nil {
if response != nil {
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}
log.Fatal(err)
}
fmt.Println(archivalResult.NumberOfIssuesUpdated)
}
PUT /rest/api/{2-3}/issues/archive/export
Export generates an export of archived issues based on the provided payload.
package main
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/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=""
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)
exportConfigPayload := &models.IssueArchivalExportPayloadScheme{
/*
ArchivedBy: []string{
"uuid-sample",
"uuid-sample",
},
*/
ArchivedDateRange: &models.DateRangeFilterRequestScheme{
DateAfter: "2023-01-01",
DateBefore: "2023-01-12",
},
//IssueTypes: []string{"Bug", "Story"},
Projects: []string{"WORK"},
//Reporters: []string{"uuid-sample"},
}
taskID, response, err := atlassian.Archive.Export(context.Background(), exportConfigPayload)
if err != nil {
if response != nil {
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}
log.Fatal(err)
}
fmt.Println(response.Endpoint)
fmt.Println(taskID)
}
This resource represents votes cast by users on an issue. Use it to get details of votes on an issue as well as cast and withdrawal votes.
GET /rest/api/{2-3}/issue/{issueIdOrKey}/votes
Returns details about the votes on an issue.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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)
votes, response, err := atlassian.Issue.Votes.Gets(context.Background(), "KP-2")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, voter := range votes.Voters {
log.Println(voter.DisplayName, voter.Self)
}
}
POST /rest/api/{2-3}/issue/{issueIdOrKey}/votes
Adds the user's vote to an issue. This is the equivalent of the user clicking Vote on an issue in Jira.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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.Issue.Votes.Add(context.Background(), "KP-2")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
DELETE /rest/api/{2-3}/issue/{issueIdOrKey}/votes
Deletes a user's vote from an issue. This is the equivalent of the user clicking Unvote on an issue in Jira.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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.Issue.Votes.Delete(context.Background(), "KP-2")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
This resource represents various ways to search for issues. Use it to search for issues with a JQL query and find issues to populate an issue picker.
GET /rest/api/{2-3}/search
Searches for issues using . If the JQL query expression is too large to be encoded as a query parameter, use the version of this resource.
POST /rest/api/{2-3}/search
Searches for issues using . There is a version of this resource that can be used for smaller JQL query expressions.
POST /rest/api/{2-3}/jql/match
Checks whether one or more issues would be returned by one or more JQL queries.
GET /rest/api/{2-3}/user/assignable/multiProjectSearch
Returns a list of users who can be assigned issues in one or more projects. The list may be restricted to users whose attributes match a string.
GET /rest/api/{2-3}/user/search
Returns a list of users that match the search string and property.
GET /rest/api/{2-3}/user/viewissue/search
Returns a list of users who fulfill these criteria:
their user attributes match a search string.
they have a set of permissions for a project or issue.
GET /rest/agile/1.0/epic/{epicIdOrKey}
Returns the epic for a given epic ID. This epic will only be returned if the user has permission to view it.
Note: This operation does not work for epics in next-gen projects.
GET /rest/agile/1.0/epic/{epicIdOrKey}/issue
Returns all issues that belong to the epic, for the given epic ID. This only includes issues that the user has permission to view. Issues returned from this resource include Agile fields, like sprint, closedSprints, flagged, and epic. By default, the returned issues are ordered by rank.
Note: If you are querying a next-gen project, do not use this operation. Instead, search for issues that belong to an epic by using the Search for issues using JQL operation in the Jira platform REST API.
Build your JQL query using the parent clause. For more information on the parent JQL field, see Advanced searching.
POST /rest/agile/1.0/epic/{epicIdOrKey}/issue
Move moves issues to an epic, for a given epic id. Issues can be only in a single epic at the same time. That means that already assigned issues to an epic, will not be assigned to the previous epic anymore. The user needs to have the edit issue permission for all issue they want to move and to the epic. The maximum number of issues that can be moved in one operation is 50.
System Administrators can configure an announcement banner to display pertinent information on all Jira pages. The banner can be used to relate important information (e.g. scheduled server maintenance, approaching project deadlines, etc.) to all users. Further, the banner visibility level can be configured to display to all users or just logged-in users.
GET /rest/api/{2/3}/announcementBanner
Get returns the current announcement banner configuration.
PUT /rest/api/{2-3}/announcementBanner
Update updates the announcement banner configuration.
In Jira, a backlog is a prioritized list of work items that need to be completed. It serves as a repository for all the tasks, user stories, bugs, and other work items that are yet to be worked on or are in the planning stage. Backlogs are typically associated with agile project management methodologies such as Scrum and Kanban.
Backlogs are visualized as lists of items that can be sorted, filtered, and prioritized. Teams can easily move items between different backlogs, update their status, estimate effort, and collaborate on the work items. Backlogs provide a centralized view of all the work in progress and assist in effective planning, tracking, and delivery of projects.
POST /rest/agile/1.0/backlog/issue
Move moves issues to the backlog.
This operation is equivalent to remove future and active sprints from a given set of issues.
At most 50 issues may be moved at once.
POST /rest/agile/1.0/backlog/{boardId}/issue
This operation is equivalent to remove future and active sprints from a given set of issues if the board has sprints.
If the board does not have sprints this will put the issues back into the backlog from the board.
At most 50 issues may be moved at once.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 = ""
projectKeys = []string{"KP"}
startAt = 0
maxResults = 50
)
users, response, err := atlassian.User.Search.Projects(context.Background(), accountID, projectKeys, startAt, maxResults)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, user := range users {
log.Println(user)
}
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 = ""
query = ""
startAt = 0
maxResults = 50
)
users, response, err := atlassian.User.Search.Do(context.Background(), accountID, query, startAt, maxResults)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, user := range users {
log.Println(user)
}
}
package main
import (
"context"
"fmt"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
options := &models.UserPermissionCheckParamsScheme{
Query: "",
AccountID: "5b86be50b8e3cb5895860d6d",
IssueKey: "",
ProjectKey: "KP",
}
users, response, err := jira.User.Search.Check(context.Background(), "EDIT_ISSUE", options, 0, 50)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
for _, user := range users {
fmt.Println(user)
}
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
epic, response, err := atlassian.Epic.Get(context.Background(), "KP-16")
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(epic)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
var (
options = &models.IssueOptionScheme{
JQL: "project = KP",
ValidateQuery: true,
Fields: []string{"status", "issuetype", "summary"},
Expand: []string{"changelog"},
}
epicKey = "KP-16"
startAt = 0
maxResult = 50
)
issues, response, err := atlassian.Epic.Issues(context.Background(), epicKey, options, startAt, maxResult)
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 _, issue := range issues.Issues {
log.Println(issue.Key)
}
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
response, err := atlassian.Epic.Move(context.Background(), "KP-16", []string{"DUMMY-1"})
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)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
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 (
jql = "order by created DESC"
fields = []string{"status"}
expand = []string{"changelog", "renderedFields", "names", "schema", "transitions", "operations", "editmeta"}
)
issues, response, err := atlassian.Issue.Search.Get(context.Background(), jql, fields, expand, 0, 50, "")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(issues.Total)
for _, issue := range issues.Issues {
for _, history := range issue.Changelog.Histories {
for _, item := range history.Items {
log.Println(issue.Key, item.Field, history.Author.DisplayName)
}
}
}
for _, issue := range issues.Issues {
for _, transition := range issue.Transitions {
log.Println(issue.Key, transition.Name, transition.ID)
}
}
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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 (
jql = "order by created DESC"
fields = []string{"status"}
expand = []string{"changelog", "renderedFields", "names", "schema", "transitions", "operations", "editmeta"}
)
issues, response, err := atlassian.Issue.Search.Post(context.Background(), jql, fields, expand, 0, 50, "")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(issues.Total)
}
package main
import (
"context"
"fmt"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
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.IssueSearchCheckPayloadScheme{
IssueIds: []int{10036},
JQLs: []string{"issuekey = KP-23"},
}
matches, response, err := atlassian.Issue.Search.Checks(context.Background(), payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, match := range matches.Matches {
fmt.Println(match)
}
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
banner, response, err := jira.Banner.Get(context.Background())
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("Status HTTP Response", response.Status)
}
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(banner.Message)
log.Println(banner.IsDismissible)
log.Println(banner.HashId)
log.Println(banner.IsEnabled)
log.Println(banner.Visibility)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
payload := &models.AnnouncementBannerPayloadScheme{
IsDismissible: true,
IsEnabled: true,
Message: "This is a public, enabled, non-dismissible banner, set using the API",
Visibility: "public",
}
response, err := jira.Banner.Update(context.Background(), payload)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("Status HTTP Response", response.Status)
}
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}
This resource represents issue link types. Use it to get, create, update, and delete link issue types as well as get lists of all link issue types.
GET /rest/api/{2-3}/issueLinkType
Returns a list of all issue link types, the method returns the following information:
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
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)
types, response, err := atlassian.Issue.Link.Type.Gets(context.Background())
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, value := range types.IssueLinkTypes {
log.Println(value)
}
}
POST /rest/api/{2-3}/issueLinkType
Creates an issue link type. Use this operation to create descriptions of the reasons why issues are linked.
The issue link type consists of a name and descriptions for a link's inward and outward relationships, the method returns the following information:
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
payload := models.LinkTypeScheme{
Inward: "Clone/Duplicated by",
Name: "Clone/Duplicate",
Outward: "Clone/Duplicates",
}
issueLinkType, response, err := atlassian.Issue.Link.Type.Create(context.Background(), &payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(issueLinkType)
}
GET /rest/api/{2-3}/issueLinkType/{issueLinkTypeId}
Returns an issue link type, the method returns the following information:
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
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)
issueLinkType, response, err := atlassian.Issue.Link.Type.Get(context.Background(), "10000")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(issueLinkType)
}
PUT /rest/api/{2-3}/issueLinkType/{issueLinkTypeId}
Updates an issue link type, the method returns the following information:
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
payload := models.LinkTypeScheme{
Inward: "Clone/Duplicated by - Updated",
Name: "Clone/Duplicate - Updated",
Outward: "Clone/Duplicates - Updated",
}
issueLinkType, response, err := atlassian.Issue.Link.Type.Update(context.Background(), "10008", &payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(issueLinkType)
}
DELETE /rest/api/{2-3}/issueLinkType/{issueLinkTypeId}
Deletes an issue link type, the method returns the following information:
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Issue.Link.Type.Delete(context.Background(), "10008")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
GET /rest/api/{2-3}/field
Returns system and custom issue fields according to the following rules:
Fields that cannot be added to the issue navigator are always returned.
Fields that cannot be placed on an issue screen are always returned.
Fields that depend on global Jira settings are only returned if the setting is enabled. That is, timetracking fields, subtasks, votes, and watches.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
fields, response, err := atlassian.Issue.Field.Gets(context.Background())
if err != nil {
log.Fatal(err)
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, field := range fields {
log.Println(field)
}
}
POST /rest/api/{2-3}/field
Creates a custom field, the method returns the following information:
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
fieldNewCreate := models.CustomFieldScheme{
Name: "Alliance 2",
Description: "this is the alliance description field",
FieldType: "cascadingselect",
SearcherKey: "cascadingselectsearcher",
}
field, response, err := atlassian.Issue.Field.Create(context.Background(), &fieldNewCreate)
if err != nil {
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println("field", field)
}
GET /rest/api/{2-3}/field/search
Returns a paginated list of fields for Classic Jira projects. The list can include:
all fields.
specific fields, by defining id
.
fields that contain a string in the field name or description, by defining query
.
specific fields that contain a string in the field name or description, by defining id
and query
.
Only custom fields can be queried, type
must be set to custom
. the method returns the following information:
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
options := models.FieldSearchOptionsScheme{
Types: []string{"custom"},
OrderBy: "lastUsed",
Expand: []string{"screensCount", "lastUsed"},
}
fields, response, err := atlassian.Issue.Field.Search(context.Background(), &options, 0, 50)
if err != nil {
log.Fatal(err)
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(fields.IsLast, fields.Total, fields.MaxResults, fields.StartAt)
for _, field := range fields.Values {
log.Println(field.ID, field.Description)
}
}
DELETE /rest/api/{2-3}/field/{id}
Deletes a custom field. The custom field is deleted whether it is in the trash or not.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
task, response, err := atlassian.Issue.Field.Delete(context.Background(), "customfield_103034")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(task.Status, task.ID, task.Finished)
}
GET /rest/api/{2-3}/workflowscheme/{id}/issuetype/{issueType}
Get returns the issue type-workflow mapping for an issue type in a workflow scheme.
package main
import (
"context"
"fmt"
v3 "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v3.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
mapping, response, err := instance.Workflow.Scheme.IssueType.Get(context.Background(), 10002, "10007", false)
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
fmt.Println(mapping)
}
PUT /rest/api/{2-3}/workflowscheme/{id}/issuetype/{issueType}
Set sets the workflow for an issue type in a workflow scheme.
Note that active workflow schemes cannot be edited. If the workflow scheme is active, set updateDraftIfNeeded
to true
in the request body and a draft workflow scheme is created or updated with the new issue type-workflow mapping. The draft workflow scheme can be published in Jira.
package main
import (
"context"
"fmt"
v3 "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v3.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
payload := &models.IssueTypeWorkflowPayloadScheme{
IssueType: "10000",
UpdateDraftIfNeeded: false,
Workflow: "DESK: Jira Service Management default workflow",
}
workflowScheme, response, err := instance.Workflow.Scheme.IssueType.Set(context.Background(), 10007, "10007", payload)
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
fmt.Println(workflowScheme)
}
DELETE /rest/api/{2-3}/workflowscheme/{id}/issuetype/{issueType}
Delete deletes the issue type-workflow mapping for an issue type in a workflow scheme.
Note that active workflow schemes cannot be edited. If the workflow scheme is active, set updateDraftIfNeeded
to true
and a draft workflow scheme is created or updated with the issue type-workflow mapping deleted. The draft workflow scheme can be published in Jira.
package main
import (
"context"
"fmt"
v3 "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v3.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
mapping, response, err := instance.Workflow.Scheme.IssueType.Delete(context.Background(), 10002, "10000", false)
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
fmt.Println(mapping)
}
GET /rest/api/{2-3}/workflowscheme/{id}/workflow
Mapping returns the workflow-issue type mappings for a workflow scheme.
package main
import (
"context"
"fmt"
v3 "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v3.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
mapping, response, err := instance.Workflow.Scheme.IssueType.Mapping(context.Background(), 10007, "", false)
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
log.Println(response.Endpoint)
for _, element := range mapping {
fmt.Println(element.Workflow, element.Workflow)
}
}
Not implemented, feel free to open a PR 👍
Not implemented, feel free to open a PR 👍
GET /rest/api/{2-3}/screens/{screenId}/tabs/{tabId}/fields
Returns all fields for a screen tab.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 (
screenID = 10000
tabID = 10003
)
fields, response, err := atlassian.Screen.Tab.Field.Gets(context.Background(), screenID, tabID)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, field := range fields {
log.Println(field)
}
}
POST /rest/api/{2-3}/screens/{screenId}/tabs/{tabId}/fields
Adds a field to a screen tab.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 (
screenID = 10000
tabID = 10003
fieldID = "customfield_10030"
)
tab, response, err := atlassian.Screen.Tab.Field.Add(context.Background(), screenID, tabID, fieldID)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(tab)
}
DELETE /rest/api/{2-3}/screens/{screenId}/tabs/{tabId}/fields/{id}
Removes a field from a screen tab.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 (
screenID = 10000
tabID = 10003
fieldID = "customfield_10030"
)
response, err := atlassian.Screen.Tab.Field.Remove(context.Background(), screenID, tabID, fieldID)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
agile, err := agile.New(nil, host)
if err != nil {
return
}
agile.Auth.SetBasicAuth(mail, token)
agile.Auth.SetUserAgent("curl/7.54.0")
response, err := agile.Backlog.Move(context.Background(), []string{"KP-23"})
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("Status HTTP Response", response.Status)
}
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
return
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
agile, err := agile.New(nil, host)
if err != nil {
return
}
agile.Auth.SetBasicAuth(mail, token)
agile.Auth.SetUserAgent("curl/7.54.0")
payload := &models.BoardBacklogPayloadScheme{
Issues: []string{"KP-23"},
RankBeforeIssue: "",
RankAfterIssue: "",
RankCustomFieldId: 0,
}
response, err := agile.Backlog.MoveTo(context.Background(), 5, payload)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("Status HTTP Response", response.Status)
}
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
return
}
GET /rest/api/{2-3}/permissionscheme/{schemeId}/permission
Returns all permission grants for a permission scheme.
POST /rest/api/{2-3}/permissionscheme/{schemeId}/permission
Creates a permission grant in a permission scheme.
GET /rest/api/{2-3}/permissionscheme/{schemeId}/permission/{permissionId}
Returns a permission grant.
DELETE /rest/api/{2-3}/permissionscheme/{schemeId}/permission/{permissionId}
Deletes a permission grant from a permission scheme
GET /rest/api/{2-3}/issue/createmeta/{projectIdOrKey}/issuetypes
FetchIssueMappings returns a page of issue type metadata for a specified project. Use the information to populate the requests in and . This operation can be accessed anonymously.
GET /rest/api/3/issue/createmeta/{projectIdOrKey}/issuetypes/{issueTypeId}
Returns a page of field metadata for a specified project and issuetype id. Use the information to populate the requests in and . This operation can be accessed anonymously.
GET /rest/api/{2-3}/issue/{issueIdOrKey}/editmeta
Returns the edit screen fields for an issue that are visible to and editable by the user. Use the information to populate the requests in .
GET /rest/api/{2-3}/issue/createmeta
Returns details of projects, issue types within projects, and, when requested, the create screen fields for each issue type for the user. Use the information to populate the requests in and .
GET /rest/api/{2-3}/project/type
Returns all
GET /rest/api/{2-3}/project/type/accessible
Returns all
GET /rest/api/{2-3}/project/type/{projectTypeKey}
Returns a
GET /rest/api/{2-3}/project/type/{projectTypeKey}/accessible
Returns a
GET /rest/api/{2-3}/project/{projectIdOrKey}/properties
Returns all keys for the project.
GET /rest/api/{2-3}/project/{projectIdOrKey}/properties/{propertyKey}
Returns the value of a .
PUT /rest/api/{2-3}/project/{projectIdOrKey}/properties/{propertyKey}
Sets the value of the . You can use project properties to store custom data against the project.
DELETE /rest/api/{2-3}/project/{projectIdOrKey}/properties/{propertyKey}
Deletes the from a project.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 permissionSchemeID = 10002
grants, response, err := atlassian.Permission.Scheme.Grant.Gets(context.Background(), permissionSchemeID, []string{"all"})
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, grant := range grants.Permissions {
log.Println(grant)
}
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
var permissionSchemeID = 10001
grant := &models.PermissionGrantPayloadScheme{
Holder: &models.PermissionGrantHolderScheme{
Parameter: "jira-administrators-system",
Type: "group",
},
Permission: "EDIT_ISSUES",
}
permissionGrant, response, err := atlassian.Permission.Scheme.Grant.Create(context.Background(), permissionSchemeID, grant)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(permissionGrant)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 (
permissionSchemeID = 10002
permissionGrantID = 10517
)
grant, response, err := atlassian.Permission.Scheme.Grant.Get(context.Background(), permissionSchemeID, permissionGrantID, []string{"all"})
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(grant)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 (
permissionSchemeID = 10002
permissionGrantID = 10517
)
response, err := atlassian.Permission.Scheme.Grant.Delete(context.Background(), permissionSchemeID, permissionGrantID)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
issueTypeMappings, response, err := atlassian.Issue.Metadata.FetchIssueMappings(context.Background(), "KP", 0, 50)
if err != nil {
log.Println(response.Bytes.String())
log.Fatal(err)
}
fmt.Println(response.Endpoint)
for _, issueType := range issueTypeMappings.Get("issueTypes").Array() {
/*
{
"description": "An error in the code",
"iconUrl": "https://your-domain.atlassian.net/images/icons/issuetypes/bug.png",
"id": "1",
"name": "Bug",
"self": "https://your-domain.atlassian.net/rest/api/3/issueType/1",
"subtask": false
}
*/
fmt.Println(issueType.Get("description").String())
fmt.Println(issueType.Get("iconUrl").String())
fmt.Println(issueType.Get("id").String())
fmt.Println(issueType.Get("name").String())
fmt.Println(issueType.Get("self").String())
fmt.Println(issueType.Get("subtask").Bool())
fmt.Println("------------")
}
}
package main
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
fieldsMappings, response, err := atlassian.Issue.Metadata.FetchFieldMappings(context.Background(), "KP", "10001", 0, 50)
if err != nil {
log.Println(response.Bytes.String())
log.Fatal(err)
}
fmt.Println(response.Endpoint)
for _, fieldSchema := range fieldsMappings.Get("fields").Array() {
fmt.Println("fieldId", fieldSchema.Get("fieldId"))
fmt.Println("required", fieldSchema.Get("required"))
fmt.Println("name", fieldSchema.Get("name"))
fmt.Println("key", fieldSchema.Get("key"))
fmt.Println("autoCompleteUrl", fieldSchema.Get("autoCompleteUrl"))
fmt.Println("hasDefaultValue", fieldSchema.Get("hasDefaultValue"))
fmt.Println("operations", fieldSchema.Get("operations").String())
fmt.Println("schema.type", fieldSchema.Get("schema.type"))
fmt.Println("schema.system", fieldSchema.Get("schema.system"))
fmt.Println("schema.items", fieldSchema.Get("schema.items"))
fmt.Println("------------")
}
}
package main
import (
"context"
"fmt"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
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)
metadata, response, err := atlassian.Issue.Metadata.Get(context.Background(), "KP-1", false, false)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
fields, response, err := atlassian.Issue.Field.Gets(context.Background())
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, field := range fields {
path := fmt.Sprintf("fields.%v.required", field.ID)
value := metadata.Get(path)
if value.Exists() {
fmt.Println("Field Name:", field.Name, "Required?:", value.String())
}
}
}
package main
import (
"context"
"fmt"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
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)
options := &models.IssueMetadataCreateOptions{
ProjectIDs: nil,
ProjectKeys: []string{"KP"},
IssueTypeIDs: nil,
IssueTypeNames: nil,
Expand: "",
}
metadata, response, err := atlassian.Issue.Metadata.Create(context.Background(), options)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
fmt.Println(metadata)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
projectTypes, response, err := atlassian.Project.Type.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)
log.Println("Response Buffer", response.Bytes.String())
for _, projectType := range projectTypes {
log.Println(projectType)
}
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
projectTypes, response, err := atlassian.Project.Type.Licensed(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 _, projectType := range projectTypes {
log.Println(projectType.Key)
}
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
projectType, response, err := atlassian.Project.Type.Get(context.Background(), "software")
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(projectType)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
projectType, response, err := atlassian.Project.Type.Accessible(context.Background(), "software")
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(projectType)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
v2 "github.com/ctreminiom/go-atlassian/v2/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)
properties, response, err := atlassian.Project.Property.Gets(context.Background(), "KP")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, key := range properties.Keys {
log.Printf("Key: %v -- Self: %v", key.Key, key.Self)
}
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
v2 "github.com/ctreminiom/go-atlassian/v2/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)
property, response, err := atlassian.Project.Property.Get(context.Background(), "KP", "jswSelectedBoardType")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("Key: %v -- Value: %v", property.Key, property.Value)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
v2 "github.com/ctreminiom/go-atlassian/v2/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)
payload := `{
"number": 5,
"string": "string-value"
}`
response, err := atlassian.Project.Property.Set(context.Background(), "KP", "property-key", &payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
v2 "github.com/ctreminiom/go-atlassian/v2/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.Project.Property.Delete(context.Background(), "KP", "property-key")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
GET /rest/api/{2-3}/issue/{issueIdOrKey}/properties
Gets returns the URLs and keys of an issue's properties.
package main
import (
"context"
"fmt"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"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)
properties, response, err := atlassian.Issue.Property.Gets(context.Background(), "KP-3")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, key := range properties.Keys {
fmt.Println(key.Self, key.Key)
}
}
GET /rest/api/{2-3}/issue/{issueIdOrKey}/properties/{propertyKey}
Get returns the key and value of an issue's property.
package main
import (
"context"
"fmt"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"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)
property, response, err := atlassian.Issue.Property.Get(context.Background(), "KP-3", "property-key")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
switch value := property.Value.(type) {
case string:
fmt.Println(value)
case int:
fmt.Println(value)
case map[string]interface{}:
for key, mapValue := range value {
fmt.Println(key, mapValue)
}
default:
fmt.Printf("I don't know about type %T!\n", value)
}
}
PUT /rest/api/{2-3}/issue/{issueIdOrKey}/properties/{propertyKey}
Set sets the value of an issue's property. Use this resource to store custom data against an issue.
package main
import (
"context"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"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 := `{
"number": 5,
"string": "string-value"
}`
response, err := atlassian.Issue.Property.Set(context.Background(), "KP-3", "property-key", &payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
DELETE /rest/api/{2-3}/issue/{issueIdOrKey}/properties/{propertyKey}
Deletes deletes an issue's property.
package main
import (
"context"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"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.Issue.Property.Delete(context.Background(), "KP-3", "property-key")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
GET /rest/api/{2-3}/screenscheme
Returns a paginated list of screen schemes. Only screen schemes used in classic projects are returned.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
screenSchemes, response, err := atlassian.Screen.Scheme.Gets(context.Background(), nil, 0, 50)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, screenScheme := range screenSchemes.Values {
log.Println(screenScheme)
}
}
POST /rest/api/{2-3}/screenscheme
Creates a screen scheme.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.ScreenSchemePayloadScheme{
Screens: &models.ScreenTypesScheme{
Default: 10000,
View: 10000,
Edit: 10000,
},
Name: "FX | Epic Screen Scheme",
Description: "sample description",
}
newScreenScheme, response, err := atlassian.Screen.Scheme.Create(context.Background(), payload)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("The new screen scheme has been created with the ID %v", newScreenScheme.ID)
}
PUT /rest/api/{2-3}/screenscheme/{screenSchemeId}
Updates a screen scheme. Only screen schemes used in classic projects can be updated.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.ScreenSchemePayloadScheme{
Screens: &models.ScreenTypesScheme{
Default: 10001,
View: 10000,
Edit: 10000,
},
Name: "FX | Epic Screen Scheme - UPDATED",
Description: "sample description - UPDATED",
}
response, err := atlassian.Screen.Scheme.Update(context.Background(), "10005", payload)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}
DELETE /rest/api/{2-3}/screenscheme/{screenSchemeId}
Deletes a screen scheme. A screen scheme cannot be deleted if it is used in an issue type screen scheme. Only screens schemes used in classic projects can be deleted.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.Screen.Scheme.Delete(context.Background(), "10005")
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}
You can link issues to keep track of duplicate or related work. You can, for example:
create a new linked issue from an existing issue in a service project or business project
create an association between an issue and a Confluence page
link an issue to any other web page
Make sure you have the link issues project permission before getting started. Note that your Jira administrator can customize the types of links that you can create.
POST /rest/api/{2-3}/issueLink
Creates a link between two issues. Use this operation to indicate a relationship between two issues and optionally add a comment to the from (outward) issue, the method returns the following information:
If the link request duplicates a link, the response indicates that the issue link was created. If the request included a comment, the comment is added.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
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 for the package v3 ---> ADF Format sample
/*
payloadADF := &models.LinkPayloadSchemeV3{
Comment: &models.CommentPayloadScheme{
Body: &models.CommentNodeScheme{
Version: 1,
Type: "doc",
Content: []*models.CommentNodeScheme{
{
Type: "paragraph",
Content: []*models.CommentNodeScheme{
{
Type: "text",
Text: "Carlos Test",
},
{
Type: "emoji",
Attrs: map[string]interface{}{
"shortName": ":grin",
"id": "1f601",
"text": "😁",
},
},
{
Type: "text",
Text: " ",
},
},
},
},
},
},
InwardIssue: &models.LinkedIssueScheme{
Key: "KP-1",
},
OutwardIssue: &models.LinkedIssueScheme{
Key: "KP-2",
},
Type: &models.LinkTypeScheme{
Name: "Duplicate",
},
}
*/
payload := &models.LinkPayloadSchemeV2{
Comment: &models.CommentPayloadSchemeV2{
Body: "test",
},
InwardIssue: &models.LinkedIssueScheme{
Key: "KP-1",
},
OutwardIssue: &models.LinkedIssueScheme{
Key: "KP-2",
},
Type: &models.LinkTypeScheme{
Name: "Duplicate",
},
}
response, err := atlassian.Issue.Link.Create(context.Background(), payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
GET /rest/api/{2-3}/issue?fields=issuelinks
Return the issue links associated with a Jira Issue, the method returns the following information:
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
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)
issueLinks, response, err := atlassian.Issue.Link.Gets(context.Background(), "KP-1")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, link := range issueLinks.Fields.IssueLinks {
log.Println(link)
}
}
GET /rest/api/{2-3}/issueLink/{linkId}
Returns an issue link, the method returns the following information:
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
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)
issueLink, response, err := atlassian.Issue.Link.Get(context.Background(), "10002")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(issueLink.ID)
log.Println("----------------")
log.Println(issueLink.Type.Name)
log.Println(issueLink.Type.ID)
log.Println(issueLink.Type.Self)
log.Println(issueLink.Type.Inward)
log.Println(issueLink.Type.Outward)
log.Println("----------------")
log.Println(issueLink.InwardIssue)
log.Println(issueLink.OutwardIssue)
}
DELETE /rest/api/{2-3}/issueLink/{linkId}
Deletes an issue link, the method returns the following information:
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
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.Issue.Link.Delete(context.Background(), "10002")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
This resource represents issue field configurations. Use it to get, set, and delete field configurations and field configuration schemes.
The Jira Issue Field Configurations define the behavior of fields within Jira issues. A field configuration is a set of rules that determines which fields are available for a particular issue type or project, and whether those fields are required, read-only, or hidden. Field configurations can be customized to meet the specific needs of your organization.
GET /rest/api/{2-3}/fieldconfiguration
Returns a paginated list of field configurations. The list can be for all field configurations or a subset determined by any combination of these criteria:
a list of field configuration item IDs.
whether the field configuration is a default.
whether the field configuration name or description contains a query string.
This method uses the following parameters:
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
fieldConfigurations, response, err := atlassian.Issue.Field.Configuration.Gets(
context.Background(),
nil,
false,
0,
50,
)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, configuration := range fieldConfigurations.Values {
log.Println(configuration)
}
}
POST /rest/api/{2-3}/fieldconfiguration
Creates a field configuration. The field configuration is created with the same field properties as the default configuration, with all the fields being optional.
This method uses the following parameters:
package main
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
newFieldConfiguration, response, err := atlassian.Issue.Field.Configuration.Create(
context.Background(),
"Story DUMMY Field Configuration",
"description sample")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
fmt.Println(newFieldConfiguration.ID)
fmt.Println(newFieldConfiguration.Name)
fmt.Println(newFieldConfiguration.Description)
fmt.Println(newFieldConfiguration.IsDefault)
}
PUT /rest/api/{2-3}/fieldconfiguration/{id}
Updates a field configuration. The name and the description provided in the request override the existing values.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Issue.Field.Configuration.Update(context.Background(), 10002, "name updated", "")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
DELETE /rest/api/{2-3}/fieldconfiguration/{id}
Deletes a field configuration.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Issue.Field.Configuration.Delete(context.Background(), 10002)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
POST /rest/servicedeskapi/customer
This method adds a customer to the Jira Service Management instance by passing a JSON file including an email address and display name. The display name does not need to be unique. The record's identifiers, name
and key
, are automatically generated from the request details.
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 (
email = "[email protected]"
displayName = "Example Customer 1"
)
newCustomer, response, err := atlassian.Customer.Create(context.Background(), email, displayName)
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("The new customer has been created!!")
log.Println("-------------------------")
log.Println(newCustomer.Name)
log.Println(newCustomer.DisplayName)
log.Println(newCustomer.AccountID)
log.Println(newCustomer.EmailAddress)
log.Println(newCustomer.Links)
log.Println(newCustomer)
log.Println("-------------------------")
}
POST /rest/servicedeskapi/servicedesk/{serviceDeskId}/customer
Adds one or more customers to a service desk. If any of the passed customers are associated with the service desk, no changes will be made for those customers 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 (
accountIDs = []string{"qm:7ee1b8dc-1ce3-467b-94cd-9bb2dcf083e2:3f06c44b-36e8-4394-9ff3-d679f854477c"}
)
response, err := atlassian.Customer.Add(context.Background(), 1, accountIDs)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", string(response.Bytes.String()))
}
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}
GET /rest/servicedeskapi/servicedesk/{serviceDeskId}/customer
This method returns a list of the customers on 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")
atlassian.Auth.SetExperimentalFlag()
var (
serviceDeskID = 1
query = ""
start = 0
limit = 50
)
customers, response, err := atlassian.Customer.Gets(context.Background(), serviceDeskID, query, start, limit)
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 _, customer := range customers.Values {
log.Println(customer)
}
}
DELETE /rest/servicedeskapi/servicedesk/{serviceDeskId}/customer
This method removes one or more customers from a service desk. The service desk must have closed access. If any of the passed customers are not associated with the service desk, no changes will be made for those customers 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")
atlassian.Auth.SetExperimentalFlag()
var (
accountIDs = []string{"qm:7ee1b8dc-1ce3-467b-94cd-9bb2dcf083e2:3f06c44b-36e8-4394-9ff3-d679f854477c"}
)
response, err := atlassian.Customer.Remove(context.Background(), 1, accountIDs)
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)
}
An issue's priority defines its importance in relation to other issues, so it helps your users determine which issues should be tackled first. Jira comes with a set of default priorities, which you can modify or add to. You can also choose different priorities for your projects.
GET /rest/api/{2-3}/priority
Returns the list of all issue priorities, the method returns the following information:
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
priorities, response, err := atlassian.Issue.Priority.Gets(context.Background())
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for pos, priority := range priorities {
log.Println(pos, priority)
}
}
GET /rest/api/{2-3}/priority/{id}
Returns an issue priority, the method returns the following information:
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var priorityID = "1"
priority, response, err := atlassian.Issue.Priority.Get(context.Background(), priorityID)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(priority)
}
POST /rest/api/3/priority
Creates an issue priority.
No implemented, yet. Feel free to open a new PR or issue
PUT /rest/api/3/priority/default
Sets default issue priority.
No implemented, yet. Feel free to open a new PR or issue
PUT /rest/api/3/priority/move
Changes the order of issue priorities.
No implemented, yet. Feel free to open a new PR or issue
GET /rest/api/3/priority/search
Returns a paginated list of priorities. The list can contain all priorities or a subset determined by any combination of these criteria:
a list of priority IDs. Any invalid priority IDs are ignored.
whether the field configuration is a default. This returns priorities from company-managed (classic) projects only, as there is no concept of default priorities in team-managed projects.
No implemented, yet. Feel free to open a new PR or issue
PUT /rest/api/3/priority/{id}
Updates an issue priority.
No implemented, yet. Feel free to open a new PR or issue
DELETE /rest/api/3/priority/{id}
Deletes an issue priority.
No implemented, yet. Feel free to open a new PR or issue
GET /rest/api/{2-3}/project/{projectIdOrKey}/role
Returns a list of for the project returning the name and self URL for each role.
GET /rest/api/{2-3}/project/{projectIdOrKey}/role/{id}
Returns a project role's details and actors associated with the project. The list of actors is sorted by display name.
GET /rest/api/{2-3}/project/{projectIdOrKey}/roledetails
Returns all and the details for each role. Note that the list of project roles is common to all projects.
GET /rest/api/{2-3}/role
Gets a list of all project roles, complete with project role details and default actors.
POST /rest/api/{2-3}/role
Creates a new project role with no .
In this article, I would be showing you how to edit a Jira issue using the "go-atlassian" library.
Create a new directory for your project.
Open a terminal and navigate to the project directory.
Initialize a new Go module using the following command:
In the terminal, run the following command to install the "go-atlassian" library:
Create a new Go file (e.g., main.go
) in your project directory.
Open the file and import the required packages:
You can use the V2 and V3 Jira endpoint versions.
In the main
function, create a new Jira client and authenticate using your Jira URL, username, and API token:
You do not need to send all the fields inside "fields". You can just send the fields you want to update. Absent fields are left unchanged and some fields cannot be updated this way (for example, comments). Instead you must use explicit-verb updates.
For system-fields, you can use the &models.IssueSchemeV2 struct, something like this:
For custom-fields, you can use the &models.CustomFields struct to inyect the customfield's by type, something like this:
Finally, call the Issue.Update() method and update the issue
Save the main.go
file.
In the terminal, navigate to your project directory.
Execute the following command to run the program:
startAt
The index of the first item to return in a page of results (page offset).
maxResults
The maximum number of items to return per page.
id's
The list of field configuration IDs.
isDefault
If true returns default field configurations only.
query
The query string used to match against field configuration names and descriptions.
description
The description of the field configuration.
name
The name of the field configuration. Must be unique.
go mod init <module-name>
go get -v github.com/ctreminiom/go-atlassian
package main
import (
"fmt"
"log"
"os"
jira "github.com/ctreminiom/go-atlassian/jira/v2"
)
func main() {
jiraHost := "https://<_jira_instance_>.atlassian.net"
mailAddress := "<your_mail>"
apiToken := "<your_api_token>"
client, err := jira.New(nil, jiraHost)
if err != nil {
log.Fatal(err)
}
client.Auth.SetBasicAuth(mailAddress, apiToken)
}
var payload = models.IssueSchemeV2{
Fields: &models.IssueFieldsSchemeV2{
Summary: "New summary test",
Priority: &models.PriorityScheme{Name: "Minor"},
},
}
var customFields = models.CustomFields{}
err = customFields.Groups("customfield_10052", []string{"jira-administrators", "jira-administrators-system"})
if err != nil {
log.Fatal(err)
}
err = customFields.Number("customfield_10043", 9000)
if err != nil {
log.Fatal(err)
}
_, err = atlassian.Issue.Update(context.Background(), "KP-2", false, &payload, &customFields, nil)
if err != nil {
log.Fatal(err)
}
go run main.go
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
roles, response, err := atlassian.Project.Role.Gets(context.Background(), "KP")
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
for key, value := range *roles {
log.Println(key, value)
}
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
role, response, err := atlassian.Project.Role.Get(context.Background(), "KP", 10005)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(role.ID)
log.Println(role.Name)
log.Println(role.Description)
log.Println(role.Self)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
rolesDetails, response, err := atlassian.Project.Role.Details(context.Background(), "KP")
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, role := range rolesDetails {
log.Println(role.Name)
log.Println(role.ID)
log.Println(role.Admin)
log.Println(role.TranslatedName)
}
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
roles, response, err := atlassian.Project.Role.Global(context.Background())
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, role := range roles {
log.Println(role)
}
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
var payload = &models.ProjectRolePayloadScheme{
Name: "Developers",
Description: "A project role that represents developers in a project",
}
newRole, response, err := atlassian.Project.Role.Create(context.Background(), payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(newRole)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
task, response, err := atlassian.Task.Get(context.Background(), "1000")
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(task)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.Task.Cancel(context.Background(), "1000")
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}
In this article, I would be showing you how to create Jira workflow and append transitions using go-atlassian
Create a new directory for your project and navigate to it in your terminal or command prompt. Initialize a new Go module using the following command:
go mod init your-module-name
To use the "go-atlassian" library, you need to install it as a dependency in your project. Run the following command:
go get github.com/ctreminiom/go-atlassian
Create a new Go file, e.g., main.go
, and import the necessary packages:
package main
import (
"fmt"
"log"
jira "github.com/ctreminiom/go-atlassian/jira/v2"
)
Initialize the Jira API client with your Jira base URL and API token:
func main() {
jiraClient, err := jira.New(nil, "https://your-jira-instance.atlassian.net")
if err != nil {
log.Fatal(err)
}
// Set API token for authentication
jiraClient.Auth.SetBasicAuth(mail, token)
}
To create a new workflow, we need to the create the models.WorkflowPayloadScheme
payload struct with the following information.
Worfklow Name.
Workflow Description.
Workflow Statuses.
Workflow Transitions.
Let's try to create a workflow with directed transitions and all-to-all transitions, something like this:
The first step to create a Jira workflow is recognize what's gonna be the statuses you want to use.
In this particular example, we're needed to use the following statuses:
Open
In Progress
QA
Waiting for approval
Escalated
Closed
Resolved
var statusesNamesAsSlice = []string{
"Open", "In Progress", "QA",
"Waiting for approval", "Escalated",
"Closed", "Resolved",
}
var statusesAsMap = make(map[string]*models.WorkflowStatusDetailScheme)
for _, statusName := range statusesNamesAsSlice {
options := &models.WorkflowStatusSearchParams{
SearchString: statusName,
}
page, response, err := instance.Workflow.Status.Search(context.Background(), options, 0, 1)
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
var wasFound bool
for _, status := range page.Values {
if status.Name == statusName {
statusesAsMap[status.Name] = status
wasFound = true
break
}
}
if !wasFound {
// If the workflow is not found, it's required to create a new global status
statusPayload := &models.WorkflowStatusPayloadScheme{
Statuses: []*models.WorkflowStatusNodeScheme{
{
Name: statusName,
StatusCategory: "IN_PROGRESS",
},
},
Scope: &models.WorkflowStatusScopeScheme{
Type: "GLOBAL",
},
}
statuses, response, err := instance.Workflow.Status.Create(context.Background(), statusPayload)
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
for _, status := range statuses {
if status.Name == statusName {
statusesAsMap[status.Name] = status
break
}
}
}
}
for name, data := range statusesAsMap {
fmt.Println(name, data.ID)
}
The previously code extracts the status ID's from the Jira instance and if one status is not available on the instance, it'll automatically create the statuses and append the information on the statusesAsMap
variable.
With the status ID's, we can proceed with the creation of the workflow statuses payload
var workflowStatuses []*models.WorkflowTransitionScreenScheme
for _, status := range statusesAsMap {
workflowStatuses = append(workflowStatuses, &models.WorkflowTransitionScreenScheme{
ID: status.ID,
Properties: nil,
})
}
With the statuses id's extracted, we can create a workflow transitions. The transitions define the paths that an issue can take from one status to another.
For example: an issue in the "Open" status can transition to the "In Progress" status when work begins on it.
There're the conditional validations needed to create a valid workflow transition:
include one initial transition.
not use the same name for a global and directed transition.
have a unique name for each global transition.
have a unique 'to' status for each global transition.
have unique names for each transition from a status.
not have a 'from' status on initial and global transitions.
have a 'from' status on directed transitions.
var workflowTransitions []*models.WorkflowTransitionPayloadScheme
// -----
// The initial transition is required, it creates the relationship between the creation trigger with the
// first status
// -----
workflowTransitions = append(workflowTransitions, &models.WorkflowTransitionPayloadScheme{
Name: "Create",
To: "1",
Type: "initial",
})
// -----
// Create the Escalated and Waiting for approval statuses because the relationship is all-to-all
workflowTransitions = append(workflowTransitions, &models.WorkflowTransitionPayloadScheme{
Name: "Escalated",
To: statusesAsMap["Escalated"].ID,
Type: "global",
})
workflowTransitions = append(workflowTransitions, &models.WorkflowTransitionPayloadScheme{
Name: "Waiting for approval",
To: statusesAsMap["Waiting for approval"].ID,
Type: "global",
})
// -----
// ----
// Create the directed transitions, it's required to use the from and to statuses
// Open -----------------------> In Progress
workflowTransitions = append(workflowTransitions, &models.WorkflowTransitionPayloadScheme{
Name: "In Progress",
From: []string{statusesAsMap["Open"].ID},
To: statusesAsMap["In Progress"].ID,
Type: "directed",
})
// In Progress -----------------------> QA
workflowTransitions = append(workflowTransitions, &models.WorkflowTransitionPayloadScheme{
Name: "QA",
From: []string{statusesAsMap["In Progress"].ID},
To: statusesAsMap["QA"].ID,
Type: "directed",
})
// QA -----------------------> In Progress
workflowTransitions = append(workflowTransitions, &models.WorkflowTransitionPayloadScheme{
Name: "QA",
From: []string{statusesAsMap["QA"].ID},
To: statusesAsMap["In Progress"].ID,
Type: "directed",
})
// QA -----------------------> Closed
workflowTransitions = append(workflowTransitions, &models.WorkflowTransitionPayloadScheme{
Name: "Closed",
From: []string{statusesAsMap["QA"].ID},
To: statusesAsMap["Closed"].ID,
Type: "directed",
})
// QA -----------------------> Resolved
workflowTransitions = append(workflowTransitions, &models.WorkflowTransitionPayloadScheme{
Name: "Resolved",
From: []string{statusesAsMap["QA"].ID},
To: statusesAsMap["Resolved"].ID,
Type: "directed",
})
In conclusion, we can combine the statuses and transitions structs and create the workflow using the structs created on the previous steps.
workflowPayload := &models.WorkflowPayloadScheme{
Name: "Workflow Name - Sample",
Description: "Workflow Name - Description",
Statuses: workflowStatuses,
Transitions: workflowTransitions,
}
newWorkflow, response, err := instance.Workflow.Create(context.Background(), workflowPayload)
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
log.Println(newWorkflow.Name)
log.Println(newWorkflow.EntityID)
GET /rest/api/{2-3}/attachment/meta
Returns the attachment settings, that is, whether attachments are enabled and the maximum attachment size allowed, the method returns the following information:
GET /rest/api/{2-3}/attachment/{id}
Returns the metadata for an attachment. Note that the attachment itself is not returned, the method returns the following information:
GET /rest/api/{2-3}/attachment/{id}/expand/human
This is an experimental endpoint
Returns the metadata for the contents of an attachment, if it is an archive, and metadata for the attachment itself.
For example, if the attachment is a ZIP archive, then information about the files in the archive is returned and metadata for the ZIP archive. Currently, only the ZIP archive format is supported, the method returns the following information:
DELETE /rest/api/{2-3}/attachment/{id}
Deletes an attachment from an issue, the method returns the following information:
POST /rest/api/{2-3}/issue/{issueIdOrKey}/attachments
Adds one or more attachments to an issue. Attachments are posted as multipart/form-data ().
The request must have a X-Atlassian-Token: no-check
header, if not it is blocked. See for more information.
The name of the multipart/form-data parameter that contains the attachments must be file
.
It only accepts one attachment at once
GET /rest/api/{2-3}/attachment/content/{id}
This endpoint returns the contents of an attachment. A Range
header can be set to define a range of bytes within the attachment to download.
If successful, Jira will return a response with the attachment file. You can save the file to your local filesystem or process it in your application as needed.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
settings, response, err := atlassian.Issue.Attachment.Settings(context.Background())
if err != nil {
log.Fatal(err)
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println("settings", settings.Enabled, settings.UploadLimit)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/davecgh/go-spew/spew"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
metadata, response, err := atlassian.Issue.Attachment.Metadata(context.Background(), "10016")
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
spew.Dump(metadata)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/davecgh/go-spew/spew"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
humanMetadata, response, err := atlassian.Issue.Attachment.Human(context.Background(), "10016")
if err != nil {
log.Fatal(err)
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
spew.Dump(humanMetadata)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Issue.Attachment.Delete(context.Background(), "attachmentID")
if err != nil {
log.Fatal(err)
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
"path/filepath"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
absolutePath, err := filepath.Abs("jira/mocks/image.png")
if err != nil {
log.Fatal(err)
}
log.Println("Using the path", absolutePath)
reader, err := os.Open(absolutePath)
if err != nil {
log.Fatal(err)
}
defer reader.Close()
var (
issueKeyOrID = "KP-2"
fileName = "image-mock-00.png"
)
attachments, response, err := atlassian.Issue.Attachment.Add(context.Background(), issueKeyOrID, fileName, reader)
if err != nil {
log.Fatal(err)
return
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("We've found %v attachments", len(attachments))
for _, attachment := range attachments {
log.Println(attachment.ID, attachment.Filename)
}
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
attachmentMetadata, response, err := atlassian.Issue.Attachment.Metadata(context.Background(), "10016")
if err != nil {
log.Fatal(err)
}
response, err = atlassian.Issue.Attachment.Download(context.Background(), "10016", false)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
if err := os.WriteFile(attachmentMetadata.Filename, response.Bytes.Bytes(), 0666); err != nil {
log.Fatal(err)
}
}
This resource represents project components. Uses to get, create, update, and delete project components. Also get components for project and get a count of issues by component.
POST /rest/api/{2-3}/component
Creates a component. Use components to provide containers for issues within a project.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.ComponentPayloadScheme{
IsAssigneeTypeValid: false,
Name: "Component 2",
Description: "This is a Jira component",
Project: "KP",
AssigneeType: "PROJECT_LEAD",
LeadAccountID: "5b86be50b8e3cb5895860d6d",
}
newComponent, response, err := atlassian.Project.Component.Create(context.Background(), payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("The new component has been created with the ID %v", newComponent.ID)
}
GET /rest/api/{2-3}/component/{id}
Returns a component.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
component, response, err := atlassian.Project.Component.Get(context.Background(), "10006")
if err != nil {
log.Fatal(err)
}
log.Println(component)
log.Println(response.Endpoint)
}
PUT /rest/api/{2-3}/component/{id}
Updates a component. Any fields included in the request are overwritten. If leadAccountId
is an empty string ("") the component lead is removed.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.ComponentPayloadScheme{
IsAssigneeTypeValid: false,
Name: "Component 1 - UPDATED",
Description: "This is a Jira component - UPDATED",
}
componentUpdated, response, err := atlassian.Project.Component.Update(context.Background(), "10006", payload)
if err != nil {
log.Fatal(err)
}
log.Println(response.Endpoint)
log.Println(componentUpdated)
}
DELETE /rest/api/{2-3}/component/{id}
Deletes a component.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.Project.Component.Delete(context.Background(), "10006")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
GET /rest/api/{2-3}/component/{id}/relatedIssueCounts
Returns the counts of issues assigned to the component.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
count, response, err := atlassian.Project.Component.Count(context.Background(), "10005")
if err != nil {
log.Fatal(err)
}
log.Println(count)
log.Println(response.Endpoint)
}
GET /rest/api/{2-3}/project/{projectIdOrKey}/components
Returns all components in a project.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 projectKey = "KP"
components, response, err := atlassian.Project.Component.Gets(context.Background(), projectKey)
if err != nil {
log.Fatal(err)
}
log.Println(response.Endpoint)
for _, component := range components {
log.Println(component)
}
}
GET /rest/api/{2-3}/user
Returns a user.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
}
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/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 /rest/api/{2-3}/user
Deletes a user.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
}
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/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 /rest/api/{2-3}/user/groups
Returns the groups to which a user belongs.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 /rest/api/{2-3}/users/search
Returns a list of all (active and inactive) users.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
}
}
This resource represents options for sharing filters. Use it to get share scopes as well as add and remove share scopes from filters.
GET /rest/api/3/filter/defaultShareScope
Returns the default sharing settings for new filters and dashboards for a user, the method returns the following information:
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
scope, response, err := atlassian.Filter.Share.Scope(context.Background())
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
return
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println("Scope", scope)
}
PUT /rest/api/3/filter/defaultShareScope
Returns the share permissions for a filter. A filter can be shared with groups, projects, all logged-in users, or the public. Sharing with all logged-in users or the public is known as global share permission, the method returns the following information:
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
permissions, response, err := atlassian.Filter.Share.Gets(context.Background(), 1)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for index, permission := range permissions {
log.Println(index, permission.Type, permission.Type)
}
}
POST /rest/api/3/filter/{id}/permission
Add a share permissions to a filter. If you add global share permission (one for all logged-in users or the public) it will overwrite all share permissions for the filter, the method returns the following information:
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() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
/*
We can add different share permissions, for example:
---- Project ID only
payload := jira.PermissionFilterBodyScheme{
Type: "project",
ProjectID: "10000",
}
---- Project ID and role ID
payload := jira.PermissionFilterBodyScheme{
Type: "project",
ProjectID: "10000",
ProjectRoleID: "222222",
}
==== Group Name
payload := jira.PermissionFilterBodyScheme{
Type: "group",
GroupName: "jira-users",
}
*/
payload := models.PermissionFilterPayloadScheme{
Type: "project",
ProjectID: "10000",
}
permissions, response, err := atlassian.Filter.Share.Add(context.Background(), 1001, &payload)
if err != nil {
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for index, permission := range permissions {
log.Println(index, permission.ID, permission.Type)
}
}
GET /rest/api/3/filter/{id}/permission
Returns share permission for a filter. A filter can be shared with groups, projects, all logged-in users, or the public.
Sharing with all logged-in users or the public is known as global share permission, the method returns the following information:
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/jira/v3"
"github.com/ctreminiom/go-atlassian/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
permission, response, err := atlassian.Filter.Share.Get(context.Background(), 10001, 100012)
if err != nil {
log.Fatal(err)
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(permission)
}
DELETE /rest/api/3/filter/{id}/permission/{permissionId}
Deletes share permission from a filter.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/jira/v3"
"github.com/ctreminiom/go-atlassian/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Filter.Share.Delete(context.Background(), 11111, 11111)
if err != nil {
log.Fatal(err)
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
PUT /rest/api/3/filter/defaultShareScope
Sets the default sharing for new filters and dashboards for a user.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/jira/v3"
"github.com/ctreminiom/go-atlassian/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Filter.Share.SetScope(context.Background(), "GLOBAL")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
In this article, I would be showing you how to add custom-fields on a Jira project screens using go-atlassian.
Before we get started, let's first understand the Jira entities involved in this process: screens, screen tabs, and screen tab fields.
Screens:
Screens in Jira define the layout and configuration of different views, such as issue creation, editing, and viewing.
Each screen consists of one or more screen tabs.
Screen Tabs:
Screen tabs are sections within a screen that group related fields together.
A screen can have multiple screen tabs, and each tab can contain multiple fields.
Screen Tab Fields:
Screen tab fields are the individual fields (e.g., standard or custom fields) displayed within a screen tab.
Create a new directory for your project and navigate to it in your terminal or command prompt. Initialize a new Go module using the following command:
go mod init your-module-name
To use the "go-atlassian" library, you need to install it as a dependency in your project. Run the following command:
go get github.com/ctreminiom/go-atlassian
Create a new Go file, e.g., main.go
, and import the necessary packages:
package main
import (
"fmt"
"log"
jira "github.com/ctreminiom/go-atlassian/jira/v2"
)
Initialize the Jira API client with your Jira base URL and API token:
func main() {
client, err := jira.New(nil, "https://your-jira-instance.atlassian.net")
if err != nil {
log.Fatal(err)
}
// Set API token for authentication
client.Auth.SetBasicAuth(mail, token)
}
Before to add the customfields on the project screens, we need to search the issue type screen scheme associated with a Jira project, then iterates the mapping to extract the screen schemes linked. In this particular example, we're going to add the following customfields on the KP project:
Start Date customfield_10068
Sprint customfield_10020
DueDate duedate
timeTracking timetracking
Environment customfield_10069
Category customfield_10070
Testing By customfield_10071
Use the following code to extract the issue type screen scheme linked to the KP project.
var projectKey = "KP"
// --------------------------------------------------
// Extract the project ID using the Project.Get() method
// --------------------------------------------------
project, response, err := client.Project.Get(context.Background(), projectKey, nil)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("Status HTTP Response", response.Status)
}
log.Fatal(err)
}
// --------------------------------------------------
// Transform the project id string to integer
// --------------------------------------------------
projectIDAsInt, err := strconv.Atoi(project.ID)
if err != nil {
log.Fatal(err)
}
// --------------------------------------------------
// Extract the issue type screen scheme linked to the project selected
// --------------------------------------------------
projectMapping, response, err := client.Issue.Type.ScreenScheme.Projects(context.Background(), []int{projectIDAsInt}, 0, 50)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("Status HTTP Response", response.Status)
}
log.Fatal(err)
}
// --------------------------------------------------
// Iterates the struts and extract the issue type screen scheme id
// --------------------------------------------------
var issueTypeScreenSchemeID string
for _, scheme := range projectMapping.Values {
for _, projectID := range scheme.ProjectIds {
if project.ID == projectID {
issueTypeScreenSchemeID = projectID
}
}
}
With the Issue Type Screen Scheme ID extracted from the previous step, we can proceed with the screen scheme extraction, use the following code to extract the screen schemes
// --------------------------------------------------
// Transform the project id string to integer
// --------------------------------------------------
issueTypeScreenSchemeIDAsInt, err := strconv.Atoi(issueTypeScreenSchemeID)
if err != nil {
log.Fatal(err)
}
// --------------------------------------------------
// Extract the screen schemes linked to the issue type screen schemes
// --------------------------------------------------
schemeMapping, response, err := client.Issue.Type.ScreenScheme.Mapping(
context.Background(),
[]int{issueTypeScreenSchemeIDAsInt},
0,
50)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("Status HTTP Response", response.Status)
}
log.Fatal(err)
}
// --------------------------------------------------
// Iterates the struts and extract the screen schemes ID as integers
// --------------------------------------------------
var screenSchemesIDs []int
for _, scheme := range schemeMapping.Values {
screenSchemeIDAsInt, err := strconv.Atoi(scheme.ScreenSchemeID)
if err != nil {
log.Fatal(err)
}
screenSchemesIDs = append(screenSchemesIDs, screenSchemeIDAsInt)
}
The next step is extract the screen ID's from the screen schemes, you can use this code to extract the screen IDs.
// --------------------------------------------------
// Extract the screens from the screen schemes IDs
// --------------------------------------------------
options := &models.ScreenSchemeParamsScheme{IDs: screenSchemesIDs}
screenSchemes, response, err := client.Screen.Scheme.Gets(context.Background(), options, 0, 50)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("Status HTTP Response", response.Status)
}
log.Fatal(err)
}
// --------------------------------------------------
// Iterates the struts and screen IDs
// --------------------------------------------------
var screenIDs []int
for _, screenScheme := range screenSchemes.Values {
if screenScheme.Screens != nil {
screenIDs = append(screenIDs, screenScheme.Screens.Default)
screenIDs = append(screenIDs, screenScheme.Screens.Create)
screenIDs = append(screenIDs, screenScheme.Screens.Edit)
screenIDs = append(screenIDs, screenScheme.Screens.View)
}
}
// --------------------------------------------------
// Remove the duplicated values from the screenIDs slice
// I used the function "removeDuplicateInt" from the Stackoverflow question
// https://stackoverflow.com/questions/66643946/how-to-remove-duplicates-strings-or-int-from-slice-in-go
// --------------------------------------------------
screenIDsWithOutDuplicated := removeDuplicateInt(screenIDs)
The final step is add the custom-fields on the screen default tabs, it's required to validate if the customfield is already added on the screen tab, if not, add the custom-field on the screen and log the result.
We can use the following code below:
var customFieldsIDs = []string{
"customfield_10068",
"customfield_10020",
"duedate",
"timetracking",
"customfield_10069",
"customfield_10070",
"customfield_10071",
}
// --------------------------------------------------
// Process each screen and do the following validations/logic
// 1. Extract the screen default tab
// 2. Using the default screen tab, extract the customfields stored on it
// 3. Check if the customfield is already added on the screen tab
// 4. If so, skip it
// 5. If not, append the customfield on the screen tab
// --------------------------------------------------
for _, screenID := range screenIDsWithOutDuplicated {
// --------------------------------------------------
// If you want to process the default screen, you can comment this if statement
// --------------------------------------------------
if screenID == 0 {
continue
}
tabs, response, err := client.Screen.Tab.Gets(context.Background(), screenID, projectKey)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("Status HTTP Response", response.Status)
}
log.Fatal(err)
}
defaultTab := tabs[0].ID
fields, response, err := client.Screen.Tab.Field.Gets(context.Background(), screenID, defaultTab)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("Status HTTP Response", response.Status)
}
log.Fatal(err)
}
// --------------------------------------------------
// Iterate the fields slice and stores the fields already added on the screen tab
// --------------------------------------------------
var fieldsAlreadyAdded []string
for _, field := range fields {
fieldsAlreadyAdded = append(fieldsAlreadyAdded, field.ID)
}
// --------------------------------------------------
// Check if the customfield requested is already added on the screen tab
// --------------------------------------------------
var fieldsAvailableToAdd []string
for _, customFieldID := range customFieldsIDs {
var isTaken bool
for _, fieldsAdded := range fieldsAlreadyAdded {
if customFieldID == fieldsAdded {
isTaken = true
break
}
}
if !isTaken {
fieldsAvailableToAdd = append(fieldsAvailableToAdd, customFieldID)
}
}
// --------------------------------------------------
// For each customfield filtered, add the field on the screen tab
// --------------------------------------------------
for _, fieldID := range fieldsAvailableToAdd {
_, response, err = client.Screen.Tab.Field.Add(context.Background(), screenID, defaultTab, fieldID)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
log.Println("Status HTTP Response", response.Status)
}
log.Fatal(err)
}
log.Println("The field", fieldID, "has been added on the screen ", screenID)
}
When you run the code, the custom-fields selected will be available on the project 👍🎉.
This resource represents issues types
Just as a project can have many different types of work, Jira uses different issue types to help identify, categorize, and report on your team’s work. We’ll cover Jira’s standard-issue types below.
GET /rest/api/{2-3}/issuetype
Returns all issue types.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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)
types, response, err := atlassian.Issue.Type.Gets(context.Background())
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, value := range types {
log.Println(value.ID, value.Name, value.Subtask, value.Scope)
}
}
POST /rest/api/{2-3}/issuetype
Creates an issue type and adds it to the default issue type scheme.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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)
issueTypePayload := models.IssueTypePayloadScheme{
Name: "Risk",
Description: "this is the issue type description",
Type: "standard",
}
issueType, response, err := atlassian.Issue.Type.Create(context.Background(), &issueTypePayload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(issueType.Name)
}
GET /rest/api/{2-3}/issuetype/{id}
Returns an issue type.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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)
issueType, response, err := atlassian.Issue.Type.Get(context.Background(), "10000")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(issueType.Name)
}
PUT /rest/api/{2-3}/issuetype/{id}
Updates the issue type.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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)
issueTypePayload := models.IssueTypePayloadScheme{
Name: "Risk UPDATED",
Description: "this is the issue type description, UPDATED",
}
issueType, response, err := atlassian.Issue.Type.Update(context.Background(), "id", &issueTypePayload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(issueType.Name)
}
DELETE /rest/api/{2-3}/issuetype/{id}
Deletes the issue type. If the issue type is in use, all uses are updated with the alternative issue type (alternativeIssueTypeId
).
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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.Issue.Type.Delete(context.Background(), "id")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
GET /rest/api/{2-3}/issuetype/{id}/alternatives
Returns a list of issue types that can be used to replace the issue type.
The alternative issue types are those assigned to the same workflow scheme, field configuration scheme, and screen scheme.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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)
issueTypes, response, err := atlassian.Issue.Type.Alternatives(context.Background(), "")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, issueType := range issueTypes {
log.Println(issueType)
}
}
In this article, I would be showing you how to create a Service Management customer request with custom-fields.
Create a new directory for your project.
Open a terminal and navigate to the project directory.
Initialize a new Go module using the following command:
go mod init <module-name>
In the terminal, run the following command to install the "go-atlassian" library:
go get -v github.com/ctreminiom/go-atlassian
Create a new Go file (e.g., main.go
) in your project directory.
Open the file and import the required packages:
package main
import (
"fmt"
"github.com/ctreminiom/go-atlassian/jira/sm"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
)
In the main
function, create a new Jira client and authenticate using your Jira URL, username, and API token:
func main() {
jiraHost := "https://<_jira_instance_>.atlassian.net"
mailAddress := "<your_mail>"
apiToken := "<your_api_token>"
client, err := sm.New(nil, jiraHost)
if err != nil {
log.Fatal(err)
}
client.Auth.SetBasicAuth(mailAddress, apiToken)
}
Define the fields you want to set:
payload := &models.CreateCustomerRequestPayloadScheme{
Channel: "",
Form: nil,
IsAdfRequest: false,
RaiseOnBehalfOf: "",
RequestFieldValues: nil,
RequestParticipants: nil,
RequestTypeID: "10",
ServiceDeskID: "1",
}
if err := payload.AddCustomField("summary", "Summary Sample"); err != nil {
log.Fatal(err)
}
if err := payload.DateCustomField("duedate", time.Now()); err != nil {
log.Fatal(err)
}
if err := payload.Components([]string{"Intranet"}); err != nil {
log.Fatal(err)
}
if err := payload.AddCustomField("labels", []string{"label-00", "label-01"}); err != nil {
log.Fatal(err)
}
Create a new issue using the Create
method and set the custom fields:
ticket, response, err := atlassian.Request.Create(context.Background(), payload, form)
if err != nil {
log.Fatal(err)
}
Save the main.go
file.
In the terminal, navigate to your project directory.
Execute the following command to run the program:
go run main.go
This will create a new ITSM customer request in Jira with the specified custom field values.
This resource represents remote issue links, a way of linking Jira to information in other systems. Use it to get, create, update, and delete remote issue links either by ID or global ID. The global ID provides a way of accessing remote issue links using information about the item's remote system host and remote system identifier.
GET /rest/api/{2-3}/issue/{issueIdOrKey}/remotelink
Gets returns the remote issue links for an issue. When a remote issue link global ID is provided the record with that global ID is returned, otherwise all remote issue links are returned.
POST /rest/api/{2-3}/issue/{issueIdOrKey}/remotelink
Create creates or updates a remote issue link for an issue.
If a globalId
is provided and a remote issue link with that global ID is found it is updated. Any fields without values in the request are set to null. Otherwise, the remote issue link is created.
DELETE /rest/api/{2-3}/issue/{issueIdOrKey}/remotelink/{linkId}
Delete deletes a remote issue link from an issue.
GET /rest/api/{2-3}/issue/{issueIdOrKey}/remotelink/{linkId}
Get returns a remote issue link for an issue.
PUT /rest/api/{2-3}/issue/{issueIdOrKey}/remotelink/{linkId}
Update updates a remote issue link for an issue.
DELETE /rest/api/{2-3}/issue/{issueIdOrKey}/remotelink
DeleteByGlobalId deletes the remote issue link from the issue using the link's global ID where the global ID includes reserved URL characters these must be escaped in the request.
package main
import (
"context"
"fmt"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
remoteLinks, response, err := instance.Issue.Link.Remote.Gets(context.Background(), "KP-23", "")
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
}
log.Fatal(err)
}
for _, remoteLink := range remoteLinks {
fmt.Println(remoteLink.ID)
}
}
package main
import (
"context"
"fmt"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
payload := &models.RemoteLinkScheme{
Application: &models.RemoteLinkApplicationScheme{
Name: "My Acme Tracker",
Type: "com.acme.tracker",
},
GlobalID: "system=http://www.mycompany.com/support&id=1",
ID: 0,
Object: &models.RemoteLinkObjectScheme{
Icon: &models.RemoteLinkObjectLinkScheme{
Title: "Support Ticket",
URL16X16: "http://www.mycompany.com/support/ticket.png",
},
Status: &models.RemoteLinkObjectStatusScheme{
Icon: &models.RemoteLinkObjectLinkScheme{
Link: "http://www.mycompany.com/support?id=1&details=closed",
Title: "Case Closed",
URL16X16: "http://www.mycompany.com/support/resolved.png",
},
Resolved: true,
},
Summary: "Customer support issue",
Title: "TSTSUP-111",
URL: "http://www.mycompany.com/support?id=1",
},
Relationship: "causes",
}
remoteLink, response, err := instance.Issue.Link.Remote.Create(context.Background(), "KP-23", payload)
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
}
log.Fatal(err)
}
fmt.Print(remoteLink.Self, remoteLink.ID)
}
package main
import (
"context"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
response, err := instance.Issue.Link.Remote.DeleteById(context.Background(), "KP-23", "10001")
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
}
log.Fatal(err)
}
}
package main
import (
"context"
"fmt"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
remoteLink, response, err := instance.Issue.Link.Remote.Get(context.Background(), "KP-23", "10002")
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
}
log.Fatal(err)
}
fmt.Println(remoteLink.ID, remoteLink.GlobalID)
}
package main
import (
"context"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
payload := &models.RemoteLinkScheme{
Application: &models.RemoteLinkApplicationScheme{
Name: "My Acme Tracker",
Type: "com.acme.tracker",
},
GlobalID: "system=http://www.mycompany.com/support&id=1",
Object: &models.RemoteLinkObjectScheme{
Icon: &models.RemoteLinkObjectLinkScheme{
Title: "Support Ticket",
URL16X16: "http://www.mycompany.com/support/ticket.png",
},
Status: &models.RemoteLinkObjectStatusScheme{
Icon: &models.RemoteLinkObjectLinkScheme{
Link: "http://www.mycompany.com/support?id=1&details=closed",
Title: "Case Closed",
URL16X16: "http://www.mycompany.com/support/resolved.png",
},
Resolved: true,
},
Summary: "Customer support issue",
Title: "TSTSUP-111",
URL: "http://www.mycompany.com/support?id=1",
},
Relationship: "causes",
}
response, err := instance.Issue.Link.Remote.Update(context.Background(), "KP-23", "10001", payload)
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
}
log.Fatal(err)
}
}
package main
import (
"context"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
response, err := instance.Issue.Link.Remote.DeleteByGlobalId(context.Background(), "KP-23", "system=http://www.mycompany.com/support&id=1")
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
}
log.Fatal(err)
}
}
GET /rest/api/{2-3}/projectCategory
Returns all project categories.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
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)
categories, response, err := atlassian.Project.Category.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 _, category := range categories {
log.Println("----------------")
log.Println(category.Self)
log.Println(category.ID)
log.Println(category.Name)
log.Println(category.Description)
log.Println("----------------")
}
}
POST /rest/api/{2-3}/projectCategory
Creates a project category.
package main
import (
"context"
"fmt"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"math/rand"
"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 payload = &models.ProjectCategoryPayloadScheme{
Name: fmt.Sprintf("Category #%v", rand.Intn(100)),
Description: "description sample",
}
newCategory, response, err := atlassian.Project.Category.Create(context.Background(), payload)
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.Printf("The new category %v has been created with the ID %v", newCategory.Name, newCategory.ID)
}
GET /rest/api/{2-3}/projectCategory/{id}
Returns a project category.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
category, response, err := atlassian.Project.Category.Get(context.Background(), 10002)
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(category)
}
PUT /rest/api/{2-3}/projectCategory/{id}
Updates a project category.
package main
import (
"context"
"fmt"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"math/rand"
"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 (
projectCategoryID = 10000
payload = &models.ProjectCategoryPayloadScheme{
Name: fmt.Sprintf("Category #%v - updated", rand.Intn(100)),
}
)
categoryUpdated, response, err := atlassian.Project.Category.Update(context.Background(), projectCategoryID, payload)
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.Printf("The project category %v has been updated", categoryUpdated.ID)
}
DELETE /rest/api/{2-3}/projectCategory/{id}
Deletes a project category.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.Project.Category.Delete(context.Background(), 10002)
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("HTTP Endpoint Bytes", response.Bytes.String())
}
In Jira, a group is a collection of users who have similar roles, responsibilities, or permissions. Groups can be used to simplify user management by allowing you to grant permissions and roles to entire groups of users rather than individual users.
Here are some ways you can use groups in Jira:
Assigning permissions: You can assign permissions to a group of users instead of individual users. For example, you might create a group called "Developers" and grant them permissions to create and modify issues.
Sharing filters and dashboards: You can share filters and dashboards with groups of users. For example, you might create a filter that shows all issues assigned to the "Developers" group and share it with all members of that group.
Managing notifications: You can use groups to manage notifications in Jira. For example, you might create a group called "Product Owners" and add all product owners to that group. You can then set up notifications so that all members of the "Product Owners" group are notified when certain events occur in Jira.
Restricting access: You can use groups to restrict access to certain parts of Jira. For example, you might create a group called "Administrators" and grant them access to sensitive parts of Jira such as user management and system settings.
POST /rest/api/{2-3}/group
Creates a group
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
group, response, err := atlassian.Group.Create(context.Background(), "jira-users-22")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println("Group created", group.Name)
}
DELETE /rest/api/{2-3}/group
Deletes a group
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Group.Delete(context.Background(), "jira-users-2")
if err != nil {
log.Fatal(err)
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
GET /rest/api/{2-3}/group/bulk
This is an experimental endpoint
Returns a paginated list of groups, the method returns the following information:
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
options := models.GroupBulkOptionsScheme{
GroupIDs: nil,
GroupNames: nil,
}
groups, response, err := atlassian.Group.Bulk(context.Background(), &options, 0, 50)
if err != nil {
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(groups.IsLast)
for index, group := range groups.Values {
log.Printf("#%v, Group: %v", index, group.Name)
}
}
GET /rest/api/{2-3}/group/member
Returns a paginated list of all users in a group
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
members, response, err := atlassian.Group.Members(context.Background(), "jira-users", false, 0, 100)
if err != nil {
log.Fatal(err)
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(members.IsLast)
for index, member := range members.Values {
log.Printf("#%v - Group %v - Member Mail %v - Member AccountID %v", index, "jira-users", member.EmailAddress, member.AccountID)
}
}
POST /rest/api/{2-3}/group/user
Adds a user to a group
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
_, response, err := atlassian.Group.Add(context.Background(), "groupName", "accountID")
if err != nil {
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
DELETE /rest/api/{2-3}/group/user
Removes a user from a group
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Group.Remove(context.Background(), "groupName", "accountID")
if err != nil {
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
This resource represents custom issue field select list options created in Jira or using the REST API. This resource supports the following field types:
Checkboxes.
Radio Buttons.
Select List (single choice).
Select List (multiple choices).
Select List (cascading).
GET /rest/api/{2-3}/field/{fieldId}/context/{contextId}/option
Returns a list of all custom field option for a context. Options are returned first then cascading options, in the order they display in Jira, the method returns the following information:
POST /rest/api/{2-3}/field/{fieldId}/context/{contextId}/option
Creates options and, where the custom select field is of the type Select List (cascading), cascading options for a custom select field. The options are added to a context of the field.
The maximum number of options that can be created per request is 1000 and each field can have a maximum of 10000 options, the method returns the following information:
PUT /rest/api/{2-3}/field/{fieldId}/context/{contextId}/option
Updates the options of a custom field. If any of the options are not found, no options are updated. Options where the values in the request match the current values aren't updated and aren't reported in the response.
Note that this operation only works for issue field select list options created in Jira or using operations from the resource, it cannot be used with issue field select list options created by Connect apps.
DELETE /rest/api/{2-3}/field/{fieldId}/context/{contextId}/option/{optionId}
Deletes a custom field option. Options with cascading options cannot be deleted without deleting the cascading options first.
This operation works for custom field options created in Jira or the operations from this resource. To work with issue field select list options created for Connect apps use the operations.
PUT /rest/api/{2-3}/field/{fieldId}/context/{contextId}/option/move
Changes the order of custom field options or cascading options in a context.
GET /rest/api/{2-3}/statuses/search
Search returns a list of statuses that match a search on name or project.
GET /rest/api/{2-3}/statuses
Get returns a list of the statuses specified by one or more status IDs.
POST /rest/api/{2-3}/statuses
Create creates statuses for a global or project scope.
PUT /rest/api/{2-3}/statuses
Update updates statuses by ID.
DELETE /rest/api/{2-3}/statuses
Delete deletes statuses by ID.
GET /rest/api/{2-3}/status
Bulk returns a list of all statuses associated with active workflows.
GET /rest/api/{2-3}/status/{idOrName}
Get returns a status.
The status must be associated with an active workflow to be returned.
If a name is used on more than one status, only the status found first is returned. Therefore, identifying the status by its ID may be preferable.
GET /rest/api/{2-3}/notificationscheme
Search returns a list of ordered by the display name.
POST /rest/api/{2-3}/notificationscheme
Create creates a notification scheme with notifications. You can create up to 1000 notifications per request.
GET /rest/api/{2-3}/notificationscheme/project
Projects returns a paginated mapping of project that have notification scheme assigned. You can provide either one or multiple notification scheme IDs or project IDs to filter by.
If you don't provide any, this will return a list of all mappings. Note that only company-managed (classic) projects are supported. This is because team-managed
projects don't have a concept of a default notification scheme. The mappings are ordered by projectId.
GET /rest/api/{2-3}/notificationscheme/{id}
Get returns a notification scheme, including the list of events and the recipients who will receive notifications for those events.
PUT /rest/api/{2-3}/notificationscheme/{id}
Update updates a notification scheme.
DELETE /rest/api/{2-3}/notificationscheme/{notificationSchemeId}
Delete deletes a notification scheme.
PUT /rest/api/{2-3}/notificationscheme/{id}/notification
Append adds notifications to a notification scheme. You can add up to 1000 notifications per request.
DELETE /rest/api/{2-3}/notificationscheme/{notificationSchemeId}/notification/{notificationId}
Remove removes a notification from a notification scheme.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var (
fieldID = "customfield_10038"
contextID = 10180
)
fieldOptions, response, err := atlassian.Issue.Field.Context.Option.Gets(context.Background(), fieldID, contextID, nil, 0, 50)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, option := range fieldOptions.Values {
log.Println(option)
}
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var (
fieldID = "customfield_10038"
contextID = 10180
payload = &models.FieldContextOptionListScheme{
Options: []*models.CustomFieldContextOptionScheme{
// Single/Multiple Choice example
{
Value: "Option 3",
Disabled: false,
},
{
Value: "Option 4",
Disabled: false,
},
///////////////////////////////////////////
/*
// Cascading Choice example
{
OptionID: "1027",
Value: "Argentina",
Disabled: false,
},
{
OptionID: "1027",
Value: "Uruguay",
Disabled: false,
},
*/
}}
)
fieldOptions, response, err := atlassian.Issue.Field.Context.Option.Create(context.Background(), fieldID, contextID, payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, option := range fieldOptions.Options {
log.Println(option)
}
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var (
fieldID = "customfield_10038"
contextID = 10180
payload = &models.FieldContextOptionListScheme{
Options: []*models.CustomFieldContextOptionScheme{
// Single/Multiple Choice example
{
ID: "10064",
Value: "Option 3 - Updated",
Disabled: false,
},
{
ID: "10065",
Value: "Option 4 - Updated",
Disabled: true,
},
///////////////////////////////////////////
/*
// Cascading Choice example
{
OptionID: "1027",
Value: "Argentina",
Disabled: false,
},
{
OptionID: "1027",
Value: "Uruguay",
Disabled: false,
},
*/
}}
)
fieldOptions, response, err := atlassian.Issue.Field.Context.Option.Update(context.Background(), fieldID, contextID, payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, option := range fieldOptions.Options {
log.Println(option)
}
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var (
fieldID = "customfield_10038"
contextID, optionID = 10180, 10064
)
response, err := atlassian.Issue.Field.Context.Option.Delete(context.Background(), fieldID, contextID, optionID)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
"sort"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var (
fieldID = "customfield_10038"
contextID = 10180
)
log.Println("Getting the field context options")
options, response, err := atlassian.Issue.Field.Context.Option.Gets(context.Background(), fieldID, contextID, nil, 0, 50)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
var (
optionsAsMap = make(map[string]string)
optionsAsList []string
)
for _, option := range options.Values {
optionsAsList = append(optionsAsList, option.Value)
optionsAsMap[option.Value] = option.ID
}
log.Println("Sorting the fields")
sort.Strings(optionsAsList)
log.Println("Creating the new option ID's payload to order")
var optionsIDsAsList []string
for _, option := range optionsAsList {
optionsIDsAsList = append(optionsIDsAsList, optionsAsMap[option])
}
var payload = &models.OrderFieldOptionPayloadScheme{
Position: "First",
CustomFieldOptionIds: optionsIDsAsList,
}
log.Println("Ordering the options")
response, err = atlassian.Issue.Field.Context.Option.Order(context.Background(), fieldID, contextID, payload)
if err != nil {
if response != nil {
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Fatal(err)
}
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
"fmt"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
options := &models.NotificationSchemeSearchOptions{
NotificationSchemeIDs: []string{"10000"},
ProjectIDs: nil,
OnlyDefault: false,
Expand: nil,
}
notificationSchemes, response, err := jira.NotificationScheme.Search(context.Background(), options, 0, 50)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
for _, notificationScheme := range notificationSchemes.Values {
fmt.Println(notificationScheme)
}
}
package main
import (
"context"
"fmt"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
payload := &models.NotificationSchemePayloadScheme{
Description: "Notification Scheme #2",
Name: "Notification Scheme Description sample",
Events: []*models.NotificationSchemePayloadEventScheme{
{
Event: &models.NotificationSchemeEventTypeScheme{
ID: "1",
},
Notifications: []*models.NotificationSchemeEventNotificationScheme{
{
NotificationType: "Group",
Parameter: "jira-administrators",
},
},
},
},
}
notificationScheme, response, err := jira.NotificationScheme.Create(context.Background(), payload)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
fmt.Println(notificationScheme.Id)
}
package main
import (
"context"
"fmt"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
mapping, response, err := jira.NotificationScheme.Projects(context.Background(), nil, nil, 0, 50)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
for _, element := range mapping.Values {
fmt.Println(element.NotificationSchemeId, element.ProjectId)
}
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
payload := &models.NotificationSchemePayloadScheme{
Description: "description update sample",
Name: "new notification scheme name",
}
response, err := jira.NotificationScheme.Update(context.Background(), "10002", payload)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
}
package main
import (
"context"
"fmt"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
notificationScheme, response, err := jira.NotificationScheme.Get(context.Background(), "10000", []string{"all"})
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
fmt.Println(notificationScheme.Self)
fmt.Println(notificationScheme.Name)
fmt.Println(notificationScheme.ID)
fmt.Println(notificationScheme.Description)
fmt.Println(notificationScheme.Scope)
fmt.Println(notificationScheme.NotificationSchemeEvents)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
response, err := jira.NotificationScheme.Delete(context.Background(), "10002")
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
payload := &models.NotificationSchemeEventsPayloadScheme{
NotificationSchemeEvents: []*models.NotificationSchemePayloadEventScheme{
{
Event: &models.NotificationSchemeEventTypeScheme{
ID: "1",
},
Notifications: []*models.NotificationSchemeEventNotificationScheme{
{
NotificationType: "Group",
Parameter: "jira-administrators",
},
},
},
},
}
response, err := jira.NotificationScheme.Append(context.Background(), "10002", payload)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
response, err := jira.NotificationScheme.Remove(context.Background(), "10002", "10000")
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
}
GET /rest/api/{2-3}/project/{projectIdOrKey}/versions
Returns all versions in a project. The response is not paginated.
package main
import (
"context"
"fmt"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
versions, response, err := atlassian.Project.Version.Gets(context.Background(), "KP")
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 _, version := range versions {
fmt.Println(version)
}
}
POST /rest/api/{2-3}/version
Creates a project version.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.VersionPayloadScheme{
Archived: false,
ReleaseDate: "2021-03-06",
Name: "Version Sandbox",
Description: "Version Sandbox description",
ProjectID: 10000,
Released: false,
StartDate: "2021-03-02",
}
newVersion, response, err := atlassian.Project.Version.Create(context.Background(), payload)
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.Printf("The new version has been created with the ID %v", newVersion.ID)
}
GET /rest/api/{2-3}/version/{id}
Returns a project version.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
version, response, err := atlassian.Project.Version.Get(context.Background(), "10002", []string{"issuesstatus", "operations"})
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(version)
}
PUT /rest/api/{2-3}/version/{id}
Updates a project version.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.VersionPayloadScheme{
Archived: false,
Name: "Version Sandbox - UPDATED",
Description: "Version Sandbox description - UPDATED",
ProjectID: 10000,
Released: true,
}
versionUpdated, response, err := atlassian.Project.Version.Update(context.Background(), "10002", payload)
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(versionUpdated)
}
PUT /rest/api/{2-3}/version/{id}/mergeto/{moveIssuesTo}
Merges two project versions. The merge is completed by deleting the version specified in id
and replacing any occurrences of its ID in fixVersion
with the version ID specified in moveIssuesTo
.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.Project.Version.Merge(context.Background(), "10001", "10000")
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)
}
GET /rest/api/{2-3}/version/{id}/relatedIssueCounts
Returns the following counts for a version:
Number of issues where the fixVersion
is set to the version.
Number of issues where the affectedVersion
is set to the version.
Number of issues where a version custom field is set to the version.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
count, response, err := atlassian.Project.Version.RelatedIssueCounts(context.Background(), "10002")
if err != nil {
log.Fatal(err)
}
log.Println(response.Endpoint)
log.Println(count)
}
GET /rest/api/{2-3}/version/{id}/unresolvedIssueCount
Returns counts of the issues and unresolved issues for the project version.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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)
count, response, err := atlassian.Project.Version.UnresolvedIssueCount(context.Background(), "10000")
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(count)
}
GET /rest/api/{2-3}/workflowscheme
Returns a paginated list of all workflow schemes, not including draft workflow schemes.
package main
import (
"context"
"fmt"
v3 "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v3.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
workflowSchemes, response, err := instance.Workflow.Scheme.Gets(context.Background(), 0, 50)
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
for _, workflowScheme := range workflowSchemes.Values {
fmt.Println(workflowScheme.Name)
fmt.Println(workflowScheme.Description)
fmt.Println(workflowScheme.ID)
fmt.Println(workflowScheme.Self)
fmt.Println(workflowScheme.DefaultWorkflow)
}
fmt.Println(workflowSchemes.IsLast)
}
POST /rest/api/{2-3}/workflowscheme
Creates a workflow scheme.
package main
import (
"context"
"fmt"
v3 "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v3.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
payload := &models.WorkflowSchemePayloadScheme{
DefaultWorkflow: "jira",
Name: "Example workflow scheme",
Description: "The description of the example workflow scheme.",
IssueTypeMappings: map[string]interface{}{
"10002": "PV: Project Management Workflow",
"10005": "Software Simplified Workflow for Project K2",
},
}
newWorkflowScheme, response, err := instance.Workflow.Scheme.Create(context.Background(), payload)
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
fmt.Println(newWorkflowScheme.Name)
fmt.Println(newWorkflowScheme.Description)
fmt.Println(newWorkflowScheme.ID)
fmt.Println(newWorkflowScheme.Self)
fmt.Println(newWorkflowScheme.DefaultWorkflow)
}
GET /rest/api/{2-3}/workflowscheme/{id}
Returns a workflow scheme.
package main
import (
"context"
"fmt"
v3 "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v3.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
workflowScheme, response, err := instance.Workflow.Scheme.Get(context.Background(), 10007, false)
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
fmt.Println(workflowScheme.Name)
fmt.Println(workflowScheme.Description)
fmt.Println(workflowScheme.ID)
fmt.Println(workflowScheme.Self)
fmt.Println(workflowScheme.DefaultWorkflow)
}
PUT /rest/api/{2-3}/workflowscheme/{id}
Updates a workflow scheme, including the name, default workflow, issue type to project mappings, and more. If the workflow scheme is active (that is, being used by at least one project), then a draft workflow scheme is created or updated instead, provided that updateDraftIfNeeded
is set to true
.
package main
import (
"context"
"fmt"
v3 "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v3.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
payload := &models.WorkflowSchemePayloadScheme{
Name: "Example workflow scheme - UPDATED",
Description: "The description of the example workflow scheme.",
IssueTypeMappings: map[string]interface{}{
"10002": "PV: Project Management Workflow",
"10005": "Software Simplified Workflow for Project K2",
},
UpdateDraftIfNeeded: true,
}
workflowSchemeUpdated, response, err := instance.Workflow.Scheme.Update(context.Background(), 10003, payload)
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
fmt.Println(workflowSchemeUpdated.Name)
fmt.Println(workflowSchemeUpdated.Description)
fmt.Println(workflowSchemeUpdated.ID)
fmt.Println(workflowSchemeUpdated.Self)
fmt.Println(workflowSchemeUpdated.DefaultWorkflow)
}
DELETE /rest/api/{2-3}/workflowscheme/{id}
Delete deletes a workflow scheme. Please note that a workflow scheme cannot be deleted if it is active (that is, being used by at least one project).
package main
import (
"context"
v3 "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v3.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
response, err := instance.Workflow.Scheme.Delete(context.Background(), 10003)
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
}
GET /rest/api/{2-3}/workflowscheme/project
Associations returns a list of the workflow schemes associated with a list of projects.
Each returned workflow scheme includes a list of the requested projects associated with it.
Any team-managed or non-existent projects in the request are ignored and no errors are returned.
package main
import (
"context"
"fmt"
v3 "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v3.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
schemesByProject, response, err := instance.Workflow.Scheme.Associations(context.Background(), []int{10001})
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
for _, mapping := range schemesByProject.Values {
fmt.Println(mapping.WorkflowScheme.Name, mapping.WorkflowScheme.ID)
fmt.Println(mapping.ProjectIds)
}
}
PUT /rest/api/{2-3}/workflowscheme/project
Assign assigns a workflow scheme to a project. This operation is performed only when there are no issues in the project. The workflow schemes can only be assigned to classic projects.
package main
import (
"context"
v3 "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v3.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
response, err := instance.Workflow.Scheme.Assign(context.Background(), "10001", "10001")
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
}
This resource represents permission schemes for a project.
GET /rest/api/{2-3}/project/{projectKeyOrId}/permissionscheme
Gets the permission scheme associated with the project.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
scheme, response, err := atlassian.Project.Permission.Get(context.Background(), "KP", []string{"all"})
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(scheme)
}
PUT /rest/api/{2-3}/project/{projectKeyOrId}/permissionscheme
Assigns a permission scheme with a project
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 (
projectKeyOrID = "KP"
permissionSchemeID = 10000
)
scheme, response, err := atlassian.Project.Permission.Assign(context.Background(), projectKeyOrID, permissionSchemeID)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(scheme)
}
GET /rest/api/{2-3}/project/{projectKeyOrId}/securitylevel
Returns all issue security levels for the project that the user has access to.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
levels, response, err := atlassian.Project.Permission.SecurityLevels(context.Background(), "KP")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, level := range levels.Levels {
log.Println(level)
}
}
This resource represents users watching an issue. Use it to get details of users watching an issue as well as start and stop a user watching an issue.
GET /rest/api/{2-3}/issue/{issueIdOrKey}/watchers
Returns the watchers for an issue.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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)
watchers, response, err := atlassian.Issue.Watchers.Gets(context.Background(), "KP-2")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(watchers.IsWatching, watchers.WatchCount)
for _, watcher := range watchers.Watchers {
log.Println(watcher.Self, watcher.AccountID)
}
}
POST /rest/api/{2-3}/issue/{issueIdOrKey}/watchers
Adds a user as a watcher of an issue by passing the account ID of the user. For example, "5b10ac8d82e05b22cc7d4ef5"
. If no user is specified the calling user is added.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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.Issue.Watchers.Add(context.Background(), "KP-2")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
DELETE /rest/api/{2-3}/issue/{issueIdOrKey}/watchers
Deletes a user as a watcher of an issue.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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.Issue.Watchers.Delete(context.Background(), "KP-2", "5b86be50b8e3cb5895860d6d")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
POST /rest/api/{2-3}/issue/watching
Not implemented, yet. Feel free to open a PR or issue
package main
import (
"context"
"fmt"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
options := &models.WorkflowStatusSearchParams{
ProjectID: "10000",
StatusCategory: "IN_PROGRESS",
Expand: []string{"usages"},
}
var projectStatuses []*models.WorkflowStatusDetailScheme
var startAt int
for {
page, response, err := atlassian.Workflow.Status.Search(context.Background(), options, startAt, 50)
if err != nil {
log.Println(response.Code)
log.Println(response.Endpoint)
log.Fatal(err)
}
projectStatuses = append(projectStatuses, page.Values...)
if page.IsLast {
break
}
startAt = startAt + 50
}
for _, status := range projectStatuses {
fmt.Println(status.Name, status.ID, status.StatusCategory)
fmt.Println("--------------------------------")
fmt.Println("Status Name:", status.Name)
fmt.Println("Status ID:", status.ID)
fmt.Println("Status Category:", status.StatusCategory)
for index, project := range status.Usages {
fmt.Println("--- Project Usage #", index)
fmt.Println("---- Project ID:", project.Project.ID)
fmt.Println("---- Project IssueTypes:", project.IssueTypes)
}
fmt.Println("--------------------------------")
}
}
package main
import (
"context"
"fmt"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
statuses, response, err := atlassian.Workflow.Status.Gets(context.Background(), []string{"401", "400", "10008"}, []string{"usages"})
if err != nil {
log.Println(response.Code)
log.Println(response.Endpoint)
log.Fatal(err)
}
for _, status := range statuses {
fmt.Println(status.Name, status.ID, status.StatusCategory)
fmt.Println("--------------------------------")
fmt.Println("Status Name:", status.Name)
fmt.Println("Status ID:", status.ID)
fmt.Println("Status Category:", status.StatusCategory)
for index, project := range status.Usages {
fmt.Println("--- Project Usage #", index)
fmt.Println("---- Project ID:", project.Project.ID)
fmt.Println("---- Project IssueTypes:", project.IssueTypes)
}
fmt.Println("--------------------------------")
}
}
package main
import (
"context"
"fmt"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
payload := &models.WorkflowStatusPayloadScheme{
Statuses: []*models.WorkflowStatusNodeScheme{
{
Name: "UAT TEST",
StatusCategory: "IN_PROGRESS",
Description: "status description",
},
{
Name: "Stage TEST",
StatusCategory: "IN_PROGRESS",
Description: "status description",
},
},
Scope: &models.WorkflowStatusScopeScheme{
Type: "GLOBAL",
},
}
statuses, response, err := atlassian.Workflow.Status.Create(context.Background(), payload)
if err != nil {
log.Println(response.Code)
log.Println(response.Endpoint)
log.Println(response.Bytes.String())
log.Fatal(err)
}
for _, status := range statuses {
fmt.Println(status.Name, status.ID, status.StatusCategory)
fmt.Println("--------------------------------")
fmt.Println("Status Name:", status.Name)
fmt.Println("Status ID:", status.ID)
fmt.Println("Status Category:", status.StatusCategory)
fmt.Println("--------------------------------")
}
}
package main
import (
"context"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
payload := &models.WorkflowStatusPayloadScheme{
Statuses: []*models.WorkflowStatusNodeScheme{
{
ID: "10013",
Name: "UAT Finished",
StatusCategory: "DONE",
Description: "status description",
},
{
ID: "10014",
Name: "Stage Finished",
StatusCategory: "DONE",
Description: "status description",
},
},
}
response, err := atlassian.Workflow.Status.Update(context.Background(), payload)
if err != nil {
log.Println(response.Code)
log.Println(response.Endpoint)
log.Println(response.Bytes.String())
log.Fatal(err)
}
}
package main
import (
"context"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Workflow.Status.Delete(context.Background(), []string{"10013", "10014"})
if err != nil {
log.Println(response.Code)
log.Println(response.Endpoint)
log.Println(response.Bytes.String())
log.Fatal(err)
}
}
package main
import (
"context"
"fmt"
v3 "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v3.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
activeStatuses, response, err := instance.Workflow.Status.Bulk(context.Background())
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
for _, status := range activeStatuses {
fmt.Println(status.Name, status.ID)
}
}
package main
import (
"context"
"fmt"
v3 "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v3.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
status, response, err := instance.Workflow.Status.Get(context.Background(), "Open")
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
fmt.Println(status.Name, status.ID)
}
In Jira, a filter is a saved search query that you can use to retrieve a specific set of issues from your Jira instance. A filter can be based on various criteria such as issue type, priority, status, assignee, labels, and more.
Filters can be saved and shared with other users, allowing you to easily collaborate and work together on a specific set of issues. You can also use filters to create custom dashboards and reports to monitor the progress of your team's work.
POST /rest/api/{2-3}/filter
This method creates a new filter. The filter is shared according to the default share scope. The filter is not selected as a favorite, the method returns the following information:
package main
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"github.com/google/uuid"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
newFilterBody := models.FilterPayloadScheme{
Name: fmt.Sprintf("Filter #%v", uuid.New().String()),
Description: "Filter's description",
JQL: "issuetype = Bug",
Favorite: false,
SharePermissions: []*models.SharePermissionScheme{
{
Type: "project",
Project: &models.ProjectScheme{
ID: "10000",
},
Role: nil,
Group: nil,
},
{
Type: "group",
Group: &models.GroupScheme{Name: "jira-administrators"},
},
},
}
filter, response, err := atlassian.Filter.Create(context.Background(), &newFilterBody)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("The filter has been created: %v - %v", filter.ID, filter.Name)
}
GET /rest/api/3/filter/favourite
This method returns the visible favorite filters of the user, the method returns the following information:
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
filters, response, err := atlassian.Filter.Favorite(context.Background())
if err != nil {
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println("favorite filters", len(filters))
for _, filter := range filters {
log.Println(filter)
}
GET /rest/api/{2-3}/filter/my
Returns the filters owned by the user. If includeFavourites
is true
, the user's visible favorite filters are also returned, the method returns the following information:
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
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)
myFilters, response, err := atlassian.Filter.My(context.Background(), false, []string{"sharedUsers", "subscriptions"})
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println("my filters", len(myFilters))
for _, filter := range myFilters {
log.Println(filter.ID)
for _, shareUser := range filter.ShareUsers.Items {
log.Println(shareUser.Name, shareUser.DisplayName)
}
for _, subscription := range filter.Subscriptions.Items {
log.Println(subscription.ID)
}
}
}
GET /rest/api/{2-3}/filter/search
Returns a paginated list of filters. Use this operation to get:
specific filters, by defining id
only.
filters that match all of the specified attributes. For example, all filters for a user with a particular word in their name. When multiple attributes are specified only filters matching all attributes are returned.
🔒 Permissions required: None, however, only the following filters that match the query parameters are returned:
filters owned by the user.
filters shared with a group that the user is a member of.
filters shared with a private project that the user has Browse projects project permission
for.
filters shared with a public project.
filters shared with the public.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
options := models.FilterSearchOptionScheme{
Name: "",
AccountID: "",
Group: "",
ProjectID: 0,
IDs: nil,
OrderBy: "description",
Expand: nil,
}
filters, response, err := atlassian.Filter.Search(context.Background(), &options, 0, 10)
if err != nil {
if response != nil {
log.Println("HTTP Endpoint Used", response.Endpoint)
}
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println("Filters found", len(filters.Values))
}
GET /rest/api/{2-3}/filter/{id}
This method returns a filter using the ID as a parameter, the method returns the following information:
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
filter, response, err := atlassian.Filter.Get(context.Background(), 1, nil)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println("Get Filter result", filter.Name, filter.Name)
}
PUT /rest/api/{2-3}/filter/{id}
This method updates a filter. Use this operation to update a filter's name, description, JQL, or sharing, the method returns the following information:
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
payload := models.FilterPayloadScheme{
JQL: "issuetype = Story",
}
filter, response, err := atlassian.Filter.Update(context.Background(), 1, &payload)
if err != nil {
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println("new JQL filter value", filter.Jql)
}
DELETE /rest/api/{2-3}/filter/{id}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Filter.Delete(context.Background(), 1)
if err != nil {
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
PUT /rest/api/{2-3}/filter/{id}/owner
This is an experimental endpoint
Changes the owner of the filter.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Filter.Change(context.Background(), 1, "asda03333")
if err != nil {
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
A permission scheme is a collection of permission grants. A permission grant consists of a holder
and a permission
.
The holder
object contains information about the user or group being granted the permission. For example, the Administer projects permission is granted to a group named Teams in space administrators. In this case, the type is "type": "group"
, and the parameter is the group name, "parameter": "Teams in space administrators"
. The holder
object is defined by the following properties:
type
Identifies the user or group (see the list of types below).
parameter
The value of this property depends on the type
. For example, if the type
is a group, then you need to specify the group name.
The following types
are available. The expected values for the parameter
are given in parenthesis (some types
may not have a parameter
):
GET /rest/api/{2-3}/permissionscheme
Returns all permission schemes.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
permissionSchemes, response, err := atlassian.Permission.Scheme.Gets(context.Background())
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, permissionScheme := range permissionSchemes.PermissionSchemes {
log.Println(permissionScheme.ID, permissionScheme.Name)
}
}
GET /rest/api/{2-3}/permissionscheme/{schemeId}
Returns a permission scheme.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 (
permissionSchemeID = 10001
expand = []string{"field", "group", "permissions", "projectRole", "user"}
)
permissionScheme, response, err := atlassian.Permission.Scheme.Get(context.Background(), permissionSchemeID, expand)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(permissionScheme)
}
POST /rest/api/{2-3}/permissionscheme
Creates a new permission scheme. You can create a permission scheme with or without defining a set of permission grants.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.PermissionSchemeScheme{
Name: "EF Permission Scheme",
Description: "EF Permission Scheme description",
Permissions: []*models.PermissionGrantScheme{
{
Permission: "ADMINISTER_PROJECTS",
Holder: &models.PermissionGrantHolderScheme{
Parameter: "jira-administrators-system",
Type: "group",
},
},
{
Permission: "CLOSE_ISSUES",
Holder: &models.PermissionGrantHolderScheme{
Type: "assignee",
},
},
},
}
permissionScheme, response, err := atlassian.Permission.Scheme.Create(context.Background(), payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(permissionScheme)
}
DELETE /rest/api/{2-3}/permissionscheme/{schemeId}
Deletes a permission scheme.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 permissionSchemeID = 10004
response, err := atlassian.Permission.Scheme.Delete(context.Background(), permissionSchemeID)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
PUT /rest/api/{2-3}/permissionscheme/{schemeId}
Updates a permission scheme
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.PermissionSchemeScheme{
Name: "EF Permission Scheme - UPDATED",
Description: "EF Permission Scheme description - UPDATED",
Permissions: []*models.PermissionGrantScheme{
{
Permission: "CLOSE_ISSUES",
Holder: &models.PermissionGrantHolderScheme{
Parameter: "jira-administrators-system",
Type: "group",
},
},
},
}
permissionScheme, response, err := atlassian.Permission.Scheme.Update(context.Background(), 10004, payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(permissionScheme.Name)
log.Println(permissionScheme.ID)
log.Println(permissionScheme.Description)
log.Println(permissionScheme.Self)
for _, permissionGrant := range permissionScheme.Permissions {
log.Println(permissionGrant.ID, permissionGrant.Permission)
}
}
name
description
anyone
Grant for anonymous users.
applicationRole
Grant for users with access to the specified application (application name). See Update product access settings for more information.
assignee
Grant for the user currently assigned to an issue.
group
Grant for the specified group (group name).
groupCustomField
Grant for a user in the group selected in the specified custom field (custom field ID).
projectLead
Grant for a project lead.
projectRole
Grant for the specified project role (project role ID).
reporter
Grant for the user who reported the issue.
sd.customer.portal.only
Jira Service Desk only. Grants customers permission to access the customer portal but not Jira
user
Grant for the specified user (user ID - historically this was the userkey but that is deprecated and the account ID should be used).
userCustomField
Grant for a user selected in the specified custom field (custom field ID).
package models
// InfoScheme represents the information about a system.
type InfoScheme struct {
Version string `json:"version,omitempty"` // The version of the system.
PlatformVersion string `json:"platformVersion,omitempty"` // The platform version of the system.
BuildDate *InfoBuildDataScheme `json:"buildDate,omitempty"` // The build date of the system.
BuildChangeSet string `json:"buildChangeSet,omitempty"` // The build change set of the system.
IsLicensedForUse bool `json:"isLicensedForUse,omitempty"` // Indicates if the system is licensed for use.
Links *InfoLinkScheme `json:"_links,omitempty"` // Links related to the system.
}
// InfoBuildDataScheme represents the build date of a system.
type InfoBuildDataScheme struct {
ISO8601 DateTimeScheme `json:"iso8601,omitempty"` // The ISO 8601 format of the build date.
Jira string `json:"jira,omitempty"` // The Jira format of the build date.
Friendly string `json:"friendly,omitempty"` // The friendly format of the build date.
EpochMillis int64 `json:"epochMillis,omitempty"` // The epoch milliseconds of the build date.
}
// InfoLinkScheme represents a link related to a system.
type InfoLinkScheme struct {
Self string `json:"self,omitempty"` // The URL of the system itself.
}
Jira dashboards are customizable, visual displays that provide an overview of project status and performance metrics in real-time. Dashboards are used to track progress and identify trends, enabling teams to make informed decisions and prioritize tasks.
Here are some key elements of Jira dashboards:
Gadgets: Gadgets are the building blocks of Jira dashboards. They are small, customizable widgets that display information in various formats, such as charts, lists, or calendars. Examples of gadgets include the Agile Sprint Burndown gadget, which shows the remaining work in a sprint, or the Pie Chart gadget, which displays the distribution of issues across a project.
Filters: Filters are used to specify which data should be displayed in a gadget. For example, you can create a filter that displays all open bugs assigned to a specific developer. Filters can be saved and reused across multiple gadgets.
Layout: Dashboards can be customized with different layouts to display multiple gadgets on a single page. Users can create multiple dashboards for different purposes, such as a team dashboard or a project-specific dashboard.
Permissions: Jira dashboards can be shared with team members or made public, depending on the level of access required. Permissions can be set at the individual gadget level or for the entire dashboard.
GET /rest/api/{2-3}/dashboard
Returns a list of dashboards owned by or shared with the user. The list may be filtered to include only favorite or owned dashboards.
POST /rest/api/{2-3}/dashboard
This is an experimental endpoint
This method allows you to create a new dashboard in your Jira instance. The request body should contain a JSON object with the following properties:
name: The name of the dashboard.
sharePermissions: An array of objects representing the users and groups who have permission to view the dashboard.
gadget: An array of objects representing the gadgets that should be displayed on the dashboard.
GET /rest/api/{2-3}/dashboard/search
Returns a paginated list of dashboards. This operation is similar to Get dashboards except that the results can be refined to include dashboards that have specific attributes.
For example, dashboards with a particular name. When multiple attributes are specified only filters matching all attributes are returned.
GET /rest/api/{2-3}/dashboard/{id}
Returns a dashboard using the dashboard-id
However, to get a dashboard, the dashboard must be shared with the user or the user must own it. Note, users with Administer Jira are considered owners of the System dashboard. The System dashboard is considered to be shared with all other users.
PUT /rest/api/{2-3}/dashboard/{id}
This is an experimental endpoint
Updates a dashboard, replacing all the dashboard details with those provided. The dashboard to be updated must be owned by the user.
DELETE /rest/api/{2-3}/dashboard/{id}
This is an experimental endpoint
Deletes a dashboard, the dashboard to be deleted must be owned by the user.
POST /rest/api/{2-3}/dashboard/{id}/copy
This is an experimental endpoint
Copies a dashboard. Any values provided in the dashboard
parameter replace those in the copied dashboard.
POST /rest/agile/1.0/sprint
Creates a future sprint. Sprint name and origin board id are required. Start date, end date, and goal are optional.
GET /rest/agile/1.0/sprint/{sprintId}
Returns the sprint for a given sprint ID. The sprint will only be returned if the user can view the board that the sprint was created on, or view at least one of the issues in the sprint.
PUT /rest/agile/1.0/sprint/{sprintId}
Performs a full update of a sprint. A full update means that the result will be exactly the same as the request body. Any fields not present in the request JSON will be set to null.
POST /rest/agile/1.0/sprint/{sprintId}
Performs a partial update of a sprint. A partial update means that fields not present in the request JSON will not be updated.
GET /rest/agile/1.0/sprint/{sprintId}/issue
Returns all issues in a sprint, for a given sprint ID. This only includes issues that the user has permission to view. By default, the returned issues are ordered by rank.
GET /rest/agile/1.0/sprint/{sprintId}/issue
GET /rest/agile/1.0/sprint/{sprintId}/issue
DELETE /rest/agile/1.0/sprint/{sprintId}
Delete deletes a sprint. Once a sprint is deleted, all open issues in the sprint will be moved to the backlog.
POST /rest/agile/1.0/sprint/{sprintId}/issue
Move moves issues to a sprint, for a given sprint ID. Issues can only be moved to open or active sprints. The maximum number of issues that can be moved in one operation is 50.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
payload := &models.SprintPayloadScheme{
Name: "Sprint XX",
StartDate: "2015-04-11T15:22:00.000+10:00",
EndDate: "2015-04-20T01:22:00.000+10:00",
OriginBoardID: 4,
Goal: "Sprint XX goal",
}
sprint, response, err := atlassian.Sprint.Create(context.Background(), payload)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", response.Bytes.String())
}
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Bytes.String())
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(sprint)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
sprint, response, err := atlassian.Sprint.Get(context.Background(), 3)
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(sprint)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
payload := &models.SprintPayloadScheme{
Name: "Sprint XX-Updated",
Goal: "Sprint XX goal-Updated",
State: "Active",
StartDate: "2020-04-11T15:22:00.000+10:00",
EndDate: "2021-04-20T01:22:00.000+10:00",
}
sprint, response, err := atlassian.Sprint.Update(context.Background(), 2, payload)
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(sprint.Name, sprint.Goal)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
payload := &models.SprintPayloadScheme{
Name: "Sprint XX-Patched",
}
sprint, response, err := atlassian.Sprint.Path(context.Background(), 2, payload)
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(sprint.Name, sprint.Goal)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
options := &models.IssueOptionScheme{
JQL: "",
Fields: nil,
Expand: nil,
ValidateQuery: false,
}
issues, response, err := atlassian.Sprint.Issues(context.Background(), 2, options, 0, 50)
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(issues.Total)
log.Println(issues.Expand)
log.Println(issues.MaxResults)
log.Println(issues.StartAt)
for _, issue := range issues.Issues {
log.Println(issue.Key, issue.ID)
}
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
response, err := atlassian.Sprint.Start(context.Background(), 3)
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)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
response, err := atlassian.Sprint.Start(context.Background(), 3)
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)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
response, err := atlassian.Sprint.Delete(context.Background(), 3)
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)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
options := &models.SprintMovePayloadScheme{
Issues: nil,
RankBeforeIssue: "",
RankAfterIssue: "",
RankCustomFieldId: 0,
}
response, err := atlassian.Sprint.Move(context.Background(), 3, options)
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)
}
In Jira Cloud, custom fields are managed in a way that allows for flexibility and dynamic creation. Each new custom field that you create within a Jira Cloud instance is assigned a unique ID. This ID is used to identify and manage the custom field's configuration and data within the Jira system.
In this particular case, the library contains multiples helpers method will help you to extract the customfield information by type using the response buffer.
The following methods can be used to extract the customfield information from one issue.
This method parses a multi-select custom field from the given buffer data associated with the specified custom field ID and returns a slice of pointers to CustomFieldContextOptionSchema
structs.
issue, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
options, err := models.ParseMultiSelectCustomField(response.Bytes, "customfield_10046")
if err != nil {
log.Fatal(err)
}
for _, option := range options {
fmt.Println(option.ID, option.Value)
}
ParseSelectCustomField parses a select custom field from the given buffer data associated with the specified custom field ID and returns a CustomFieldContextOptionScheme struct
_, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
option, err := models.ParseSelectCustomField(response.Bytes, "customfield_10047")
if err != nil {
log.Fatal(err)
}
fmt.Println(option.ID, option.Value)
This method parses a cascading custom field from the given buffer data associated with the specified custom field ID and returns a CascadingSelectScheme struct pointer.
issue, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
cascading, err := models.ParseCascadingSelectCustomField(response.Bytes, "customfield_10045")
if err != nil {
log.Fatal(err)
}
fmt.Println(cascading.Value, cascading.Child.Value)
ParseDatePickerCustomField parses the datepicker customfield from the given buffer data associated with the specified custom field ID and returns a struct time.Time value
_, response, err := client.Issue.Get(context.Background(), "KP-24", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
datePicker, err := models.ParseDatePickerCustomField(response.Bytes, "customfield_10040")
if err != nil {
log.Fatal(err)
}
fmt.Println(datePicker.String())
ParseDateTimeCustomField parses the datetime customfield from the given buffer data associated with the specified custom field ID and returns a struct time.Time value.
_, response, err := client.Issue.Get(context.Background(), "KP-24", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
datePicker, err := models.ParseDateTimeCustomField(response.Bytes, "customfield_10041")
if err != nil {
log.Fatal(err)
}
fmt.Println(datePicker.String())
This method parses a group-picker custom field from the given buffer data associated with the specified custom field ID and returns a slice of pointers to UserDetailScheme structs.
issue, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
users, err := models.ParseMultiUserPickerCustomField(response.Bytes, "customfield_10055")
if err != nil {
log.Fatal(err)
}
for _, user := range users {
fmt.Println(user.EmailAddress, user.AccountID)
}
This method parses a group-picker custom field from the given buffer data associated with the specified custom field ID and returns a slice of pointers to GroupDetailScheme structs.
issue, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
groups, err := models.ParseMultiGroupPickerCustomField(response.Bytes, "customfield_10052")
if err != nil {
log.Fatal(err)
}
for _, group := range groups {
fmt.Println(group.Name)
}
ParseFloatCustomField parses a float custom field from the given buffer data associated with the specified custom field ID and returns string.
issue, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
number, err := models.ParseFloatCustomField(response.Bytes, "customfield_10043")
if err != nil {
log.Fatal(err)
}
fmt.Println(number)
ParseSprintCustomField parses a sprints custom field from the given buffer data associated with the specified custom field ID and returns a slice of the SprintDetailScheme struct.
issue, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
sprints, err := models.ParseSprintCustomField(response.Bytes, "customfield_10020")
if err != nil {
log.Fatal(err)
}
for _, sprint := range sprints {
fmt.Println(sprint.ID)
}
ParseLabelCustomField parses a textfield slice custom field from the given buffer data associated with the specified custom field ID and returns string slice.
issue, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
labels, err := models.ParseLabelCustomField(response.Bytes, "customfield_10042")
if err != nil {
log.Fatal(err)
}
for _, label := range labels {
fmt.Println(label)
}
ParseMultiVersionCustomField parses a version-picker custom field from the given buffer data associated with the specified custom field ID and returns a slice of pointers to VersionDetailScheme structs.
issue, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
versions, err := models.ParseMultiVersionCustomField(response.Bytes, "customfield_10067")
if err != nil {
log.Fatal(err)
}
for _, version := range versions {
fmt.Println(version.ID, version.Name, version.Description)
}
ParseUserPickerCustomField parses a user custom field from the given buffer data associated with the specified custom field ID and returns a struct of UserDetailScheme.
_, response, err := client.Issue.Get(context.Background(), "KP-24", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
user, err := models.ParseUserPickerCustomField(response.Bytes, "customfield_10051")
if err != nil {
log.Fatal(err)
}
fmt.Println(user.EmailAddress)
fmt.Println(user.DisplayName)
fmt.Println(user.AccountID)
fmt.Println(user.AccountType)
ParseAssetCustomField parses the Jira assets elements from the given buffer data associated with the specified custom field ID and returns a struct CustomFieldAssetScheme slice.
issue, response, err := client.Issue.Get(context.Background(), "KP-23", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
assets, err := models.ParseAssetCustomField(response.Bytes, "customfield_10068")
if err != nil {
log.Fatal(err)
}
for _, asset := range assets {
fmt.Println(asset.Id, asset.WorkspaceId, asset.ObjectId)
}
ParseStringCustomField parses a textfield custom field from the given buffer data associated with the specified custom field ID and returns string.
_, response, err := client.Issue.Get(context.Background(), "KP-24", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
textField, err := models.ParseStringCustomField(response.Bytes, "customfield_10049")
if err != nil {
log.Fatal(err)
}
fmt.Println(textField)
If you want to extract the customfield values from a buffer of issues, you can use the following methods, it returns a map where the key is the issue key and the value is the customfield values parsed
ParseMultiSelectCustomFields extracts and parses multi-select custom field data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a slice of CustomFieldContextOptionScheme structs, representing the parsed multi-select custom field values.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10046"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
multiSelectOptions, err := models.ParseMultiSelectCustomFields(response.Bytes, "customfield_10046")
if err != nil {
log.Fatal(err)
}
for issue, options := range multiSelectOptions {
for _, option := range options {
fmt.Println(issue, option.ID, option.Value)
}
}
ParseSelectCustomFields extracts and parses select custom field data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a CustomFieldContextOptionScheme struct, representing the parsed select custom field value.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10047"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseSelectCustomFields(response.Bytes, "customfield_10047")
if err != nil {
log.Fatal(err)
}
for issue, option := range customfields {
fmt.Println(issue, option.ID, option.Value)
}
ParseCascadingCustomFields extracts and parses a cascading custom field data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a CascadingSelectScheme struct pointer, representing the parsed cascading custom field value.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10045"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseCascadingCustomFields(response.Bytes, "customfield_10045")
if err != nil {
log.Fatal(err)
}
for issue, value := range customfields {
fmt.Println(issue, value.Value, value.Child.Value)
}
ParseMultiUserPickerCustomFields extracts and parses a user picker custom field data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a slice of UserDetailScheme structs, representing the parsed multi-select custom field values.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10055"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseMultiUserPickerCustomFields(response.Bytes, "customfield_10055")
if err != nil {
log.Fatal(err)
}
for issue, users := range customfields {
for _, user := range users {
fmt.Println(issue, user.AccountID, user.DisplayName)
}
}
ParseDatePickerCustomFields extracts and parses the datepicker customfield data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a time.Time value, representing the parsed datepicker values with the Jira issues.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10040"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseDatePickerCustomFields(response.Bytes, "customfield_10040")
if err != nil {
log.Fatal(err)
}
for issue, datepicker := range customfields {
fmt.Println(issue, datepicker.String())
}
ParseDateTimeCustomFields extracts and parses the datetime customfield data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a time.Time value, representing the parsed datetime values with the Jira issues.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10041"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseDateTimeCustomFields(response.Bytes, "customfield_10041")
if err != nil {
log.Fatal(err)
}
for issue, datetime := range customfields {
fmt.Println(issue, datetime.String())
}
ParseMultiGroupPickerCustomFields extracts and parses a group picker custom field data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a slice of GroupDetailScheme structs, representing the parsed multi-group custom field values.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10052"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseMultiGroupPickerCustomFields(response.Bytes, "customfield_10052")
if err != nil {
log.Fatal(err)
}
for issue, groups := range customfields {
for _, group := range groups {
fmt.Println(issue, group.Name, group.GroupID)
}
}
ParseFloatCustomFields extracts and parses the float customfield information from multiple issues using a bytes.Buffer.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a string representing the parsed float64 customfield value.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10043"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseFloatCustomFields(response.Bytes, "customfield_10043")
if err != nil {
log.Fatal(err)
}
for issue, number := range customfields {
fmt.Println(issue, number)
}
ParseStringCustomFields extracts and parses the textfield customfield information from multiple issues using a bytes.Buffer.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a string representing the parsed textfield customfield value.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10049"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseStringCustomFields(response.Bytes, "customfield_10049")
if err != nil {
log.Fatal(err)
}
for issue, textField := range customfields {
fmt.Println(issue, textField)
}
ParseUserPickerCustomFields extracts and parses a user custom field data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a UserDetailScheme struct pointer ,representing the parsed user custom field value.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10051"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseUserPickerCustomFields(response.Bytes, "customfield_10051")
if err != nil {
log.Fatal(err)
}
for issue, user := range customfields {
fmt.Println(issue, user.AccountID)
}
ParseSprintCustomFields extracts and parses sprint custom field data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a slice of SprintDetailScheme structs, representing the parsed sprint custom field values.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10020"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseSprintCustomFields(response.Bytes, "customfield_10020")
if err != nil {
log.Fatal(err)
}
for issue, sprints := range customfields {
for _, sprint := range sprints {
fmt.Println(issue, sprint.Name, sprint.ID, sprint.BoardID, sprint.State)
}
}
ParseLabelCustomFields extracts and parses the label customfield information from multiple issues using a bytes.Buffer.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a string slice representing the parsed label customfield value.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10042"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseLabelCustomFields(response.Bytes, "customfield_10042")
if err != nil {
log.Fatal(err)
}
for issue, labels := range customfields {
fmt.Println(issue, labels)
}
ParseMultiVersionCustomFields extracts and parses a version picker custom field data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a slice of VersionDetailScheme structs, representing the parsed multi-version custom field values.
The JSON data within the buffer is expected to have a specific structure where the custom field values are organized by issue keys and options are represented within a context.
The function parses this structure to extract and organize the custom field values.
If the custom field data cannot be parsed successfully, an error is returned.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10067"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseMultiVersionCustomFields(response.Bytes, "customfield_10067")
if err != nil {
log.Fatal(err)
}
for issue, versions := range customfields {
for _, version := range versions {
fmt.Println(issue, version.Name, version.ID)
}
}
ParseAssetCustomFields extracts and parses jira assets customfield data from a given bytes.Buffer from multiple issues.
This function takes the name of the custom field to parse and a bytes.Buffer containing JSON data representing the custom field values associated with different issues. It returns a map where the key is the issue key and the value is a slice of CustomFieldAssetScheme structs, representing the parsed assets associated with a Jira issues.
_, response, err := client.Issue.Search.Post(context.Background(), "project = KP", []string{"customfield_10072"}, nil, 0, 50, "")
if err != nil {
log.Fatal(err)
}
customfields, err := models.ParseAssetCustomFields(response.Bytes, "customfield_10072")
if err != nil {
log.Fatal(err)
}
for issue, assets := range customfields {
for _, asset := range assets {
fmt.Println(issue, asset.Id, asset.WorkspaceId, asset.ObjectId)
}
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jiraCloud, err := v3.New(nil, host)
if err != nil {
return
}
jiraCloud.Auth.SetBasicAuth(mail, token)
jiraCloud.Auth.SetUserAgent("curl/7.54.0")
dashboards, response, err := jiraCloud.Dashboard.Gets(context.Background(), 0, 50, "")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, dashboard := range dashboards.Dashboards {
log.Println(dashboard.ID, dashboard.Name)
}
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jiraCloud, err := v3.New(nil, host)
if err != nil {
return
}
jiraCloud.Auth.SetBasicAuth(mail, token)
jiraCloud.Auth.SetUserAgent("curl/7.54.0")
var payload = &models.DashboardPayloadScheme{
Name: "Team Tracking 4",
Description: "description sample",
SharePermissions: []*models.SharePermissionScheme{
{
Type: "project",
Project: &models.ProjectScheme{
ID: "10000",
},
Role: nil,
Group: nil,
},
{
Type: "group",
Group: &models.GroupScheme{Name: "jira-administrators"},
},
},
}
dashboard, response, err := jiraCloud.Dashboard.Create(context.Background(), payload)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("Dashboard Name: %v", dashboard.Name)
log.Printf("Dashboard ID: %v", dashboard.ID)
log.Printf("Dashboard View: %v", dashboard.View)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
searchOptions := models.DashboardSearchOptionsScheme{
DashboardName: "Bug",
GroupPermissionName: "administrators",
OrderBy: "description",
Expand: []string{"description", "favourite", "sharePermissions"},
}
dashboards, response, err := jira.Dashboard.Search(context.Background(), &searchOptions, 0, 50)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, dashboard := range dashboards.Values {
log.Printf("Dashboard Name: %v", dashboard.Name)
log.Printf("Dashboard ID: %v", dashboard.ID)
log.Printf("Dashboard View: %v", dashboard.View)
if dashboard.SharePermissions != nil {
for _, permission := range dashboard.SharePermissions {
log.Println(permission)
}
}
}
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
dashboard, response, err := jira.Dashboard.Get(context.Background(), "10001")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("Dashboard Name: %v", dashboard.Name)
log.Printf("Dashboard ID: %v", dashboard.ID)
log.Printf("Dashboard View: %v", dashboard.View)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
var payload = &models.DashboardPayloadScheme{
Name: "Team Tracking #1111",
Description: "",
SharePermissions: []*models.SharePermissionScheme{
{
Type: "project",
Project: &models.ProjectScheme{
ID: "10000",
},
Role: nil,
Group: nil,
},
{
Type: "group",
Group: &models.GroupScheme{Name: "jira-administrators"},
},
},
}
dashboard, response, err := jira.Dashboard.Update(context.Background(), "10001", payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("Dashboard Name: %v", dashboard.Name)
log.Printf("Dashboard ID: %v", dashboard.ID)
log.Printf("Dashboard View: %v", dashboard.View)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jiraCloud, err := v3.New(nil, host)
if err != nil {
return
}
jiraCloud.Auth.SetBasicAuth(mail, token)
jiraCloud.Auth.SetUserAgent("curl/7.54.0")
response, err := jiraCloud.Dashboard.Delete(context.Background(), "10003")
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jira, err := v3.New(nil, host)
if err != nil {
return
}
jira.Auth.SetBasicAuth(mail, token)
jira.Auth.SetUserAgent("curl/7.54.0")
var payload = &models.DashboardPayloadScheme{
Name: "Team Tracking #2 copy",
Description: "Description sample",
SharePermissions: []*models.SharePermissionScheme{
{
Type: "project",
Project: &models.ProjectScheme{
ID: "10000",
},
Role: nil,
Group: nil,
},
{
Type: "group",
Group: &models.GroupScheme{Name: "jira-administrators"},
},
},
}
dashboard, response, err := jira.Dashboard.Copy(context.Background(), "10001", payload)
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.Printf("Dashboard Name: %v", dashboard.Name)
log.Printf("Dashboard ID: %v", dashboard.ID)
log.Printf("Dashboard View: %v", dashboard.View)
}
A comment is a piece of text that can be added to an issue to provide additional information or to update the issue's status. Comments can be added by users who have permission to view and edit the issue, and can be used for a variety of purposes, such as:
Providing context or additional details about an issue.
Sharing progress or updates on the issue's status.
Asking questions or requesting feedback from other team members.
Acknowledging or responding to other comments or feedback.
Notifying other users of relevant information or changes.
Mention your teammates: If you need someone to know about a comment, you can mention them in it. Type @ followed by their name, then choose the right person from the list. The person you mention will be notified about your comment and can quickly jump to the issue to see what's happening.
Apply comment permissions: If your comment is only meant for a specific Jira group or project role, comment permissions let you restrict your comments to the appropriate audience. When writing your comment, click the lock icon under it and choose a Jira group or project role to restrict it to.
GET /rest/api/{2-3}/issue/{issueIdOrKey}/comment
Returns all comments for an issue.
GET /rest/api/{2-3}/issue/{issueIdOrKey}/comment/{id}
Returns a comment.
DELETE /rest/api/{2-3}/issue/{issueIdOrKey}/comment/{id}
Deletes a comment.
POST /rest/api/{2-3}/issue/{issueIdOrKey}/comment
Adds a comment to an issue.
The Atlassian Document Format (ADF) represents rich text stored in Atlassian products. For example, in Jira Cloud platform, the text in issue comments and in textarea
custom fields is stored as ADF, here's a bundle of examples you can use in order to create custom body messages.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/v2/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassianV2, err := v2.New(nil, host)
if err != nil {
return
}
atlassianV2.Auth.SetBasicAuth(mail, token)
richTextComments, response, err := atlassianV2.Issue.Comment.Gets(context.Background(), "KP-2", "", nil, 0, 50)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, comment := range richTextComments.Comments {
log.Println(comment.ID, comment.Created, comment.Body)
}
atlassianV3, err := v3.New(nil, host)
if err != nil {
return
}
atlassianV3.Auth.SetBasicAuth(mail, token)
adfComments, response, err := atlassianV3.Issue.Comment.Gets(context.Background(), "KP-2", "", nil, 0, 50)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, adfComment := range adfComments.Comments {
log.Println(adfComment.Body.Type)
}
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
comment, response, err := atlassian.Issue.Comment.Get(context.Background(), "KP-2", "10011")
if err != nil {
log.Fatal(err)
}
log.Println(response.Endpoint)
log.Println(comment.ID, comment.Created)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Issue.Comment.Delete(context.Background(), "KP-2", "10011")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
payload := &models.CommentPayloadSchemeV2{
Body: "test",
}
newComment, response, err := atlassian.Issue.Comment.Add(context.Background(), "KP-2", payload, nil)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(newComment.ID)
}
commentBody := jira.CommentNodeScheme{}
commentBody.Version = 1
commentBody.Type = "doc"
//Append Header
commentBody.AppendNode(&jira.CommentNodeScheme{
Type: "heading",
Attrs: map[string]interface{}{"level": 1},
Content: []*jira.CommentNodeScheme{
{
Type: "text",
Text: "Header 1",
},
},
})
//Append Lorem text
commentBody.AppendNode(&jira.CommentNodeScheme{
Type: "paragraph",
Content: []*jira.CommentNodeScheme{
{
Type: "text",
Text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore " +
"et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip " +
"ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore " +
"eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui " +
"officia deserunt mollit anim id est laborum",
},
},
})
//Append Nested Panel Data
commentBody.AppendNode(&jira.CommentNodeScheme{
Type: "panel",
Attrs: map[string]interface{}{"panelType":"note"},
Content: []*jira.CommentNodeScheme{
{
Type: "paragraph",
Content: []*jira.CommentNodeScheme{
{
Type: "text",
Text: "Excepteur ",
Marks: []*jira.MarkScheme{
{Type: "textColor", Attrs: map[string]interface{}{"color":"#6554c0"}},
},
},
{
Type: "text",
Text: "sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum",
},
},
},
},
})
//Append Heading Title
commentBody.AppendNode(&jira.CommentNodeScheme{
Type: "heading",
Attrs: map[string]interface{}{"level": 2},
Content: []*jira.CommentNodeScheme{
{
Type: "text",
Text: "Links",
},
},
})
//Append bulletList
commentBody.AppendNode(&jira.CommentNodeScheme{
Type: "bulletList",
Content: []*jira.CommentNodeScheme{
{
Type: "listItem",
Content: []*jira.CommentNodeScheme{
{
Type: "paragraph",
Content: []*jira.CommentNodeScheme{
{
Type: "text",
Text: "Google.com",
Marks: []*jira.MarkScheme{
{
Type: "link",
Attrs: map[string]interface{}{"href": "https://www.google.com/"},
},
},
},
},
},
},
},
{
Type: "listItem",
Content: []*jira.CommentNodeScheme{
{
Type: "paragraph",
Content: []*jira.CommentNodeScheme{
{
Type: "text",
Text: "Facebook.com",
Marks: []*jira.MarkScheme{
{
Type: "link",
Attrs: map[string]interface{}{"href": "https://www.facebook.com/"},
},
},
},
},
},
},
},
},
})
commentBody := jira.CommentNodeScheme{}
commentBody.Version = 1
commentBody.Type = "doc"
//Create the Tables Headers
tableHeaders := &jira.CommentNodeScheme{
Type: "tableRow",
Content: []*jira.CommentNodeScheme{
{
Type: "tableHeader",
Content: []*jira.CommentNodeScheme{
{
Type: "paragraph",
Content: []*jira.CommentNodeScheme{
{
Type: "text",
Text: "Header 1",
Marks: []*jira.MarkScheme{
{
Type: "strong",
},
},
},
},
},
},
},
{
Type: "tableHeader",
Content: []*jira.CommentNodeScheme{
{
Type: "paragraph",
Content: []*jira.CommentNodeScheme{
{
Type: "text",
Text: "Header 2",
Marks: []*jira.MarkScheme{
{
Type: "strong",
},
},
},
},
},
},
},
{
Type: "tableHeader",
Content: []*jira.CommentNodeScheme{
{
Type: "paragraph",
Content: []*jira.CommentNodeScheme{
{
Type: "text",
Text: "Header 3",
Marks: []*jira.MarkScheme{
{
Type: "strong",
},
},
},
},
},
},
},
},
}
row1 := &jira.CommentNodeScheme{
Type: "tableRow",
Content: []*jira.CommentNodeScheme{
{
Type: "tableCell",
Content: []*jira.CommentNodeScheme{
{
Type: "paragraph",
Content: []*jira.CommentNodeScheme{
{Type: "text", Text: "Row 00"},
},
},
},
},
{
Type: "tableCell",
Content: []*jira.CommentNodeScheme{
{
Type: "paragraph",
Content: []*jira.CommentNodeScheme{
{Type: "text", Text: "Row 01"},
},
},
},
},
{
Type: "tableCell",
Content: []*jira.CommentNodeScheme{
{
Type: "paragraph",
Content: []*jira.CommentNodeScheme{
{Type: "text", Text: "Row 02"},
},
},
},
},
},
}
row2 := &jira.CommentNodeScheme{
Type: "tableRow",
Content: []*jira.CommentNodeScheme{
{
Type: "tableCell",
Content: []*jira.CommentNodeScheme{
{
Type: "paragraph",
Content: []*jira.CommentNodeScheme{
{Type: "text", Text: "Row 10"},
},
},
},
},
{
Type: "tableCell",
Content: []*jira.CommentNodeScheme{
{
Type: "paragraph",
Content: []*jira.CommentNodeScheme{
{Type: "text", Text: "Row 11"},
},
},
},
},
{
Type: "tableCell",
Content: []*jira.CommentNodeScheme{
{
Type: "paragraph",
Content: []*jira.CommentNodeScheme{
{Type: "text", Text: "Row 12"},
},
},
},
},
},
}
commentBody.AppendNode(&jira.CommentNodeScheme{
Type: "table",
Attrs: map[string]interface{}{"isNumberColumnEnabled": false, "layout": "default"},
Content: []*jira.CommentNodeScheme{tableHeaders, row1, row2},
})
This resource represents issue type screen schemes.
GET /rest/api/{2-3}/issuetypescreenscheme
Returns a paginated list of issue type screen schemes. Only issue type screen schemes used in classic projects are returned.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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)
screenSchemes, response, err := atlassian.Issue.Type.ScreenScheme.Gets(context.Background(), []int{10001, 10002}, 0, 50)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(screenSchemes)
for _, screenScheme := range screenSchemes.Values {
log.Println(screenScheme)
}
}
POST /rest/api/{2-3}/issuetypescreenscheme
Creates an issue-type screen scheme.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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.IssueTypeScreenSchemePayloadScheme{
Name: "FX 2 Issue Type Screen Scheme",
IssueTypeMappings: []*models.IssueTypeScreenSchemeMappingPayloadScheme{
{
IssueTypeID: "default",
ScreenSchemeID: "10000",
},
{
IssueTypeID: "10004", // Bug
ScreenSchemeID: "10002",
},
},
}
issueTypeScreenSchemeID, response, err := atlassian.Issue.Type.ScreenScheme.Create(context.Background(), &payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(issueTypeScreenSchemeID)
}
GET /rest/api/{2-3}/issuetypescreenscheme/mapping
Returns a paginated list of issue-type screen scheme items. Only issue type screen schemes used in classic projects are returned.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
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)
mapping, response, err := atlassian.Issue.Type.ScreenScheme.Mapping(context.Background(), nil, 0, 50)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, item := range mapping.Values {
log.Println(item)
}
}
PUT /rest/api/{2-3}/issuetypescreenscheme/project
Assigns an issue-type screen scheme to a project.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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 (
issueTypeScreenSchemeID = "10002"
projectID = "10002"
)
response, err := atlassian.Issue.Type.ScreenScheme.Assign(context.Background(), issueTypeScreenSchemeID, projectID)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
GET /rest/api/{2-3}/issuetypescreenscheme/project
Returns a paginated list of issue type screen schemes and, for each issue type screen scheme, a list of the projects that use it. Only issue type screen schemes used in classic projects are returned.
CREATE THE CODE SAMPLE
PUT /rest/api/{2-3}/issuetypescreenscheme/{issueTypeScreenSchemeId}
Updates an issue type screen scheme.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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 (
issueTypeScreenSchemeID = "10002"
name = "FX Issue Type Screen Scheme - UPDATED"
description = ""
)
response, err := atlassian.Issue.Type.ScreenScheme.Update(context.Background(), issueTypeScreenSchemeID, name, description)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
DELETE /rest/api/{2-3}/issuetypescreenscheme/{issueTypeScreenSchemeId}
Deletes an issue type screen scheme.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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 (
issueTypeScreenSchemeID = "10004"
)
response, err := atlassian.Issue.Type.ScreenScheme.Delete(context.Background(), issueTypeScreenSchemeID)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
PUT /rest/api/{2-3}/issuetypescreenscheme/{issueTypeScreenSchemeId}/mapping
Appends issue type to screen scheme mappings to an issue type screen scheme.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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)
var payload = &models.IssueTypeScreenSchemePayloadScheme{
IssueTypeMappings: []*models.IssueTypeScreenSchemeMappingPayloadScheme{
{
IssueTypeID: "10000", // Epic Issue Type
ScreenSchemeID: "10002",
},
{
IssueTypeID: "10002", // Task Issue Type
ScreenSchemeID: "10002",
},
},
}
var issueTypeScreenSchemeID = "10005"
response, err := atlassian.Issue.Type.ScreenScheme.Append(context.Background(), issueTypeScreenSchemeID, payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
PUT /rest/api/{2-3}/issuetypescreenscheme/{issueTypeScreenSc}/mapping/default
Updates the default screen scheme of an issue-type screen scheme. The default screen scheme is used for all unmapped issue types.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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 (
issueTypeScreenSchemeID = "10005"
screenSchemeID = "10002"
)
response, err := atlassian.Issue.Type.ScreenScheme.UpdateDefault(context.Background(), issueTypeScreenSchemeID, screenSchemeID)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
POST /rest/api/{2-3}/issuetypescreenscheme/{issueTypeScreenSc}/mapping/remove
Removes issue type to screen scheme mappings from an issue type screen scheme.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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 (
issueTypeScreenSchemeID = "10005"
issueTypesIDs = []string{"10002", "10000"}
)
response, err := atlassian.Issue.Type.ScreenScheme.Remove(context.Background(), issueTypeScreenSchemeID, issueTypesIDs)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
GET /rest/api/{2-3}/issuetypescreenscheme/{issueTypeScreenSchemeId}/project
Returns a paginated list of projects associated with an issue-type screen scheme. Only company-managed projects associated with an issue-type screen scheme are returned.
CREATE THE CODE SAMPLE
GET /rest/api/{2-3}/screens/{screenId}/tabs
Returns the list of tabs for a screen.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 (
screenID = 10000
projectKey = "KP"
)
tabs, response, err := atlassian.Screen.Tab.Gets(context.Background(), screenID, projectKey)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, tab := range tabs {
log.Println(tab.ID, tab.Name)
}
}
POST /rest/api/{2-3}/screens/{screenId}/tabs
Creates a tab for a screen.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 (
screenID = 10000
tabName = "Development"
)
newTab, response, err := atlassian.Screen.Tab.Create(context.Background(), screenID, tabName)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("The new tab has been created: %v", newTab.ID)
}
PUT /rest/api/{2-3}/screens/{screenId}/tabs/{tabId}
Updates the name of a screen tab.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 (
screenID = 10000
tabID = 10019
tabNameUpdated = "Time tracking"
)
tabUpdated, response, err := atlassian.Screen.Tab.Update(context.Background(), screenID, tabID, tabNameUpdated)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("The tab has been updated: %v", tabUpdated.ID)
}
DELETE /rest/api/{2-3}/screens/{screenId}/tabs/{tabId}
Deletes a screen tab.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 (
screenID = 10000
tabID = 10019
)
response, err := atlassian.Screen.Tab.Delete(context.Background(), screenID, tabID)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}
POST /rest/api/{2-3}/screens/{screenId}/tabs/{tabId}/move/{pos}
Moves a screen tab.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 (
screenID = 10000
tabID = 1
tabPosition = 0
)
response, err := atlassian.Screen.Tab.Move(context.Background(), screenID, tabID, tabPosition)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}
The Issue field configuration schemes let you apply a field configuration to all issues of a certain type. When you want to change the fields that appear on all Bug issue types in a certain project, you can do so by simply configuring the associated field configuration scheme. You can also save time by reusing the same field configuration for issue types across multiple projects.
GET /rest/api/{2-3}/fieldconfigurationscheme
Returns a list of field configuration schemes.
POST /rest/api/{2-3}/fieldconfigurationscheme
Creates a field configuration scheme.
GET /rest/api/{2-3}/fieldconfigurationscheme/mapping
Returns a list of field configuration issue type items.
GET /rest/api/{2-3}/fieldconfigurationscheme/project
Returns a list of field configuration schemes and, for each scheme, a list of the projects that use it.
The list is sorted by field configuration scheme ID. The first item contains the list of project IDs assigned to the default field configuration scheme.
PUT /rest/api/{2-3}/fieldconfigurationscheme/project
Assigns a field configuration scheme to a project. If the field configuration scheme ID is null
, the operation assigns the default field configuration scheme.
PUT /rest/api/{2-3}/fieldconfigurationscheme/{id}
Updates a field configuration scheme.
DELETE /rest/api/{2-3}/fieldconfigurationscheme/{id}
Deletes a field configuration scheme.
PUT /rest/api/{2-3}/fieldconfigurationscheme/{id}/mapping
Assigns issue types to field configurations on field configuration scheme.
POST /rest/api/{2-3}/fieldconfigurationscheme/{id}/mapping/delete
Removes issue types from the field configuration scheme.
package models
// CustomerPageScheme represents a page of customers in a system.
type CustomerPageScheme struct {
Expands []interface{} `json:"_expands,omitempty"` // Additional data related to the customers.
Size int `json:"size,omitempty"` // The number of customers on the page.
Start int `json:"start,omitempty"` // The index of the first customer on the page.
Limit int `json:"limit,omitempty"` // The maximum number of customers that can be on the page.
IsLastPage bool `json:"isLastPage,omitempty"` // Indicates if this is the last page of customers.
Links *CustomerPageLinksScheme `json:"_links,omitempty"` // Links related to the page of customers.
Values []*CustomerScheme `json:"values,omitempty"` // The customers on the page.
}
// CustomerPageLinksScheme represents links related to a page of customers.
type CustomerPageLinksScheme struct {
Base string `json:"base,omitempty"` // The base URL for the links.
Context string `json:"context,omitempty"` // The context for the links.
Next string `json:"next,omitempty"` // The URL for the next page of customers.
Prev string `json:"prev,omitempty"` // The URL for the previous page of customers.
}
// CustomerScheme represents a customer in a system.
type CustomerScheme struct {
AccountID string `json:"accountId,omitempty"` // The account ID of the customer.
Name string `json:"name,omitempty"` // The name of the customer.
Key string `json:"key,omitempty"` // The key of the customer.
EmailAddress string `json:"emailAddress,omitempty"` // The email address of the customer.
DisplayName string `json:"displayName,omitempty"` // The display name of the customer.
Active bool `json:"active,omitempty"` // Indicates if the customer is active.
TimeZone string `json:"timeZone,omitempty"` // The time zone of the customer.
Links *CustomerLinkScheme `json:"_links,omitempty"` // Links related to the customer.
}
// CustomerLinkScheme represents links related to a customer.
type CustomerLinkScheme struct {
JiraREST string `json:"jiraRest"` // The Jira REST API link for the customer.
AvatarURLs *AvatarURLScheme `json:"avatarUrls"` // The URLs for the customer's avatars.
Self string `json:"self"` // The URL for the customer itself.
}
package main
import (
"context"
"fmt"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
fieldSchemes, response, err := atlassian.Issue.Field.Configuration.Scheme.Gets(context.Background(), nil, 0, 50)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, scheme := range fieldSchemes.Values {
fmt.Println("-------------------")
fmt.Println("ID ", scheme.ID)
fmt.Println("Name ", scheme.Name)
fmt.Println("Description ", scheme.Description)
}
}
package main
import (
"context"
"fmt"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
schemeCreated, response, err := atlassian.Issue.Field.Configuration.Scheme.Create(context.Background(), "test", "")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
fmt.Println("ID ", schemeCreated.ID)
fmt.Println("Name ", schemeCreated.Name)
fmt.Println("Description ", schemeCreated.Description)
}
package main
import (
"context"
"fmt"
v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
items, response, err := atlassian.Issue.Field.Configuration.Scheme.Mapping(context.Background(), []int{10000}, 0, 50)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, item := range items.Values {
fmt.Println(item)
}
}
package main
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
items, response, err := atlassian.Issue.Field.Configuration.Scheme.Project(context.Background(), []int{10003}, 0, 50)
if err != nil {
log.Println(response.Bytes.String())
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, item := range items.Values {
fmt.Println(item.ProjectIds)
fmt.Println(item.FieldConfigurationScheme)
}
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
payload := &models.FieldConfigurationSchemeAssignPayload{
FieldConfigurationSchemeID: "10000",
ProjectID: "10003",
}
response, err := atlassian.Issue.Field.Configuration.Scheme.Assign(context.Background(), payload)
if err != nil {
log.Println(response.Bytes.String())
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Issue.Field.Configuration.Scheme.Update(context.Background(),10002, "test updated", "")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Issue.Field.Configuration.Scheme.Delete(context.Background(),10002)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
payload := &models.FieldConfigurationToIssueTypeMappingPayloadScheme{
Mappings: []*models.FieldConfigurationToIssueTypeMappingScheme{
{
IssueTypeID: "10002",
FieldConfigurationID: "10003",
},
},
}
response, err := atlassian.Issue.Field.Configuration.Scheme.Link(context.Background(),10003, payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Issue.Field.Configuration.Scheme.Unlink(context.Background(),10003, []string{"10002"})
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
POST /rest/api/{2-3}/project
Creates a project based on a project type template
const (
BusinessContentManagement = "com.atlassian.jira-core-project-templates:jira-core-simplified-content-management"
BusinessDocumentApproval = "com.atlassian.jira-core-project-templates:jira-core-simplified-document-approval"
BusinessLeadTracking = "com.atlassian.jira-core-project-templates:jira-core-simplified-lead-tracking"
BusinessProcessControl = "com.atlassian.jira-core-project-templates:jira-core-simplified-process-control"
BusinessProcurement = "com.atlassian.jira-core-project-templates:jira-core-simplified-procurement"
BusinessProjectManagement = "com.atlassian.jira-core-project-templates:jira-core-simplified-project-management"
BusinessRecruitment = "com.atlassian.jira-core-project-templates:jira-core-simplified-recruitment"
BusinessTaskTracking = "com.atlassian.jira-core-project-templates:jira-core-simplified-task-tracking"
ITSMServiceDesk = "com.atlassian.servicedesk:simplified-it-service-desk"
ITSMInternalServiceDesk = "com.atlassian.servicedesk:simplified-internal-service-desk"
ITSMExternalServiceDesk = "com.atlassian.servicedesk:simplified-external-service-desk"
SoftwareTeamManagedKanban = "com.pyxis.greenhopper.jira:gh-simplified-agility-kanban"
SoftwareTeamManagedScrum = "com.pyxis.greenhopper.jira:gh-simplified-agility-scrum"
SoftwareCompanyManagedKanban = "com.pyxis.greenhopper.jira:gh-simplified-kanban-classic"
SoftwareCompanyManagedScrum = "com.pyxis.greenhopper.jira:gh-simplified-scrum-classic"
)
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.ProjectPayloadScheme{
NotificationScheme: 10021,
Description: "Example Project description",
LeadAccountID: "5b86be50b8e3cb5895860d6d",
URL: "https://atlassian.com",
ProjectTemplateKey: "com.pyxis.greenhopper.jira:gh-simplified-agility-kanban",
AvatarID: 10200,
IssueSecurityScheme: 10001,
Name: "Project DUMMY #3",
PermissionScheme: 10011,
AssigneeType: "PROJECT_LEAD",
ProjectTypeKey: "software",
Key: "DUMMY3",
CategoryID: 10120,
}
newProject, response, err := atlassian.Project.Create(context.Background(), payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println("-------------------")
log.Println(newProject.ID)
log.Println(newProject.Self)
log.Println(newProject.Key)
log.Println("-------------------")
}
GET /rest/api/{2-3}/project/search
Returns a paginated list of projects visible to the user.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
options := &models.ProjectSearchOptionsScheme{
OrderBy: "issueCount",
Action: "browse",
Expand: []string{"insight", "lead", "issueTypes", "projectKeys", "description"},
}
var (
startAt = 0
maxResults = 50
)
projects, response, err := atlassian.Project.Search(context.Background(), options, startAt, maxResults)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, project := range projects.Values {
log.Println(project)
}
}
GET /rest/api/{2-3}/project/{projectIdOrKey}
Returns the project details
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
project, response, err := atlassian.Project.Get(context.Background(), "KP", []string{"issueTypes"})
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(project)
for _, issueType := range project.IssueTypes {
log.Println(issueType.Name)
}
}
PUT /rest/api/{2-3}/project/{projectIdOrKey}
Updates the project details of a project.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.ProjectUpdateScheme{
Description: "Example Project description",
}
projectUpdated, response, err := atlassian.Project.Update(context.Background(), "KP", payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(projectUpdated)
}
DELETE /rest/api/{2-3}/project/{projectIdOrKey}
Deletes a project.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jiraCloud, err := v2.New(nil, host)
if err != nil {
return
}
jiraCloud.Auth.SetBasicAuth(mail, token)
jiraCloud.Auth.SetUserAgent("curl/7.54.0")
response, err := jiraCloud.Project.Delete(context.Background(), "DUM", true)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
POST /rest/api/{2-3}/project/{projectIdOrKey}/archive
Archives a project. Archived projects cannot be deleted. To delete an archived project, restore the project and then delete it. To restore a project, use the Jira UI.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.Project.Archive(context.Background(), "PK")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
POST /rest/api/{2-3}/project/{projectIdOrKey}/delete
Deletes a project asynchronously.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jiraCloud, err := v2.New(nil, host)
if err != nil {
return
}
jiraCloud.Auth.SetBasicAuth(mail, token)
jiraCloud.Auth.SetUserAgent("curl/7.54.0")
task, response, err := jiraCloud.Project.DeleteAsynchronously(context.Background(), "DUM")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(task.ID)
log.Println(task)
}
POST /rest/api/{2-3}/project/{projectIdOrKey}/restore
Restores a project from the Jira recycle bin.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
jiraCloud, err := v2.New(nil, host)
if err != nil {
return
}
jiraCloud.Auth.SetBasicAuth(mail, token)
jiraCloud.Auth.SetUserAgent("curl/7.54.0")
projectRestored, response, err := jiraCloud.Project.Restore(context.Background(), "DUM")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(projectRestored)
}
GET /rest/api/{2-3}/project/{projectIdOrKey}/statuses
Returns the valid statuses for a project. The statuses are grouped by issue type, as each project has a set of valid issue types and each issue type has a set of valid statuses.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
statuses, response, err := atlassian.Project.Statuses(context.Background(), "KP")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, status := range statuses {
log.Println(status)
}
}
GET /rest/api/{2-3}/project/{projectKeyOrId}/notificationscheme
Gets a notification scheme associated with the project.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
notificationScheme, response, err := atlassian.Project.NotificationScheme(context.Background(), "KP", []string{"all"})
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(notificationScheme)
log.Println(notificationScheme.Name, notificationScheme.ID)
for _, event := range notificationScheme.NotificationSchemeEvents {
log.Println(event.Event.ID, event.Event.Name)
for index, notification := range event.Notifications {
log.Println(index, event.Event.Name, notification.ID, notification.NotificationType, notification.Parameter)
}
}
}
This resource represents issue type schemes in classic projects
GET /rest/api/{2-3}/issuetypescheme
Returns a paginated list of issue type schemes.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
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)
issueTypeSchemes, response, err := atlassian.Issue.Type.Scheme.Gets(context.Background(), nil, 0, 50)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, issueTypeScheme := range issueTypeSchemes.Values {
log.Println(issueTypeScheme)
}
}
POST /rest/api/{2-3}/issuetypescheme
Creates an issue type scheme.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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.IssueTypeSchemePayloadScheme{
DefaultIssueTypeID: "10001",
IssueTypeIds: []string{"10001", "10002", "10005"},
Name: "Kanban Issue Type Scheme 1",
Description: "A collection of issue types suited to use in a kanban style project.",
}
issueTypeSchemeID, response, err := atlassian.Issue.Type.Scheme.Create(context.Background(), &payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println("issueTypeSchemeID", issueTypeSchemeID)
}
GET /rest/api/{2-3}/issuetypescheme/mapping
Returns a paginated list of issue-type scheme items. Only issue type scheme items used in classic projects are returned.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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)
items, response, err := atlassian.Issue.Type.Scheme.Items(context.Background(), nil, 0, 50)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, item := range items.Values {
log.Println(item)
}
}
GET /rest/api/{2-3}/issuetypescheme/project
Returns a paginated list of issue type schemes and, for each issue type scheme, a list of the projects that use it. Only issue type schemes used in classic projects are returned.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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)
issueTypesSchemes, response, err := atlassian.Issue.Type.Scheme.Projects(context.Background(), []int{10000}, 0, 50)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, issueTypeScheme := range issueTypesSchemes.Values {
log.Println(issueTypeScheme.IssueTypeScheme.Name, issueTypeScheme.ProjectIds)
}
}
PUT /rest/api/{2-3}/issuetypescheme/project
Assigns an issue type scheme to a project. If any issues in the project are assigned issue types not present in the new scheme, the operation will fail.
To complete the assignment those issues must be updated to use issue types in the new scheme.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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.Issue.Type.Scheme.Assign(context.Background(), "schemeID", "projectID")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
PUT /rest/api/{2-3}/issuetypescheme/{issueTypeSchemeId}
Updates an issue type scheme.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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.IssueTypeSchemePayloadScheme{
Name: "Kanban Issue Type Scheme - UPDATED",
Description: "A collection of issue types suited to use in a kanban style project.- UPDATED",
}
response, err := atlassian.Issue.Type.Scheme.Update(context.Background(), 1000, &payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
DELETE /rest/api/{2-3}/issuetypescheme/{issueTypeSchemeId}
Deletes an issue type scheme. Only issue type schemes used in classic projects can be deleted. Any projects assigned to the scheme are reassigned to the default issue type scheme.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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.Issue.Type.Scheme.Delete(context.Background(), 1001)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
PUT /rest/api/{2-3}/issuetypescheme/{issueTypeSchemeId}/issuetype
Adds issue types to an issue type scheme. The added issue types are appended to the issue types list. If any of the issue types exist in the issue type scheme, the operation fails and no issue types are added.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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.Issue.Type.Scheme.Append(context.Background(), 10182, []int{10003, 10000})
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
DELETE /rest/api/{2-3}/issuetypescheme/{issueTypeSche}/issuetype/{issueType}
Removes an issue type from an issue type scheme.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/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.Issue.Type.Scheme.Remove(context.Background(), 10182, 10003)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
Not implemented, yet. Feel free to open a PR or issue
This resource represents the screens used to record issue details
GET /rest/api/{2-3}/field/{fieldId}/screens
Returns a list of the screens a field is used in.
GET /rest/api/{2-3}/screens
Returns a list of all screens or those specified by one or more screen IDs.
POST /rest/api/{2-3}/screens
Creates a screen with a default field tab.
POST /rest/api/{2-3}/screens/addToDefault/{fieldId}
Adds a field to the default tab of the default screen.
PUT /rest/api/{2-3}/screens/{screenId}
Updates a screen. Only screens used in classic projects can be updated.
DELETE /rest/api/{2-3}/screens/{screenId}
Deletes a screen. A screen cannot be deleted if it is used in a screen scheme, workflow, or workflow draft. Only screens used in classic projects can be deleted.
GET /rest/api/{2-3}/screens/{screenId}/availableFields
Returns the fields that can be added to a tab on a screen.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 (
fieldID = "customfield_10014"
startAt = 0
maxResult = 50
)
screens, response, err := atlassian.Screen.Fields(context.Background(), fieldID, startAt, maxResult)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, screen := range screens.Values {
log.Println(screen.ID, screen.Name, screen.Description)
}
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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 (
screenIDs = []int{10000}
startAt = 0
maxResults = 0
)
screens, response, err := atlassian.Screen.Gets(context.Background(), screenIDs, startAt, maxResults)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, screen := range screens.Values {
log.Println(screen.ID, screen.Name, screen.Description)
}
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
newScreen, response, err := atlassian.Screen.Create(context.Background(), "FX Screen", "sample description")
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("The new screen has been created with the ID %v", newScreen.ID)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.Screen.AddToDefault(context.Background(), "customfield_xxxx")
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
screenUpdated, response, err := atlassian.Screen.Update(context.Background(), 10015, "AX Screen", "")
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(screenUpdated)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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.Screen.Delete(context.Background(), 10015)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/v2/jira/v3"
"github.com/ctreminiom/go-atlassian/v2/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)
fields, response, err := atlassian.Screen.Available(context.Background(), 10000)
if err != nil {
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, field := range fields {
log.Println(field.ID, field.Name)
}
}
GET /rest/api/{2-3}/issue/{issueIdOrKey}/worklog
Returns worklogs for an issue, starting from the oldest worklog or from the worklog started on or after a date and time.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
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 (
ctx = context.Background()
key = "KP-1"
maxResult = 50
after = 0
expand = []string{""}
)
worklogs, response, err := atlassian.Issue.Worklog.Issue(ctx, key, 0, maxResult, after, expand)
if err != nil {
log.Fatal(err)
}
log.Println(response.Endpoint, response.Code)
for _, worklog := range worklogs.Worklogs {
log.Println(worklog.ID)
}
}
POST /rest/api/{2-3}/issue/{issueIdOrKey}/worklog
Adds a worklog to an issue.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
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)
// V3 payload
/*
// Comment worklog
commentBody := models.CommentNodeScheme{}
commentBody.Version = 1
commentBody.Type = "doc"
//Create the Tables Headers
tableHeaders := &v3.CommentNodeScheme{
Type: "tableRow",
Content: []*v3.CommentNodeScheme{
{
Type: "tableHeader",
Content: []*v3.CommentNodeScheme{
{
Type: "paragraph",
Content: []*v3.CommentNodeScheme{
{
Type: "text",
Text: "Header 1",
Marks: []*v3.MarkScheme{
{
Type: "strong",
},
},
},
},
},
},
},
{
Type: "tableHeader",
Content: []*v3.CommentNodeScheme{
{
Type: "paragraph",
Content: []*v3.CommentNodeScheme{
{
Type: "text",
Text: "Header 2",
Marks: []*v3.MarkScheme{
{
Type: "strong",
},
},
},
},
},
},
},
{
Type: "tableHeader",
Content: []*v3.CommentNodeScheme{
{
Type: "paragraph",
Content: []*v3.CommentNodeScheme{
{
Type: "text",
Text: "Header 3",
Marks: []*v3.MarkScheme{
{
Type: "strong",
},
},
},
},
},
},
},
},
}
row1 := &v3.CommentNodeScheme{
Type: "tableRow",
Content: []*v3.CommentNodeScheme{
{
Type: "tableCell",
Content: []*v3.CommentNodeScheme{
{
Type: "paragraph",
Content: []*v3.CommentNodeScheme{
{Type: "text", Text: "Row 00"},
},
},
},
},
{
Type: "tableCell",
Content: []*v3.CommentNodeScheme{
{
Type: "paragraph",
Content: []*v3.CommentNodeScheme{
{Type: "text", Text: "Row 01"},
},
},
},
},
{
Type: "tableCell",
Content: []*v3.CommentNodeScheme{
{
Type: "paragraph",
Content: []*v3.CommentNodeScheme{
{Type: "text", Text: "Row 02"},
},
},
},
},
},
}
row2 := &v3.CommentNodeScheme{
Type: "tableRow",
Content: []*v3.CommentNodeScheme{
{
Type: "tableCell",
Content: []*v3.CommentNodeScheme{
{
Type: "paragraph",
Content: []*v3.CommentNodeScheme{
{Type: "text", Text: "Row 10"},
},
},
},
},
{
Type: "tableCell",
Content: []*v3.CommentNodeScheme{
{
Type: "paragraph",
Content: []*v3.CommentNodeScheme{
{Type: "text", Text: "Row 11"},
},
},
},
},
{
Type: "tableCell",
Content: []*v3.CommentNodeScheme{
{
Type: "paragraph",
Content: []*v3.CommentNodeScheme{
{Type: "text", Text: "Row 12"},
},
},
},
},
},
}
commentBody.AppendNode(&v3.CommentNodeScheme{
Type: "table",
Attrs: map[string]interface{}{"isNumberColumnEnabled": false, "layout": "default"},
Content: []*v3.CommentNodeScheme{tableHeaders, row1, row2},
})
var options = &v3.WorklogOptionsScheme{
Notify: true,
AdjustEstimate: "auto",
ReduceBy: "3h",
//OverrideEditableFlag: true,
Expand: []string{"expand", "properties"},
Payload: &v3.WorklogPayloadScheme{
Comment: &commentBody,
Visibility: &jira.IssueWorklogVisibilityScheme{
Type: "group",
Value: "jira-users",
},
Started: "2021-07-16T07:01:10.774+0000",
TimeSpentSeconds: 12000,
},
}
*/
options := &models.WorklogOptionsScheme{
Notify: false,
AdjustEstimate: "",
NewEstimate: "",
ReduceBy: "",
OverrideEditableFlag: false,
Expand: nil,
}
payload := &models.WorklogPayloadSchemeV2{
Comment: &models.CommentPayloadSchemeV2{
Visibility: nil,
Body: "test",
},
Visibility: nil,
Started: "2021-07-16T07:01:10.774+0000",
TimeSpentSeconds: 12000,
}
worklog, response, err := atlassian.Issue.Worklog.Add(context.Background(), "KP-1", payload, options)
if err != nil {
log.Println(response.Endpoint, response.Code)
log.Fatal(err)
}
log.Println(response.Endpoint, response.Code)
log.Println(worklog.ID, worklog.IssueID)
}
GET /rest/api/{2-3}/issue/{issueIdOrKey}/worklog/{id}
Returns a worklog.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
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 (
ctx = context.Background()
key = "KP-1"
worklogID = "10000"
expand = []string{"all"}
)
worklog, response, err := atlassian.Issue.Worklog.Get(ctx, key, worklogID, expand)
if err != nil {
log.Fatal(err)
}
log.Println(response.Endpoint, response.Code)
log.Println(worklog.ID, worklog.Self)
}
PUT /rest/api/{2-3}/issue/{issueIdOrKey}/worklog/{id}
Updates a worklog.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
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)
/*
// Comment worklog
commentBody := v3.CommentNodeScheme{}
commentBody.Version = 1
commentBody.Type = "doc"
//Create the Tables Headers
tableHeaders := &v3.CommentNodeScheme{
Type: "tableRow",
Content: []*v3.CommentNodeScheme{
{
Type: "tableHeader",
Content: []*v3.CommentNodeScheme{
{
Type: "paragraph",
Content: []*v3.CommentNodeScheme{
{
Type: "text",
Text: "Header 1",
Marks: []*v3.MarkScheme{
{
Type: "strong",
},
},
},
},
},
},
},
{
Type: "tableHeader",
Content: []*v3.CommentNodeScheme{
{
Type: "paragraph",
Content: []*v3.CommentNodeScheme{
{
Type: "text",
Text: "Header 2",
Marks: []*v3.MarkScheme{
{
Type: "strong",
},
},
},
},
},
},
},
{
Type: "tableHeader",
Content: []*v3.CommentNodeScheme{
{
Type: "paragraph",
Content: []*v3.CommentNodeScheme{
{
Type: "text",
Text: "Header 3",
Marks: []*v3.MarkScheme{
{
Type: "strong",
},
},
},
},
},
},
},
},
}
row1 := &v3.CommentNodeScheme{
Type: "tableRow",
Content: []*v3.CommentNodeScheme{
{
Type: "tableCell",
Content: []*v3.CommentNodeScheme{
{
Type: "paragraph",
Content: []*v3.CommentNodeScheme{
{Type: "text", Text: "Row 00"},
},
},
},
},
{
Type: "tableCell",
Content: []*v3.CommentNodeScheme{
{
Type: "paragraph",
Content: []*v3.CommentNodeScheme{
{Type: "text", Text: "Row 01"},
},
},
},
},
{
Type: "tableCell",
Content: []*v3.CommentNodeScheme{
{
Type: "paragraph",
Content: []*v3.CommentNodeScheme{
{Type: "text", Text: "Row 02"},
},
},
},
},
},
}
row2 := &v3.CommentNodeScheme{
Type: "tableRow",
Content: []*v3.CommentNodeScheme{
{
Type: "tableCell",
Content: []*v3.CommentNodeScheme{
{
Type: "paragraph",
Content: []*v3.CommentNodeScheme{
{Type: "text", Text: "Row 10"},
},
},
},
},
{
Type: "tableCell",
Content: []*v3.CommentNodeScheme{
{
Type: "paragraph",
Content: []*v3.CommentNodeScheme{
{Type: "text", Text: "Row 11"},
},
},
},
},
{
Type: "tableCell",
Content: []*v3.CommentNodeScheme{
{
Type: "paragraph",
Content: []*v3.CommentNodeScheme{
{Type: "text", Text: "Row 12"},
},
},
},
},
},
}
commentBody.AppendNode(&v3.CommentNodeScheme{
Type: "table",
Attrs: map[string]interface{}{"isNumberColumnEnabled": false, "layout": "default"},
Content: []*v3.CommentNodeScheme{tableHeaders, row1, row2},
})
var options = &v3.WorklogOptionsScheme{
Notify: true,
AdjustEstimate: "auto",
ReduceBy: "3h",
//OverrideEditableFlag: true,
Expand: []string{"expand", "properties"},
Payload: &v3.WorklogPayloadScheme{
Comment: &commentBody,
Visibility: &jira.IssueWorklogVisibilityScheme{
Type: "group",
Value: "jira-users",
},
Started: "2021-07-16T07:01:10.774+0000",
TimeSpentSeconds: 12000,
},
}
*/
options := &models.WorklogOptionsScheme{
Notify: true,
AdjustEstimate: "auto",
ReduceBy: "3h",
OverrideEditableFlag: false,
Expand: nil,
}
payload := &models.WorklogPayloadSchemeV2{
Comment: &models.CommentPayloadSchemeV2{
Visibility: nil,
Body: "test",
},
Visibility: nil,
Started: "2021-07-16T07:01:10.774+0000",
TimeSpentSeconds: 12000,
}
worklog, response, err := atlassian.Issue.Worklog.Update(context.Background(), "KP-1", "10000", payload, options)
if err != nil {
log.Println(response.Endpoint, response.Code)
log.Fatal(err)
}
log.Println(response.Endpoint, response.Code)
log.Println(worklog.ID, worklog.IssueID)
}
DELETE /rest/api/{2-3}/issue/{issueIdOrKey}/worklog/{id}
Deletes a worklog from an issue.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
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.Issue.Worklog.Delete(context.Background(), "KP-1", "10000", nil)
if err != nil {
log.Println(response.Endpoint, response.Code)
log.Fatal(err)
}
log.Println(response.Endpoint, response.Code)
}
GET /rest/api/{2-3}/worklog/deleted
Returns a list of IDs and delete timestamps for worklogs deleted after a date and time.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
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)
result, response, err := atlassian.Issue.Worklog.Deleted(context.Background(), 0)
if err != nil {
log.Println(response.Endpoint, response.Code)
log.Fatal(err)
}
log.Println(response.Endpoint, response.Code)
log.Println(result)
}
POST /rest/api/{2-3}/worklog/list
Returns worklog details for a list of worklog IDs.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
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 (
worklogsIDs = []int{10000}
expand = []string{"all"}
)
worklogs, response, err := atlassian.Issue.Worklog.Gets(context.Background(), worklogsIDs, expand)
if err != nil {
log.Fatal(err)
}
log.Println(response.Endpoint, response.Code)
for _, worklog := range worklogs {
log.Println(worklog)
}
}
GET /rest/api/{2-3}/worklog/updated
Returns a list of IDs and update timestamps for worklogs updated after a date and time.
This resource is paginated, with a limit of 1000 worklogs per page. Each page lists worklogs from oldest to youngest. If the number of items in the date range exceeds 1000, until
indicates the timestamp of the youngest item on the page. Also, nextPage
provides the URL for the next page of worklogs. The lastPage
parameter is set to true on the last page of worklogs.c
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
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)
result, response, err := atlassian.Issue.Worklog.Updated(context.Background(), 0, nil)
if err != nil {
log.Println(response.Endpoint, response.Code)
log.Fatal(err)
}
log.Println(response.Endpoint, response.Code)
log.Println(result)
}
The Jira Field Context Configurations define the scope of custom fields within Jira. They determine where and how a custom field can be used within Jira, such as in which projects, issue types, and screens the field should be available. Field Context Configurations are used to ensure that the right data is captured and displayed in Jira, and that users are not presented with irrelevant fields.
GET /rest/api/{2-3}/field/{fieldId}/context
Returns a list of
for a custom field. Contexts can be returned as follows:
With no other parameters set, all contexts.
By defining id
only, all contexts from the list of IDs.
By defining isAnyIssueType
, limit the list of contexts returned to either those that apply to all issue types (true) or those that apply to only a subset of issue types (false)
By defining isGlobalContext
, limit the list of contexts return to either those that apply to all projects (global contexts) (true) or those that apply to only a subset of projects (false)
POST /rest/api/{2-3}/field/{fieldId}/context
Creates a custom field context. If projectIds
is empty, a global context is created. A global context is one that applies to all project. If issueTypeIds
is empty, the context applies to all issue types, the method returns the following information:
GET /rest/api/{2-3}/field/{fieldId}/context/defaultValue
Returns a list of defaults for a custom field. The results can be filtered by contextId
, otherwise all values are returned. If no defaults are set for a context, nothing is returned.
PUT /rest/api/{2-3}/field/{fieldId}/context/defaultValue
Sets default for contexts of a custom field. Default is defined using these objects:
PUT /rest/api/{2-3}/field/{fieldId}/context/{contextId}
Updates a .
DELETE /rest/api/{2-3}/field/{fieldId}/context/{contextId}
Deletes a .
PUT /rest/api/{2-3}/field/{fieldId}/context/{contextId}/issuetype
Adds issue types to a custom field context, appending the issue types to the issue types list.
POST /rest/api/{2-3}/field/{fieldId}/context/{contextId}/issuetype/remove
Removes issue types from a custom field context.
PUT /rest/api/{2-3}/field/{fieldId}/context/{contextId}/project
Assigns a custom field context to projects.
POST /rest/api/{2-3}/field/{fieldId}/context/{contextId}/project/remove
Removes a custom field context from projects.
GET /rest/api/{2-3}/field/{fieldId}/context/projectmapping
Returns a list of context to project mappings for a custom field. The result can be filtered by contextId
. Otherwise, all mappings are returned. Invalid IDs are ignored.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var fieldID = "customfield_10038"
options := models.FieldContextOptionsScheme{
IsAnyIssueType: false,
IsGlobalContext: false,
ContextID: nil,
}
contexts, response, err := atlassian.Issue.Field.Context.Gets(context.Background(), fieldID, &options, 0, 50)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(contexts)
for _, fieldContext := range contexts.Values {
log.Println(fieldContext)
}
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var fieldID = "customfield_10038"
payload := models.FieldContextPayloadScheme{
IssueTypeIDs: []int{10004},
ProjectIDs: []int{10002},
Name: "Bug fields context $3 aaw",
Description: "A context used to define the custom field options for bugs.",
}
contextCreated, response, err := atlassian.Issue.Field.Context.Create(context.Background(), fieldID, &payload)
if err != nil {
log.Fatal(err)
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(contextCreated)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var fieldID = "customfield_10038"
defaultValues, response, err := atlassian.Issue.Field.Context.GetDefaultValues(context.Background(), fieldID, nil, 0, 50)
if err != nil {
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, value := range defaultValues.Values {
/*
For singleOption customField type, use value.OptionID
For multipleOption customField type, use value.OptionIDs
For cascadingOption customField type, use value.OptionID and value.CascadingOptionID
*/
log.Println(value)
}
}
CustomFieldContextDefaultValueSingleOption
option.single
For single choice select lists and radio buttons.
CustomFieldContextDefaultValueMultipleOption
option.multiple
For multiple-choice select lists and checkboxes.
CustomFieldContextDefaultValueCascadingOption
option.cascading
For cascading select lists.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var fieldID = "customfield_10038"
var payload = &models.FieldContextDefaultPayloadScheme{
DefaultValues: []*models.CustomFieldDefaultValueScheme{
{
ContextID: "10138",
OptionID: "10022",
Type: "option.single",
},
},
}
response, err := atlassian.Issue.Field.Context.SetDefaultValue(context.Background(), fieldID, payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var (
customFieldID = "customfield_10038"
contextID = 10140
newName = "New Context Name"
newDescription = "New Context Description"
)
response, err := atlassian.Issue.Field.Context.Update(context.Background(), customFieldID, contextID, newName, newDescription)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var (
customFieldID = "customfield_10038"
contextID = 10140
)
response, err := atlassian.Issue.Field.Context.Delete(context.Background(), customFieldID, contextID)
if err != nil {
log.Fatal(err)
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var (
customFieldID = "customfield_10038"
contextID = 10180
issueTypesIDs = []string{"10007", "10002"}
)
response, err := atlassian.Issue.Field.Context.AddIssueTypes(context.Background(), customFieldID, contextID, issueTypesIDs)
if err != nil {
log.Fatal(err)
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var (
customFieldID = "customfield_10038"
contextID = 10180
issueTypesIDs = []string{"10007", "10002"}
)
response, err := atlassian.Issue.Field.Context.RemoveIssueTypes(context.Background(), customFieldID, contextID, issueTypesIDs)
if err != nil {
return
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var (
customFieldID = "customfield_10038"
contextID = 10179
projectIDs = []string{"10003"}
)
response, err := atlassian.Issue.Field.Context.Link(context.Background(), customFieldID, contextID, projectIDs)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var (
customFieldID = "customfield_10038"
contextID = 10179
projectIDs = []string{"10003"}
)
response, err := atlassian.Issue.Field.Context.UnLink(context.Background(), customFieldID, contextID, projectIDs)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var fieldID = "customfield_10038"
mapping, response, err := atlassian.Issue.Field.Context.ProjectsContext(context.Background(), fieldID, nil, 0, 50)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(mapping.Total)
}
A board displays issues from one or more projects, giving you a flexible way of viewing, managing, and reporting on work in progress.
GET /rest/agile/1.0/board/{boardId}/backlog
Returns all issues from the board's backlog, for the given board ID.
This only includes issues that the user has permission to view.
The backlog contains incomplete issues that are not assigned to any future or active sprint.
Issues returned from this resource include Agile fields, like sprint, closedSprints, flagged, and epic. By default, the returned issues are ordered by rank.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
var (
options = &models.IssueOptionScheme{
JQL: "project = KP",
ValidateQuery: true,
Fields: []string{"status", "issuetype", "summary"},
Expand: []string{"changelog"},
}
boardID = 4
startAt = 0
maxResult = 50
)
issues, response, err := atlassian.Board.Backlog(context.Background(), boardID, startAt, maxResult, options)
if err != nil {
if response != nil {
log.Println("Response HTTP Response", string(response.Bytes.Bytes()))
}
log.Fatal(err)
}
log.Println("Response HTTP Code", response.Code)
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, issue := range issues.Issues {
log.Println(issue.Key)
}
}
GET /rest/agile/1.0/board/{boardId}/configuration
Get the board configuration.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
boardConfig, response, err := atlassian.Board.Configuration(context.Background(), 4)
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(boardConfig)
}
POST /rest/agile/1.0/board
Creates a new board. Board name, type ,and filter ID is required
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
newBoard := &models.BoardPayloadScheme{
Name: "DUMMY Board Name",
Type: "scrum", //scrum or kanban
FilterID: 10016,
// Omit the Location if you want to the board to yourself (location)
Location: &models.BoardPayloadLocationScheme{
ProjectKeyOrID: "KP",
Type: "project",
},
}
board, response, err := atlassian.Board.Create(context.Background(), newBoard)
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(board)
}
GET /rest/agile/1.0/board/{boardId}/epic
Returns all epics from the board, for the given board ID. This only includes epics that the user has permission to view. Note, if the user does not have permission to view the board, no epics will be returned at all.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
epicsPage, response, err := atlassian.Board.Epics(context.Background(), 4, 0, 50, false)
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 _, epic := range epicsPage.Values {
log.Println(epic)
}
}
GET /rest/agile/1.0/board/filter/{filterId}
Returns any boards which use the provided filter id. This method can be executed by users without a valid software license in order to find which boards are using a particular filter.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
var (
filterID = 10016
startAt = 0
maxResult = 50
)
boards, response, err := atlassian.Board.Filter(context.Background(), filterID, startAt, maxResult)
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 _, board := range boards.Values {
log.Println(board.Name, board.ID, board.Type)
}
}
GET /rest/agile/1.0/board/{boardId}
Returns the board for the given board ID.
This board will only be returned if the user has permission to view it.
Admins without the view permission will see the board as a private one, so will see only a subset of the board's data (board location for instance).
package main
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/jira/agile"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
board, response, err := atlassian.Board.Get(context.Background(), 4)
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(board)
log.Println(board.Location)
fmt.Println(response.Bytes.String())
}
GET /rest/agile/1.0/board/{boardId}/issue
Returns all issues from a board, for a given board ID.
This only includes issues that the user has permission to view.
An issue belongs to the board if its status is mapped to the board's column.
Epic issues do not belongs to the scrum boards.
Issues returned from this resource include Agile fields, like sprint, closedSprints, flagged, and epic. By default, the returned issues are ordered by rank.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
var (
options = &models.IssueOptionScheme{
//JQL: "project = KP",
//ValidateQuery: true,
Fields: []string{"status", "issuetype", "summary"},
Expand: []string{"changelog"},
}
boardID = 4
startAt = 0
maxResult = 50
)
issuesPage, response, err := atlassian.Board.Issues(context.Background(), boardID, options, startAt, maxResult)
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 _, issue := range issuesPage.Issues {
log.Println(issue.Key)
}
}
GET /rest/agile/1.0/board/{boardId}/epic/{epicId}/issue
Returns all issues that belong to an epic on the board, for the given epic ID and the board ID.
This only includes issues that the user has permission to view.
Issues returned from this resource include Agile fields, like sprint, closedSprints, flagged, and epic. By default, the returned issues are ordered by rank.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
var (
options = &models.IssueOptionScheme{
//JQL: "project = KP",
//ValidateQuery: true,
Fields: []string{"status", "issuetype", "summary"},
Expand: []string{"changelog"},
}
boardID = 4
epicID = 10029
startAt = 0
maxResult = 50
)
issuesPage, response, err := atlassian.Board.IssuesByEpic(context.Background(), boardID, epicID, options, startAt, maxResult)
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 _, issue := range issuesPage.Issues {
log.Println(issue.Key)
}
}
GET /rest/agile/1.0/board/{boardId}/sprint/{sprintId}/issue
Get all issues you have access to that belong to the sprint from the board.
Issue returned from this resource contains additional fields like: sprint, closedSprints, flagged and epic. Issues are returned ordered by rank. JQL order has higher priority than default rank.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
var (
options = &models.IssueOptionScheme{
//JQL: "project = KP",
//ValidateQuery: true,
Fields: []string{"status", "issuetype", "summary"},
Expand: []string{"changelog"},
}
boardID = 4
sprintID = 4
startAt = 0
maxResult = 50
)
issuesPage, response, err := atlassian.Board.IssuesBySprint(context.Background(), boardID, sprintID, options, startAt, maxResult)
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 _, issue := range issuesPage.Issues {
log.Println(issue.Key)
}
}
GET /rest/agile/1.0/board/{boardId}/epic/none/issue
Returns all issues that do not belong to any epic on a board, for a given board ID. This only includes issues that the user has permission to view. Issues returned from this resource include Agile fields, like sprint, closedSprints, flagged, and epic. By default, the returned issues are ordered by rank.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
var (
options = &models.IssueOptionScheme{
JQL: "project = KP",
ValidateQuery: true,
Fields: []string{"status", "issuetype", "summary"},
Expand: []string{"changelog"},
}
boardID = 4
startAt = 0
maxResult = 50
)
issuesPage, response, err := atlassian.Board.IssuesWithoutEpic(context.Background(), boardID, options, startAt, maxResult)
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 _, issue := range issuesPage.Issues {
log.Println(issue.Key)
}
}
POST /rest/agile/1.0/board/{boardId}/issue
Move issues to the backlog of a particular board (if they are already on that board).
This operation is equivalent to remove future and active sprints from a given set of issues if the board has sprints If the board does not have sprints this will put the issues back into the backlog from the board. At most 50 issues may be moved at once.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
var (
boardID = 7
payload = &models.BoardMovementPayloadScheme{
Issues: []string{"KP-3"},
RankBeforeIssue: "",
RankAfterIssue: "",
}
)
response, err := atlassian.Board.Move(context.Background(), boardID, payload)
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)
}
GET /rest/agile/1.0/board/{boardId}/project
Returns all projects that are associated with the board, for the given board ID. If the user does not have permission to view the board, no projects will be returned at all. Returned projects are ordered by the name.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
projects, response, err := atlassian.Board.Projects(context.Background(), 4, 0, 50)
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 _, project := range projects.Values {
log.Println(project)
}
}
GET /rest/agile/1.0/board/{boardId}/sprint
Returns all sprints from a board, for a given board ID. This only includes sprints that the user has permission to view.
package main
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/jira/agile"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
var (
boardID = 4
states = []string{"future", "active"} // valid values: future, active, closed
startAt = 0
maxResult = 50
)
sprints, response, err := atlassian.Board.Sprints(context.Background(), boardID, startAt, maxResult, states)
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 _, sprint := range sprints.Values {
log.Println(sprint)
}
fmt.Println(response.Bytes.String())
}
GET /rest/agile/1.0/board/{boardId}/version
Returns all versions from a board, for a given board ID. This only includes versions that the user has permission to view. Note, if the user does not have permission to view the board, no versions will be returned at all. Returned versions are ordered by the name of the project from which they belong and then by sequence defined by user.
package main
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/jira/agile"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
var (
boardID = 4
startAt = 0
maxResults = 50
released = false
)
versionsPage, response, err := atlassian.Board.Versions(context.Background(), boardID, startAt, maxResults, released)
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 _, version := range versionsPage.Values {
log.Println(version)
}
fmt.Println(response.Bytes.String())
}
DELETE /rest/agile/1.0/board/{boardId}
Delete deletes the board. Admin without the view permission can still remove the board.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
response, err := atlassian.Board.Delete(context.Background(), 4)
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)
}
GET /rest/agile/1.0/board
Gets returns all boards. This only includes boards that the user has permission to view.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/jira/agile"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := agile.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
atlassian.Auth.SetUserAgent("curl/7.54.0")
options := &models.GetBoardsOptions{
BoardType: "",
BoardName: "",
ProjectKeyOrID: "",
AccountIDLocation: "",
ProjectIDLocation: "",
IncludePrivate: true,
NegateLocationFiltering: false,
OrderBy: "",
Expand: "",
FilterID: 0,
}
boards, response, err := atlassian.Board.Gets(context.Background(), options, 0, 50)
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 _, board := range boards.Values {
log.Println(board)
}
}
This resource represents Jira issues
Need help working with issues? In Jira Software, issues help you manage code, estimate workload, and keep track of your team. On this page, you'll find a quick overview of everything that you can do with an issue.
This resource represents Jira issues. Use it to:
create or edit issues, individually or in bulk.
retrieve metadata about the options for creating or editing issues.
delete an issue.
assign a user to an issue.
get issue changelogs.
send notifications about an issue.
get details of the transitions available for an issue.
transition an issue.
In the Jira REST API, custom fields are uniquely identified by the field ID, as the display names are not unique within a Jira instance. For example, you could have two fields named "Escalation date", one with an ID of "12221" and one with an ID of "12222". A custom field is actually referenced by customfield\_
+ the field ID, rather than just the field ID.
We support the following custom field types.
Group(s) Picker
User(s) Picker
URL's
Text
Number
Date
DateTime
Select
MultiSelect
RadioButton
CheckBox
Cascading Multiselect
The examples below show how to set the values for different types of custom fields in the input data.
// The CustomFields struct is used on the Create(s), Edit methods
var customFields = jira.CustomFields{}
//Groups Picker customfield
err = customFields.Groups("customfield_10052", []string{"jira-administrators", "jira-administrators-system"})
if err != nil {
log.Fatal(err)
}
//Number customfield
err = customFields.Number("customfield_10043", 1000.3232)
if err != nil {
log.Fatal(err)
}
//User picker customfield
err = customFields.User("customfield_10044", "92c50fd7-4336-4761-abbc-bdd31ecbc380")
if err != nil {
log.Fatal(err)
}
//Users picker customfield
err = customFields.Users("customfield_10045", []string{"727b5300-78dc-4b92-961b-082676dea3f2", "697c6d52-993d-4ae3-84b2-1842bdb5b7c0"})
if err != nil {
log.Fatal(err)
}
//Group picker customfield
err = customFields.Group("customfield_10046", "scrum-masters")
if err != nil {
log.Fatal(err)
}
//URL customfield
err = customFields.URL("customfield_10047", "https://docs.go-atlassian.io/jira-software-cloud/issues")
if err != nil {
log.Fatal(err)
}
//Text customfield
err = customFields.Text("customfield_10048", "sample text")
if err != nil {
log.Fatal(err)
}
//Date customfield
err = customFields.Date("customfield_10049", time.Now().AddDate(0, -1, 0))
if err != nil {
log.Fatal(err)
}
//DateTime customfield
err = customFields.DateTime("customfield_10050", time.Now())
if err != nil {
log.Fatal(err)
}
//Select customfield
err = customFields.Select("customfield_10051", "Option 1")
if err != nil {
log.Fatal(err)
}
//MultiSelect customfield
err = customFields.MultiSelect("customfield_10052", []string{"Option 1", "Option 2", "Option 3"})
if err != nil {
log.Fatal(err)
}
//RadioButton customfield
err = customFields.RadioButton("customfield_10053", "Option 1")
if err != nil {
log.Fatal(err)
}
//CheckBox customfield
err = customFields.CheckBox("customfield_10054", []string{"Option 1", "Option 2"})
if err != nil {
log.Fatal(err)
}
//Cascading customfield
err = customFields.Cascading("customfield_10056", "America", "Costa Rica")
if err != nil {
log.Fatal(err)
}
POST /rest/api/{2-3}/issue
Creates an issue or, where the option to create subtasks is enabled in Jira, a subtask
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
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 payload = models.IssueSchemeV2{
Fields: &models.IssueFieldsSchemeV2{
Summary: "New summary test",
Project: &models.ProjectScheme{ID: "10000"},
IssueType: &models.IssueTypeScheme{Name: "Story"},
},
}
//CustomFields
var customFields = models.CustomFields{}
err = customFields.Groups("customfield_10052", []string{"jira-administrators", "jira-administrators-system"})
if err != nil {
log.Fatal(err)
}
err = customFields.Number("customfield_10043", 1000.3232)
if err != nil {
log.Fatal(err)
}
newIssue, response, err := atlassian.Issue.Create(context.Background(), &payload, &customFields)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("The new issue %v has been created with the ID %v", newIssue.Key, newIssue.ID)
}
POST /rest/api/{2-3}/issue/bulk
Creates issues and, where the option to create subtasks is enabled in Jira, subtasks.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
//CustomFields
var customFields = models.CustomFields{}
err = customFields.Groups("customfield_10052", []string{"jira-administrators", "jira-administrators-system"})
if err != nil {
log.Fatal(err)
}
err = customFields.Number("customfield_10043", 1000.3232)
if err != nil {
log.Fatal(err)
}
var issue1 = models.IssueBulkSchemeV2{
Payload: &models.IssueSchemeV2{
Fields: &models.IssueFieldsSchemeV2{
Summary: "New summary test",
Project: &models.ProjectScheme{ID: "10000"},
IssueType: &models.IssueTypeScheme{Name: "Story"},
},
},
CustomFields: &customFields,
}
var issue2 = models.IssueBulkSchemeV2{
Payload: &models.IssueSchemeV2{
Fields: &models.IssueFieldsSchemeV2{
Summary: "New summary test",
Project: &models.ProjectScheme{ID: "10000"},
IssueType: &models.IssueTypeScheme{Name: "Story"},
},
},
CustomFields: &customFields,
}
var issue3 = models.IssueBulkSchemeV2{
Payload: &models.IssueSchemeV2{
Fields: &models.IssueFieldsSchemeV2{
Summary: "New summary test",
Project: &models.ProjectScheme{ID: "10000"},
IssueType: &models.IssueTypeScheme{Name: "Story"},
},
},
CustomFields: &customFields,
}
var payload []*models.IssueBulkSchemeV2
payload = append(payload, &issue1, &issue2, &issue3)
newIssues, response, err := atlassian.Issue.Creates(context.Background(), payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, issue := range newIssues.Issues {
log.Printf(issue.Key)
}
for _, apiError := range newIssues.Errors {
log.Println(apiError.Status, apiError.Status)
}
}
GET /rest/api/{2-3}/issue/{issueIdOrKey}
Returns the details for an issue.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
issue, response, err := atlassian.Issue.Get(context.Background(), "KP-2", nil, []string{"transitions"})
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Println(issue.Key)
log.Println(issue.Fields.Reporter.AccountID)
for _, transition := range issue.Transitions {
log.Println(transition.Name, transition.ID, transition.To.ID, transition.HasScreen)
}
// Check if the issue contains sub-tasks
if issue.Fields.Subtasks != nil {
for _, subTask := range issue.Fields.Subtasks {
log.Println("Sub-Task: ", subTask.Key, subTask.Fields.Summary)
}
}
}
PUT /rest/api/{2-3}/issue/{issueIdOrKey}
Edits an issue. The edits to the issue's fields are defined using update
and fields
. There're two ways to edit an issue on Jira, implicit and explicit.
The simple way to update an issue is to do a GET, update the values inside "fields", and then PUT back.
If you PUT back exactly what you GOT, then you are also sending "names", "self", "key", etc. These are ignored.
You do not need to send all the fields inside "fields". You can just send the fields you want to update. Absent fields are left unchanged. For example, to update the summary:
var payload = jira.IssueScheme{
Fields: &jira.IssueFieldsScheme{
Summary: "New summary test test",
},
}
Some fields cannot be updated this way (for example, comments). Instead you must use explicit-verb updates (see below). You can tell if a field cannot be implicitly set by the fact it doesn't have a SET verb.
If you do send along such un-SET-able fields in this manner, they are ignored. This means that you can PUT what you GET, but not all of the document is taken into consideration.
Each field supports a set of operations (verbs) for mutating the field. You can retrieve the editable fields and the operations they support using the "editmeta" resource.
The editmeta endpoint is not mapped, yet refer to this ticket
The basic operations are defined below (but custom fields can define their own).
The general shape of an update is field, array of verb-value pairs, for example:
//Issue Update Operations
var operations = &jira.UpdateOperations{}
err = operations.AddArrayOperation("custom_field_id", map[string]string{
"value": "verb",
"value": "verb",
"value": "verb",
"value": "verb",
})
if err != nil {
log.Fatal(err)
}
// If the need to add multi-array customfields, you can the following method:
// In this particular example, we're going to the manipulate the fixVersions field.
err = operations.AddMultiRawOperation("fixVersions", []map[string]interface{}{
{
"remove": map[string]interface{}{
"name": "Version 00",
},
},
{
"remove": map[string]interface{}{
"name": "Version 101",
},
},
{
"add": map[string]interface{}{
"name": "Version 301",
},
},
})
SET: Sets the value of the field. The incoming value must be the same shape as the value of the field from a GET. For example, a string for "summary", and array of strings for "labels".
ADD: Adds an element to a field that is an array. The incoming value must be the same shape as the items of the array in a GET. For example, to add a label:
REMOVE: Removes an element from a field that is an array. The incoming value must be the same shape as the items of the array in a GET (although you can remove parts of the object that are not needed to uniquely identify the object).
EDIT: Edits an element in a field that is an array. The element is indexed/identified by the value itself (usually by id/name/key).
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var payload = models.IssueSchemeV2{
Fields: &models.IssueFieldsSchemeV2{
// Summary: "New summary test",
},
}
//CustomFields
var customFields = models.CustomFields{}
err = customFields.Groups("customfield_10052", []string{"jira-administrators", "jira-administrators-system"})
if err != nil {
log.Fatal(err)
}
err = customFields.Number("customfield_10043", 9000)
if err != nil {
log.Fatal(err)
}
//Issue Update Operations
var operations = &models.UpdateOperations{}
err = operations.AddArrayOperation("labels", map[string]string{
"triaged": "remove",
"triaged-2": "remove",
"triaged-1": "remove",
"blocker": "remove",
})
if err != nil {
log.Fatal(err)
}
err = operations.AddStringOperation("summary", "set", "new summary using operation")
if err != nil {
log.Fatal(err)
}
response, err := atlassian.Issue.Update(context.Background(), "KP-2", false, &payload, &customFields, operations)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
DELETE /rest/api/{2-3}/issue/{issueIdOrKey}
Deletes an issue.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Issue.Delete(context.Background(), "KP-6", false)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
PUT /rest/api/{2-3}/issue/{issueIdOrKey}/assignee
Assigns an issue to a user. Use this operation when the calling user does not have the Edit Issues permission but has the Assign issue permission for the project that the issue is in.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Issue.Assign(context.Background(), "KP-2", "bedc0e56-c9d1-4f5d-b380-cbced9125849")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
POST /rest/api/{2-3}/issue/{issueIdOrKey}/notify
Creates an email notification for an issue and adds it to the mail queue.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var userRecipients []*models.IssueNotifyUserScheme
userRecipients = append(userRecipients, &models.IssueNotifyUserScheme{AccountID: "87dde939-73be-465f-83c5-2217fb9dd9de"})
userRecipients = append(userRecipients, &models.IssueNotifyUserScheme{AccountID: "8abc0d5f-5eb9-48af-bd8d-b83451828a40"})
var groupsRecipients []*models.IssueNotifyGroupScheme
groupsRecipients = append(groupsRecipients, &models.IssueNotifyGroupScheme{Name: "jira-users"})
groupsRecipients = append(groupsRecipients, &models.IssueNotifyGroupScheme{Name: "scrum-masters"})
opts := &models.IssueNotifyOptionsScheme{
// The HTML body of the email notification for the issue.
HTMLBody: "The <strong>latest</strong> test results for this ticket are now available.",
// The subject of the email notification for the issue.
// If this is not specified, then the subject is set to the issue key and summary.
Subject: "SUBJECT EMAIL EXAMPLE",
// The plain text body of the email notification for the issue.
// TextBody: "lorem",
// The recipients of the email notification for the issue.
To: &models.IssueNotifyToScheme{
Reporter: true,
Assignee: true,
Watchers: true,
Voters: true,
Users: userRecipients,
Groups: groupsRecipients,
},
// Restricts the notifications to users with the specified permissions.
Restrict: nil,
}
response, err := atlassian.Issue.Notify(context.Background(), "KP-2", opts)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
GET /rest/api/{2-3}/issue/{issueIdOrKey}/transitions
Returns either all transitions or a transition that can be performed by the user on an issue, based on the issue's status.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
transitions, response, err := atlassian.Issue.Transitions(context.Background(), "KP-2")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
for _, transition := range transitions.Transitions {
log.Println(transition.ID, transition.Name)
}
}
POST /rest/api/{2-3}/issue/{issueIdOrKey}/transitions
Performs an issue transition.
Performs an issue transition and, if a transition screen is associated, updates the relevant fields from that screen.
To update fields on the transition screen, include the desired field values in the fields or update parameters within the request body. You can retrieve details about these fields by using the Get transitions endpoint with the transitions.fields expand option.
This operation supports anonymous access.
package main
import (
"context"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
return
}
atlassian.Auth.SetBasicAuth(mail, token)
var payload = &models.IssueSchemeV2{
Fields: &models.IssueFieldsSchemeV2{
Summary: "New summary test test",
Resolution: &models.ResolutionScheme{
Name: "Done",
},
},
}
//CustomFields
var customFields = &models.CustomFields{}
err = customFields.Groups("customfield_10052", []string{"jira-administrators", "jira-administrators-system"})
if err != nil {
log.Fatal(err)
}
//Issue Update Operations
var operations = &models.UpdateOperations{}
err = operations.AddArrayOperation("labels", map[string]string{
"triaged": "add",
"triaged-2": "add",
"triaged-1": "add",
"blocker": "add",
})
if err != nil {
log.Fatal(err)
}
options := &models.IssueMoveOptionsV2{
Fields: payload,
Operations: operations,
CustomFields: customFields,
}
response, err := atlassian.Issue.Move(context.Background(), "KP-7", "41", options)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}
A Jira workflow is a set of statuses and transitions that an issue moves through during its lifecycle, and typically represents a process within your organization. Workflows can be associated with particular projects and, optionally, specific issue types by using a workflow scheme.
Workflows can be customized to fit the needs of a particular team or project. Customization options include adding new stages or statuses, defining new transitions between statuses, and setting rules and conditions that determine when an issue can move from one stage to another. With a well-designed Jira workflow, teams can track the progress of their work more effectively and ensure that all team members are on the same page about the status of each task or issue.
POST /rest/api/{2-3}/workflow
Deprecated
Create creates a workflow. You can define transition rules using the shapes detailed in the following sections. If no transitional rules are specified the default system transition rules are used.
Conditions enable workflow rules that govern whether a transition can execute.
A condition that always fails.
{
Type: "RemoteOnlyCondition",
},
A condition that blocks issue transition if there is a pending approval.
{
Type: "BlockInProgressApprovalCondition",
}
A condition that allows transition if a comparison between a number custom field and a value is true.
{
Type: "CompareNumberCFCondition",
Configuration: map[string]interface{}{
"comparator": "=",
"fieldId": "customfield_10029",
"fieldValue": 2,
},
}
A condition that hides a transition from users. The transition can only be triggered from a workflow function or REST API operation.
{
Type: "RemoteOnlyCondition",
}
A condition that allows only the assignee to execute a transition.
{
Type: "AllowOnlyAssignee",
}
A condition that allows only the reporter to execute a transition.
{
Type: "AllowOnlyReporter",
}
A condition that allows only users with a permission to execute a transition.
{
Type: "PermissionCondition",
Configuration: map[string]interface{}{
"permissionKey": "BROWSE_PROJECTS",
},
},
A condition that allows a transition based on whether an issue has or has not transitioned through a status.
{
Type: "PreviousStatusCondition",
Configuration: map[string]interface{}{
"ignoreLoopTransitions": true,
"includeCurrentStatus": true,
"mostRecentStatusOnly": true,
"reverseCondition": true,
"previousStatus": map[string]interface{}{
"id": "5",
},
},
}
A condition that prevents a user to perform the transition, if the user has already performed a transition on the issue.
{
Type: "SeparationOfDutiesCondition",
Configuration: map[string]interface{}{
"fromStatus": map[string]interface{}{"id": "5"},
"toStatus": map[string]interface{}{"id": "6"},
},
}
A condition that blocks transition on a parent issue if any of its subtasks are in any of one or more statuses.
{
Type: "SubTaskBlockingCondition",
Configuration: map[string]interface{}{
"statuses": []map[string]interface{}{
{
"id": "1",
},
{
"id": "3",
},
},
},
},
A condition that allows users belonging to any group from a list of groups to execute a transition.
{
Type: "UserInAnyGroupCondition",
Configuration: map[string]interface{}{
"groups": []string{"administrators", "atlassian-addons-admin"},
},
}
A condition that allows only users with at least one project roles from a list of project roles to execute a transition.
{
Type: "InAnyProjectRoleCondition",
Configuration: map[string]interface{}{
"projectRoles": []map[string]interface{}{
{
"id": "10002",
},
{
"id": "10003",
},
{
"id": "10012",
},
{
"id": "10013",
},
},
},
}
A condition that allows only users listed in a given custom field to execute the transition.
{
Type: "UserIsInCustomFieldCondition",
Configuration: map[string]interface{}{
"allowUserInField": false,
"fieldId": "customfield_10010",
},
}
A condition that allows users belonging to a group to execute a transition.
{
Type: "UserInGroupCondition",
Configuration: map[string]interface{}{
"group": "administrators",
},
}
A condition that allows users belonging to a group specified in a custom field to execute a transition.
{
Type: "InGroupCFCondition",
Configuration: map[string]interface{}{
"fieldId": "customfield_10012",
},
}
A condition that allows users with a project role to execute a transition.
{
Type: "InProjectRoleCondition",
Configuration: map[string]interface{}{
"projectRole": map[string]interface{}{
"id": "10002",
},
},
}
A conditions that allows a transition to execute if the value of a field is equal to a constant value or simply set.
{
Type: "ValueFieldCondition",
Configuration: map[string]interface{}{
"fieldId": "assignee",
"fieldValue": "qm:6e1ecee6-8e64-4db6-8c85-916bb3275f51:54b56885-2bd2-4381-8239-78263442520f",
"comparisonType": "NUMBER",
"comparator": "=",
},
}
Validators check that any input made to the transition is valid before the transition is performed.
A validator that compares two dates.
{
Type: "DateFieldValidator",
Configuration: map[string]interface{}{
"comparator": ">",
"date1": "updated",
"date2": "created",
"expression": "1d",
"includeTime": true,
},
}
A validator that checks that a date falls on or after a reference date and before or on the reference date plus a number of days.
{
Type: "WindowsDateValidator",
Configuration: map[string]interface{}{
"date1": "customfield_10009",
"date2": "created",
"windowsDays": 5,
},
}
A validator that checks fields are not empty. By default, if a field is not included in the current context it's ignored and not validated.
{
Type: "FieldRequiredValidator",
Configuration: map[string]interface{}{
"ignoreContext": true,
"errorMessage": "Hey",
"fieldIds": []string{
"versions",
"customfield_10037",
"customfield_10003",
},
},
}
A validator that checks that a field value is changed. However, this validation can be ignored for users from a list of groups.
{
Type: "FieldChangedValidator",
Configuration: map[string]interface{}{
"fieldId": "comment",
"errorMessage": "Hey",
"exemptedGroups": []string{
"administrators",
"atlassian-addons-admin",
},
},
}
A validator that checks that a multi-select field has only one value. Optionally, the validation can ignore values copied from subtasks.
{
Type: "FieldHasSingleValueValidator",
Configuration: map[string]interface{}{
"fieldId": "attachment",
"excludeSubtasks": true,
},
}
A validator that checks the status of the parent issue of a subtask. Ìf the issue is not a subtask, no validation is performed.
{
Type: "ParentStatusValidator",
Configuration: map[string]interface{}{
"parentStatuses": []map[string]interface{}{
{
"id": "2",
},
{
"id": "1",
},
},
},
}
A validator that checks the user has a permission.
{
Type: "PermissionValidator",
Configuration: map[string]interface{}{
"permissionKey": "ADMINISTER_PROJECTS",
},
},
A validator that checks if the issue has held a status.
{
Type: "PreviousStatusValidator",
Configuration: map[string]interface{}{
"mostRecentStatusOnly": false,
"previousStatus": map[string]interface{}{"id": "15"},
},
},
A validator that checks the content of a field against a regular expression.
{
Type: "RegexpFieldValidator",
Configuration: map[string]interface{}{
"regExp": "[0-9]",
"fieldId": "customfield_10029",
},
},
A validator that checks if a user has a permission. Obsolete. You may encounter this validator when getting transition rules and can pass it when updating or creating rules, for example, when you want to duplicate the rules from a workflow on a new workflow.
{
Type: "UserPermissionValidator",
Configuration: map[string]interface{}{
"permissionKey": "BROWSE_PROJECTS",
"nullAllowed": false,
"username": "TestUser",
},
},
Post functions carry out any additional processing required after a Jira workflow transition is executed.
A post function that fires an event that is processed by the listeners.
{
Type: "FireIssueEventFunction",
Configuration: map[string]interface{}{
"event": map[string]interface{}{"id": "1"},
},
},
A post function that sets issue status to the linked status of the destination workflow status.
{
Type: "UpdateIssueStatusFunction",
}
A post function that adds a comment entered during the transition to an issue.
{
Type: "CreateCommentFunction",
}
A post function that stores updates to an issue.
{
Type: "CreateCommentFunction",
}
A post function that assigns the issue to the current user if the current user has the ASSIGNABLE_USER
permission.
{
Type: "CreateCommentFunction",
}
A post function that assigns the issue to the project or component lead developer.
{
Type: "CreateCommentFunction",
}
A post function that assigns the issue to the reporter.
{
Type: "CreateCommentFunction",
}
A post function that clears the value from a field.
{
Type: "ClearFieldValuePostFunction",
Configuration: map[string]interface{}{
"fieldId": "assignee",
},
},
A post function that copies the value of one field to another, either within an issue or from parent to subtask.
{
Type: "CopyValueFromOtherFieldPostFunction",
Configuration: map[string]interface{}{
"sourceFieldId": "assignee",
"destinationFieldId": "creator",
"copyType": "same",
},
},
A post function that updates the content of an issue custom field.
{
Type: "UpdateIssueCustomFieldPostFunction",
Configuration: map[string]interface{}{
"mode": "append",
"fieldId": "customfield_10003",
"fieldValue": "yikes",
},
},
A post function that updates a simple issue field.
{
Type: "UpdateIssueFieldFunction",
Configuration: map[string]interface{}{
"fieldId": "assignee",
"fieldValue": "5f0c277e70b8a90025a00776",
},
},
package main
import (
"context"
v3 "github.com/ctreminiom/go-atlassian/jira/v3"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v3.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
payload := &models.WorkflowPayloadScheme{
Name: "Workflow Sample",
Description: "description of the workflow sample",
Statuses: []*models.WorkflowTransitionScreenScheme{
{
ID: "1", // Open
Properties: map[string]interface{}{
"jira.issue.editable": true,
},
},
{
ID: "3", // In Progress
},
},
Transitions: []*models.WorkflowTransitionPayloadScheme{
{
Name: "Open",
To: "1",
Type: "initial",
},
{
Name: "Open",
From: []string{"1"},
Properties: map[string]interface{}{
"custom-property": "custom-value",
},
Rules: &models.WorkflowTransitionRulePayloadScheme{
Conditions: &models.WorkflowConditionScheme{
Conditions: []*models.WorkflowConditionScheme{
{
Type: "RemoteOnlyCondition",
},
{
Configuration: map[string]interface{}{
"groups": []string{"confluence-users", "scrum-masters"},
},
Type: "UserInAnyGroupCondition",
},
},
Operator: "AND",
},
},
To: "3",
Type: "directed",
},
},
}
newWorkflow, response, err := instance.Workflow.Create(context.Background(), payload)
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
log.Println(newWorkflow.Name)
log.Println(newWorkflow.EntityID)
}
GET /rest/api/{2-3}/workflow/search
Returns a paginated list of published classic workflows. When workflow names are specified, details of those workflows are returned. Otherwise, all published classic workflows are returned.
This operation does not return next-gen workflows, Deprecated
package main
import (
"context"
"fmt"
v3 "github.com/ctreminiom/go-atlassian/jira/v3"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v3.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
options := &models.WorkflowSearchOptions{
WorkflowName: nil,
Expand: []string{"transitions", "statuses", "default", "schemes", "projects", "hasDraftWorkflow", "operations"},
QueryString: "",
OrderBy: "name",
IsActive: false,
}
workflows, response, err := instance.Workflow.Gets(context.Background(), options, 0, 50)
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
for _, workflow := range workflows.Values {
fmt.Println(workflow.ID, workflow.Description, len(workflow.Statuses))
}
}
DELETE /rest/api/{2-3}/workflow/{entityId}
Deletes a workflow, the workflow cannot be deleted if it is:
an active workflow.
a system workflow.
associated with any workflow scheme.
associated with any draft workflow scheme.
package main
import (
"context"
v3 "github.com/ctreminiom/go-atlassian/jira/v3"
"log"
"os"
)
func main() {
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
instance, err := v3.New(nil, host)
if err != nil {
log.Fatal(err)
}
instance.Auth.SetBasicAuth(mail, token)
instance.Auth.SetUserAgent("curl/7.54.0")
response, err := instance.Workflow.Delete(context.Background(), "6f2a8273-7f30-4444-96ad-7ddb5d4c9f8e")
if err != nil {
if response != nil {
log.Println(response.Bytes.String())
log.Println(response.Code)
}
log.Fatal(err)
}
}
POST /rest/api/{2-3}/workflows
Returns a list of workflows and related statuses by providing workflow names, workflow IDs, or project and issue types.
Permissions required:
Administer Jira global permission to access all, including project-scoped, workflows
At least one of the Administer projects and View (read-only) workflow project permissions to access project-scoped workflows
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("SITE")
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)
options := &models.WorkflowSearchCriteria{
WorkflowIDs: nil, // The list of workflow IDs to query.
WorkflowNames: []string{"PV: Project Management Workflow"}, // The list of workflow names to query.
}
expand := []string{"workflows.usages", "statuses.usages"}
workflows, response, err := atlassian.Workflow.Search(context.Background(), options, expand, true)
if err != nil {
log.Println("Unable to search for workflows: ", err)
log.Println(response.Bytes.String())
log.Println(response.StatusCode)
log.Fatal(err)
}
for _, workflow := range workflows.Workflows {
workflowBuffer, _ := json.MarshalIndent(workflow, "", "\t")
fmt.Println(string(workflowBuffer))
}
for _, status := range workflows.Statuses {
statusBuffer, _ := json.MarshalIndent(status, "", "\t")
fmt.Println(string(statusBuffer))
}
}
GET /rest/api/{2-3}/workflows/capabilities
Get the list of workflow capabilities for a specific workflow using either the workflow ID, or the project and issue type ID pair.
The response includes the scope of the workflow, defined as global/project-based, and a list of project types that the workflow is scoped to. It also includes all rules organised into their broad categories (conditions, validators, actions, triggers, screens)
as well as the source location (Atlassian-provided, Connect, Forge).
A validator rule that checks if a user has the required permissions to execute the transition in the workflow.
A validator rule that checks if a user has the required permissions to execute the transition in the workflow.
{
"ruleKey": "system:check-permission-validator",
"parameters": {
"permissionKey": "ADMINISTER_PROJECTS"
}
}
Parameters:
permissionKey
The permission required to perform the transition. Allowed values: built-in Jira permissions.
A validator to block the child issue\u2019s transition depending on the parent issue\u2019s status.
{
"ruleKey" : "system:parent-or-child-blocking-validator"
"parameters" : {
"blocker" : "PARENT"
"statusIds" : "1,2,3"
}
}
A validator that checks if an issue has transitioned through specified previous status(es) before allowing the current transition to occur.
{
"ruleKey": "system:previous-status-validator",
"parameters": {
"previousStatusIds": "10014",
"mostRecentStatusOnly": "true"
}
}
Parameters:
previousStatusIds
a comma-separated list of status IDs, currently only support one ID.
mostRecentStatusOnly
when true
only considers the most recent status for the condition evaluation. Allowed values: true
, false
.
A validation that ensures a specific field's value meets the defined criteria before allowing an issue to transition in the workflow.
Depending on the rule type, the result will vary:
Field required
{
"ruleKey": "system:validate-field-value",
"parameters": {
"ruleType": "fieldRequired",
"fieldsRequired": "assignee",
"ignoreContext": "true",
"errorMessage": "An assignee must be set!"
}
}
Parameters:
fieldsRequired
the ID of the field that is required. For a custom field, it would look like customfield_123
.
ignoreContext
controls the impact of context settings on field validation. When set to true
, the validator doesn't check a required field if its context isn't configured for the current issue. When set to false
, the validator requires a field even if its context is invalid. Allowed values: true
, false
.
errorMessage
is the error message to display if the user does not provide a value during the transition. A default error message will be shown if you don't provide one (Optional).
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"log"
"os"
)
func main() {
var (
host = os.Getenv("SITE")
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)
capabilities, response, err := atlassian.Workflow.Capabilities(context.Background(), "workflow-id", "project-id", "issuetype-id")
if err != nil {
log.Println(response.Bytes.String())
log.Println(response.StatusCode)
log.Fatal(err)
}
capabilitiesBuffer, _ := json.MarshalIndent(capabilities, "", "\t")
fmt.Println(string(capabilitiesBuffer))
}
POST /rest/api/{2-3}/workflows/create
Create workflows and related statuses. This method allows you to create a workflow by defining transition rules using the shapes detailed in the Atlassian REST API documentation. If no transition rules are specified, the default system transition rules will be used.
Permissions required:
Administer Jira project permission to create all, including global-scoped, workflows
Administer projects project permissions to create project-scoped workflows
The AddStatus()
method is used to add a status to the WorkflowCreatesPayload
. This method ensures that any status used in the workflow is explicitly included in the payload under the statuses
tag.
payload.AddStatus(&models.WorkflowStatusUpdateScheme{
ID: "10012",
Name: "To Do",
StatusCategory: "TODO",
StatusReference: "f0b24de5-25e7-4fab-ab94-63d81db6c0c0",
})
In this example, the status "To Do" with ID "10012" is added to the workflow payload. The StatusReference
is a unique identifier used later when associating statuses with workflow steps.
The AddTransition()
method is used to add a transition between statuses in a workflow. Transitions define the movement between statuses in a workflow, such as moving from "To Do" to "In Progress".
// Adding a transition to the workflow
err := epicWorkflow.AddTransition(&models.TransitionUpdateDTOScheme{
ID: "1",
Type: "INITIAL",
Name: "Create",
To: &models.StatusReferenceAndPortScheme{
StatusReference: "f0b24de5-25e7-4fab-ab94-63d81db6c0c0",
},
})
This example adds an "INITIAL" transition called "Create" that moves the issue to the "To Do" status. The StatusReference
is used to link the transition to the appropriate status.
The AddWorkflow()
method is used to add a workflow to the WorkflowCreatesPayload
. This method is crucial for building the final payload that will be sent to the JIRA API.
// Adding the workflow to the payload
err := payload.AddWorkflow(epicWorkflow)
if err != nil {
log.Fatal(err)
}
In this example, the epicWorkflow
(previously populated with statuses and transitions) is added to the payload. This payload can include multiple workflows, making it possible to create several workflows in a single API request.
Any status used within a workflow (through transitions or initial states) must be included in the statuses
tag under the WorkflowCreatesPayload
struct.
This ensures that JIRA recognizes and correctly maps the statuses during workflow creation. Failure to include a status may result in errors or incomplete workflow creation.
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("SITE")
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)
// Create the workflow creation payload
payload := &models.WorkflowCreatesPayload{
Scope: &models.WorkflowScopeScheme{Type: "GLOBAL"},
}
// Add the status references on the payload
statuses := []struct {
ID, Name, StatusCategory, StatusReference string
}{
{"10012", "To Do", "TODO", "f0b24de5-25e7-4fab-ab94-63d81db6c0c0"},
{"3", "In Progress", "IN_PROGRESS", "c7a35bf0-c127-4aa6-869f-4033730c61d8"},
{"10002", "Done", "DONE", "6b3fc04d-3316-46c5-a257-65751aeb8849"},
}
for _, status := range statuses {
payload.AddStatus(&models.WorkflowStatusUpdateScheme{
ID: status.ID,
Name: status.Name,
StatusCategory: status.StatusCategory,
StatusReference: status.StatusReference,
})
}
epicWorkflow := &models.WorkflowCreateScheme{
Description: "This workflow represents the process of software development related to epics.",
Name: "Epic Software Development Workflow V4",
}
// Add the statuses to the workflow using the referenceID and the layout
layouts := []struct {
X, Y float64
StatusReference string
}{
{114.99993896484375, -16, "f0b24de5-25e7-4fab-ab94-63d81db6c0c0"},
{317.0000915527344, -16, "c7a35bf0-c127-4aa6-869f-4033730c61d8"},
{508.000244140625, -16, "6b3fc04d-3316-46c5-a257-65751aeb8849"},
}
for _, layout := range layouts {
epicWorkflow.AddStatus(&models.StatusLayoutUpdateScheme{
Layout: &models.WorkflowLayoutScheme{X: layout.X, Y: layout.Y},
StatusReference: layout.StatusReference,
})
}
// Add the transitions to the workflow
transitions := []struct {
ID, Type, Name, StatusReference string
}{
{"1", "INITIAL", "Create", "f0b24de5-25e7-4fab-ab94-63d81db6c0c0"},
{"21", "GLOBAL", "In Progress", "c7a35bf0-c127-4aa6-869f-4033730c61d8"},
{"31", "GLOBAL", "Done", "6b3fc04d-3316-46c5-a257-65751aeb8849"},
}
for _, transition := range transitions {
err = epicWorkflow.AddTransition(&models.TransitionUpdateDTOScheme{
ID: transition.ID,
Type: transition.Type,
Name: transition.Name,
To: &models.StatusReferenceAndPortScheme{
StatusReference: transition.StatusReference,
},
})
if err != nil {
log.Fatal(err)
}
}
// You can multiple workflows on the same payload
if err := payload.AddWorkflow(epicWorkflow); err != nil {
log.Fatal(err)
}
workflowsCreated, response, err := atlassian.Workflow.Creates(context.Background(), payload)
if err != nil {
log.Println("Unable to create workflows: ", err)
log.Println(response.Bytes.String())
log.Fatal(err)
}
workflowBuffer, _ := json.MarshalIndent(workflowsCreated, "", "\t")
fmt.Println(string(workflowBuffer))
}
POST /rest/api/{2-3}/workflows/create/validation
Validates workflows before creating them. This method allows you to validate the configuration of one or more workflows before they are created in Jira.
It helps ensure that the workflows adhere to the defined rules and constraints. The validation checks will include all aspects of the workflows, such as transitions, statuses, and any related conditions or validators.
Permissions required:
Administer Jira project permission to create all, including global-scoped, workflows
Administer projects project permissions to create project-scoped workflows
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("SITE")
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)
// Create the workflow creation payload
payload := &models.WorkflowCreatesPayload{
Scope: &models.WorkflowScopeScheme{Type: "GLOBAL"},
}
// Add the status references on the payload
statuses := []struct {
ID, Name, StatusCategory, StatusReference string
}{
{"10012", "To Do", "TODO", "f0b24de5-25e7-4fab-ab94-63d81db6c0c0"},
{"3", "In Progress", "IN_PROGRESS", "c7a35bf0-c127-4aa6-869f-4033730c61d8"},
{"10002", "Done", "DONE", "6b3fc04d-3316-46c5-a257-65751aeb8849"},
}
for _, status := range statuses {
payload.AddStatus(&models.WorkflowStatusUpdateScheme{
ID: status.ID,
Name: status.Name,
StatusCategory: status.StatusCategory,
StatusReference: status.StatusReference,
})
}
epicWorkflow := &models.WorkflowCreateScheme{
Description: "This workflow represents the process of software development related to epics.",
Name: "Epic Software Development Workflow V4",
}
// Add the statuses to the workflow using the referenceID and the layout
layouts := []struct {
X, Y float64
StatusReference string
}{
{114.99993896484375, -16, "f0b24de5-25e7-4fab-ab94-63d81db6c0c0"},
{317.0000915527344, -16, "c7a35bf0-c127-4aa6-869f-4033730c61d8"},
{508.000244140625, -16, "6b3fc04d-3316-46c5-a257-65751aeb8849"},
}
for _, layout := range layouts {
epicWorkflow.AddStatus(&models.StatusLayoutUpdateScheme{
Layout: &models.WorkflowLayoutScheme{X: layout.X, Y: layout.Y},
StatusReference: layout.StatusReference,
})
}
// Add the transitions to the workflow
transitions := []struct {
ID, Type, Name, StatusReference string
}{
{"1", "INITIAL", "Create", "f0b24de5-25e7-4fab-ab94-63d81db6c0c0"},
{"21", "GLOBAL", "In Progress", "c7a35bf0-c127-4aa6-869f-4033730c61d8"},
{"31", "GLOBAL", "Done", "6b3fc04d-3316-46c5-a257-65751aeb8849"},
}
for _, transition := range transitions {
err = epicWorkflow.AddTransition(&models.TransitionUpdateDTOScheme{
ID: transition.ID,
Type: transition.Type,
Name: transition.Name,
To: &models.StatusReferenceAndPortScheme{
StatusReference: transition.StatusReference,
},
})
if err != nil {
log.Fatal(err)
}
}
// You can multiple workflows on the same payload
if err := payload.AddWorkflow(epicWorkflow); err != nil {
log.Fatal(err)
}
validationOptions := &models.ValidationOptionsForCreateScheme{
Payload: payload,
Options: &models.ValidationOptionsLevelScheme{
Levels: []string{"ERROR", "WARNING"},
},
}
validationErrors, response, err := atlassian.Workflow.ValidateCreateWorkflows(context.Background(), validationOptions)
if err != nil {
log.Println("Unable to create workflows: ", err)
log.Println(response.Bytes.String())
log.Fatal(err)
}
for _, validationError := range validationErrors.Errors {
buffer, _ := json.MarshalIndent(validationError, "", "\t")
fmt.Println(string(buffer))
}
}
POST /rest/api/{2-3}/workflows/update
Updates workflows. This method allows you to update workflows by providing a payload containing the details of the updates. You can expand specific fields using the 'expand' parameter.
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("SITE")
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.WorkflowUpdatesPayloadScheme{
Statuses: []*models.WorkflowStatusUpdateScheme{
{
ID: "10012",
Name: "To Do",
StatusCategory: "TODO",
StatusReference: "f0b24de5-25e7-4fab-ab94-63d81db6c0c0",
},
{
ID: "3",
Name: "In Progress",
StatusCategory: "IN_PROGRESS",
StatusReference: "c7a35bf0-c127-4aa6-869f-4033730c61d8",
},
{
ID: "10002",
Name: "Done",
StatusCategory: "DONE",
StatusReference: "6b3fc04d-3316-46c5-a257-65751aeb8849",
},
},
Workflows: []*models.WorkflowUpdateScheme{
{
DefaultStatusMappings: nil,
ID: "6c91af3d-2ae1-46c1-9009-eb93a10a54d1",
StartPointLayout: nil,
Version: &models.WorkflowDocumentVersionScheme{
ID: "c44b423d-89c9-458d-abb7-89ac4fefebd4",
VersionNumber: 0,
},
},
},
}
expand := []string{"workflows.usages", "statuses.usages"}
workflowsUpdated, response, err := atlassian.Workflow.Updates(context.Background(), payload, expand)
if err != nil {
log.Println("Unable to update the workflows(s): ", err)
log.Println(response.Bytes.String())
log.Fatal(err)
}
workflowBuffer, _ := json.MarshalIndent(workflowsUpdated, "", "\t")
fmt.Println(string(workflowBuffer))
}
POST /rest/api/{2-3}/workflows/update/validation
Validates the update of one or more workflows. This method allows you to validate changes to workflows before they are applied.
The validation checks for potential issues that could prevent the workflows from being updated successfully. The validation process will check for conditions such as:
Whether the transitions are valid.
Whether the status and transition names are unique within the workflow.
If the validation fails, a list of validation errors is returned, which should be resolved before applying the changes.
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/ctreminiom/go-atlassian/v2/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
var (
host = os.Getenv("SITE")
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.WorkflowUpdatesPayloadScheme{
Statuses: []*models.WorkflowStatusUpdateScheme{
{
ID: "10012",
Name: "To Do",
StatusCategory: "TODO",
StatusReference: "f0b24de5-25e7-4fab-ab94-63d81db6c0c0",
},
{
ID: "3",
Name: "In Progress",
StatusCategory: "IN_PROGRESS",
StatusReference: "c7a35bf0-c127-4aa6-869f-4033730c61d8",
},
{
ID: "10002",
Name: "Done",
StatusCategory: "DONE",
StatusReference: "6b3fc04d-3316-46c5-a257-65751aeb8849",
},
},
Workflows: []*models.WorkflowUpdateScheme{
{
DefaultStatusMappings: nil,
ID: "6c91af3d-2ae1-46c1-9009-eb93a10a54d1",
StartPointLayout: nil,
Version: &models.WorkflowDocumentVersionScheme{
ID: "c44b423d-89c9-458d-abb7-89ac4fefebd4",
VersionNumber: 0,
},
},
},
}
payload2 := &models.ValidationOptionsForUpdateScheme{
Payload: payload,
Options: &models.ValidationOptionsLevelScheme{
Levels: []string{"ERROR", "WARNING"},
},
}
messages, response, err := atlassian.Workflow.ValidateUpdateWorkflows(context.Background(), payload2)
if err != nil {
log.Println("Unable to update the workflows(s): ", err)
log.Println(response.Bytes.String())
log.Fatal(err)
}
workflowBuffer, _ := json.MarshalIndent(messages, "", "\t")
fmt.Println(string(workflowBuffer))
}