# Introduction

<div align="center"><img src="https://github.com/ctreminiom/go-atlassian/assets/16035390/f73c7a54-ff48-454a-9821-f3d391ccd9d8" alt=""></div>

[![Releases](https://img.shields.io/github/v/release/ctreminiom/go-atlassian)](https://github.com/ctreminiom/go-atlassian/releases/latest) [![Testing](https://github.com/ctreminiom/go-atlassian/actions/workflows/test.yml/badge.svg)](https://github.com/ctreminiom/go-atlassian/actions/workflows/test.yml) [![codecov](https://codecov.io/gh/ctreminiom/go-atlassian/branch/main/graph/badge.svg?token=G0KPNMTIRV)](https://codecov.io/gh/ctreminiom/go-atlassian) [![Go Reference](https://pkg.go.dev/badge/github.com/ctreminiom/go-atlassian.svg)](https://pkg.go.dev/github.com/ctreminiom/go-atlassian) [![Go Report Card](https://goreportcard.com/badge/ctreminiom/go-atlassian)](https://goreportcard.com/report/github.com/ctreminiom/go-atlassian) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fctreminiom%2Fgo-atlassian.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fctreminiom%2Fgo-atlassian?ref=badge_shield) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/fe5c1b3c9fd64f84989ae51c42803456)](https://app.codacy.com/gh/ctreminiom/go-atlassian/dashboard?utm_source=gh\&utm_medium=referral\&utm_content=\&utm_campaign=Badge_grade) ![GitHub](https://img.shields.io/github/license/ctreminiom/go-atlassian) [![Mentioned in Awesome Go-Atlassian](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go#third-party-apis) [![OpenSSF Best Practices](https://bestpractices.coreinfrastructure.org/projects/4861/badge)](https://bestpractices.coreinfrastructure.org/projects/4861) [![OpenSSF Best Practices](https://img.shields.io/ossf-scorecard/github.com/ctreminiom/go-atlassian?label=openssf%20scorecard\&style=flat)](https://img.shields.io/ossf-scorecard/github.com/ctreminiom/go-atlassian?label=openssf%20scorecard\&style=flat) [![Documentation](https://img.shields.io/badge/%F0%9F%92%A1%20go-documentation-00ACD7.svg?style=flat)](https://docs.go-atlassian.io/) [![Sourcegraph](https://sourcegraph.com/github.com/ctreminiom/go-atlassian/-/badge.svg)](https://sourcegraph.com/github.com/ctreminiom/go-atlassian?badge) [![Dependency Review](https://github.com/ctreminiom/go-atlassian/actions/workflows/dependency-review.yml/badge.svg)](https://github.com/ctreminiom/go-atlassian/actions/workflows/dependency-review.yml) [![Analysis](https://github.com/ctreminiom/go-atlassian/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/ctreminiom/go-atlassian/actions/workflows/codeql-analysis.yml)

**go-atlassian** is a Go library that provides a simple and convenient way to interact with various Atlassian products' REST APIs. [Atlassian](https://developer.atlassian.com/cloud/) 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.

***

### 🚀Features

* 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](https://docs.go-atlassian.io/jira-software-cloud/introduction) and examples to help developers get started with using the library.

***

### 📁 Installation

If you do not have [Go](https://golang.org/) installed yet, you can find installation instructions [here](https://golang.org/doc/install). 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
```

***

### 📪 Packages

Then import the package into your project as you normally would. You can import the following packages:

<table data-full-width="true"><thead><tr><th>Module</th><th>Path</th><th>URL's</th></tr></thead><tbody><tr><td>Jira v2</td><td><code>github.com/ctreminiom/go-atlassian/v2/jira/v2</code></td><td><a href="https://docs.go-atlassian.io/jira-software-cloud/introduction">Getting Started</a></td></tr><tr><td>Jira v3</td><td><code>github.com/ctreminiom/go-atlassian/v2/jira/v3</code></td><td><a href="https://docs.go-atlassian.io/jira-software-cloud/introduction">Getting Started</a></td></tr><tr><td>Jira Software Agile</td><td><code>github.com/ctreminiom/go-atlassian/v2/jira/agile</code></td><td><a href="https://docs.go-atlassian.io/jira-agile/introduction">Getting Started</a></td></tr><tr><td>Jira Service Management</td><td><code>github.com/ctreminiom/go-atlassian/v2/jira/sm</code></td><td><a href="https://docs.go-atlassian.io/jira-service-management/introduction">Getting Started</a></td></tr><tr><td>Jira Assets</td><td><code>github.com/ctreminiom/go-atlassian/v2/assets</code></td><td><a href="https://docs.go-atlassian.io/jira-assets/overview">Getting Started</a></td></tr><tr><td>Confluence</td><td><code>github.com/ctreminiom/go-atlassian/v2/confluence</code></td><td><a href="https://docs.go-atlassian.io/confluence-cloud/introduction">Getting Started</a></td></tr><tr><td>Confluence v2</td><td><code>github.com/ctreminiom/go-atlassian/v2/confluence/v2</code></td><td><a href="https://docs.go-atlassian.io/confluence-cloud/v2/introduction">Getting Started</a></td></tr><tr><td>Admin Cloud</td><td><code>github.com/ctreminiom/go-atlassian/v2/admin</code></td><td><a href="https://docs.go-atlassian.io/atlassian-admin-cloud/overview">Getting Started</a></td></tr><tr><td>Bitbucket Cloud <em>(In Progress)</em><br></td><td><code>github.com/ctreminiom/go-atlassian/v2/bitbucket</code></td><td><a href="https://docs.go-atlassian.io/bitbucket-cloud/introduction">Getting Started</a></td></tr></tbody></table>

***

### 🔨 Usage

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](https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/).

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.

```go
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.

```go
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")
```

### ☕Cookbooks

For detailed examples and usage of the go-atlassian library, please refer to our [**Cookbook**](https://docs.go-atlassian.io/cookbooks). This section provides step-by-step guides and code samples for common tasks and scenarios.

***

### 🌍 Services

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.

```go
// 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.

***

### 🎉 Implementation

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.

```go
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](https://docs.go-atlassian.io/) contains several examples on how to use each service function.

### 📪Call a RAW API Endpoint

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

```go
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)  
}
```

***

### ✍️ Contributions

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](https://github.com/golang/go/wiki/CodeReviewComments).
* Create a pull request with a description of your changes.

Again, contributions are greatly appreciated!

***

### 💡 Inspiration

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.

***

### 📝 License

Copyright © 2023 [Carlos Treminio](https://github.com/ctreminiom). This project is [MIT](https://opensource.org/licenses/MIT) licensed.

[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fctreminiom%2Fgo-atlassian.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fctreminiom%2Fgo-atlassian?ref=badge_large)

***

### 🤝 Special Thanks

We would like to extend our sincere thanks to the following sponsors for their generous support:

* [Atlassian](https://www.atlassian.com/) for providing us Atlassian Admin/Jira/Confluence Standard licenses.
* [JetBrains](https://www.jetbrains.com/) for providing us with free licenses of [GoLand](https://www.jetbrains.com/pycharm/)
* [GitBook](https://www.gitbook.com/) for providing us non-profit / open-source plan so hence I would like to express my thanks here.

&#x20;


# Cookbooks


# Export Issue History

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.

## Step 1: Set up the project

1. Create a new directory for your project.
2. Open a terminal and navigate to the project directory.
3. Initialize a new Go module using the following command:

```bash
go mod init <module-name>
```

## Step 2: Install the "go-atlassian" library

In the terminal, run the following command to install the "go-atlassian" library:

```bash
go get -v github.com/ctreminiom/go-atlassian
```

## Step 3: Import the necessary packages

1. Create a new Go file (e.g., `main.go`) in your project directory.
2. Open the file and import the required packages:

{% code fullWidth="true" %}

```go
package main

import (
	"encoding/csv"
	"fmt"
	"log"
	"os"

	jira "github.com/ctreminiom/go-atlassian/jira/v2"
)
```

{% endcode %}

## Step 4: Authenticate with Jira

In the `main` function, create a new Jira client and authenticate using your Jira URL, username, and API token:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Step 5: Execute the JQL query

Add the following code inside the `main` function to execute the JQL query and retrieve the issues:

{% code fullWidth="true" %}

```go
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
}
```

{% endcode %}

## Step 6: Extract the issue history

Iterate over the retrieved issues and extract the changelog information.

{% code fullWidth="true" %}

```go
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,
			})
		}
	}
}
```

{% endcode %}

## Step 7: Save the issue history to a CSV file

Create a new CSV file and write the issue history data to it:

{% code fullWidth="true" %}

```go
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")
```

{% endcode %}

## Step 8: Run the program

1. Save the `main.go` file.
2. In the terminal, navigate to your project directory

<figure><img src="/files/plqmQGdE7asNXno0DkEk" alt=""><figcaption></figcaption></figure>


# Create Jira Issue

In this article, I would be showing you how to create a Jira issue using the "go-atlassian" library.

## Step 1: Set up the project

1. Create a new directory for your project.
2. Open a terminal and navigate to the project directory.
3. Initialize a new Go module using the following command:

```bash
go mod init <module-name>
```

## Step 2: Install the "go-atlassian" library

In the terminal, run the following command to install the "go-atlassian" library:

```bash
go get -v github.com/ctreminiom/go-atlassian
```

## Step 3: Import the necessary packages

1. Create a new Go file (e.g., `main.go`) in your project directory.
2. Open the file and import the required packages:

{% code fullWidth="true" %}

```go
package main

import (
	"fmt"
	"log"
	"os"

	jira "github.com/ctreminiom/go-atlassian/jira/v2"
)
```

{% endcode %}

{% hint style="warning" %}
You can use the V2 and V3 Jira endpoint versions.
{% endhint %}

## Step 4: Authenticate with Jira

In the `main` function, create a new Jira client and authenticate using your Jira URL, username, and API token:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Step 5: Custom fields definition

**OPTIONAL,** you can define custom-fields values you want to set on the issue creation. This library supports the following custom-fields types:

<table><thead><tr><th>Custom-field Types<select multiple><option value="ca61adce4a714a1686153f2794c10e43" label="Groups" color="blue"></option><option value="894f4b6ba00545eaab5ac53d6e1f018d" label="Group" color="blue"></option><option value="c265f3ce819c441194679709c4728a8c" label="URL&#x27;s" color="blue"></option><option value="22578cc0c04f41c897ef4825b184875f" label="Text" color="blue"></option><option value="525132e454db46e285e53926caf6da23" label="DateTime" color="blue"></option><option value="7f88f2d3a7f44e70a5cebc5904c84dc3" label="Date" color="blue"></option><option value="6a978dc0976a45b8acaade7f5ca67f54" label="Cascading" color="blue"></option></select></th><th>Custom-field Types<select multiple><option value="edaf8f53ecf94c25a1f7f9c7e80f4b4f" label="MultiSelect" color="blue"></option><option value="76443721591f437f8cc465df959915f0" label="Select" color="blue"></option><option value="db958f7edd4742f29fa7bba3d6d12287" label="RadioButton" color="blue"></option><option value="65039e04087f46f4a833bcf94728620b" label="User" color="blue"></option><option value="e833285c3acb45cf9d8f106d72e5b5df" label="Users" color="blue"></option><option value="3bd70347b9c8468a8fe32a1c4a33bdd1" label="Number" color="blue"></option><option value="a6abbf07433245d3bf1c66a58182d0b2" label="CheckBox" color="blue"></option></select></th></tr></thead><tbody><tr><td><span data-option="ca61adce4a714a1686153f2794c10e43">Groups, </span><span data-option="894f4b6ba00545eaab5ac53d6e1f018d">Group, </span><span data-option="c265f3ce819c441194679709c4728a8c">URL's, </span><span data-option="22578cc0c04f41c897ef4825b184875f">Text, </span><span data-option="525132e454db46e285e53926caf6da23">DateTime, </span><span data-option="7f88f2d3a7f44e70a5cebc5904c84dc3">Date, </span><span data-option="6a978dc0976a45b8acaade7f5ca67f54">Cascading</span></td><td><span data-option="edaf8f53ecf94c25a1f7f9c7e80f4b4f">MultiSelect, </span><span data-option="76443721591f437f8cc465df959915f0">Select, </span><span data-option="db958f7edd4742f29fa7bba3d6d12287">RadioButton, </span><span data-option="65039e04087f46f4a833bcf94728620b">User, </span><span data-option="e833285c3acb45cf9d8f106d72e5b5df">Users, </span><span data-option="3bd70347b9c8468a8fe32a1c4a33bdd1">Number, </span><span data-option="a6abbf07433245d3bf1c66a58182d0b2">CheckBox</span></td></tr><tr><td></td><td></td></tr></tbody></table>

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Step 6: Create an issue

Create a new issue using the `Create` method and set the custom fields:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

{% hint style="info" %}
Make sure to replace **`YOUR_PROJECT_KEY`** with the actual project key, and set the appropriate values for the other required fields like `Summary`, `Type`, `Assignee`, `Reporter`, etc.
{% endhint %}

## Step 7: Run the program

1. Save the `main.go` file.
2. In the terminal, navigate to your project directory.
3. 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.

<figure><img src="/files/1iymHYSocNsuyNr4NHsC" alt=""><figcaption></figcaption></figure>


# Extract customfields from issue(s)

## Introduction

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.

## Extract from a single issue

The following methods can be used to extract the customfield information from **one** issue.

### **ParseMultiSelectCustomField**  <a href="#parse-multiselect-customfield" id="parse-multiselect-customfield"></a>

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.&#x20;

{% code overflow="wrap" fullWidth="true" %}

```go
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)
}
```

{% endcode %}

### ParseSelectCustomField  <a href="#parse-select-customfield" id="parse-select-customfield"></a>

ParseSelectCustomField parses a select custom field from the given buffer data associated with the specified custom field ID and returns a **CustomFieldContextOptionScheme** struct

{% code overflow="wrap" fullWidth="true" %}

```go
_, 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)
```

{% endcode %}

### ParseCascadingSelectCustomField <a href="#parse-cascading-customfield" id="parse-cascading-customfield"></a>

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.

{% code overflow="wrap" fullWidth="true" %}

```go
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)
```

{% endcode %}

### ParseDatePickerCustomField  <a href="#parse-datepicker-customfield" id="parse-datepicker-customfield"></a>

ParseDatePickerCustomField parses the datepicker customfield from the given buffer data associated with the specified custom field ID and returns a struct time.Time value

{% code overflow="wrap" fullWidth="true" %}

```go
_, 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())
```

{% endcode %}

### ParseDateTimeCustomField  <a href="#parse-datetime-customfield" id="parse-datetime-customfield"></a>

ParseDateTimeCustomField parses the datetime customfield from the given buffer data associated with the specified custom field ID and returns a struct time.Time value.

{% code overflow="wrap" fullWidth="true" %}

```go
_, 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())
```

{% endcode %}

### ParseMultiUserPickerCustomField <a href="#parse-multi-userpicker-customfield" id="parse-multi-userpicker-customfield"></a>

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.

{% code overflow="wrap" fullWidth="true" %}

```go
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)
}
```

{% endcode %}

### ParseMultiGroupPickerCustomField <a href="#parse-grouppicker-customfield" id="parse-grouppicker-customfield"></a>

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.

{% code overflow="wrap" fullWidth="true" %}

```go
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)
}
```

{% endcode %}

### ParseFloatCustomField <a href="#parse-float-customfield" id="parse-float-customfield"></a>

ParseFloatCustomField parses a float custom field from the given buffer data associated with the specified custom field ID and returns string.

{% code overflow="wrap" fullWidth="true" %}

```go
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)
```

{% endcode %}

### ParseSprintCustomField <a href="#parse-sprints-customfield" id="parse-sprints-customfield"></a>

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.

{% code overflow="wrap" fullWidth="true" %}

```go
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)
}
```

{% endcode %}

### ParseLabelCustomField <a href="#parse-labels-customfield" id="parse-labels-customfield"></a>

ParseLabelCustomField parses a textfield slice custom field from the given buffer data associated with the specified custom field ID and returns string slice.

{% code overflow="wrap" fullWidth="true" %}

```go
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)
}
```

{% endcode %}

### ParseMultiVersionCustomField <a href="#parse-versionpicker-customfield" id="parse-versionpicker-customfield"></a>

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.

{% code overflow="wrap" fullWidth="true" %}

```go
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)
}
```

{% endcode %}

### ParseUserPickerCustomField  <a href="#parse-userpicker-customfield" id="parse-userpicker-customfield"></a>

ParseUserPickerCustomField parses a user custom field from the given buffer data associated with the specified custom field ID and returns a struct of UserDetailScheme.

{% code overflow="wrap" fullWidth="true" %}

```go
_, 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)
```

{% endcode %}

### ParseAssetCustomField <a href="#parse-assets-customfield" id="parse-assets-customfield"></a>

ParseAssetCustomField parses the Jira assets elements from the given buffer data associated with the specified custom field ID and returns a struct **CustomFieldAssetScheme** slice.

{% code overflow="wrap" fullWidth="true" %}

```go
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)
}
```

{% endcode %}

### ParseStringCustomField  <a href="#parse-textfield-customfield" id="parse-textfield-customfield"></a>

ParseStringCustomField parses a textfield custom field from the given buffer data associated with the specified custom field ID and returns string.

{% code fullWidth="true" %}

```go
_, 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)
```

{% endcode %}

## Extract from multiple issues

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 <a href="#parse-multiselect-customfields" id="parse-multiselect-customfields"></a>

ParseMultiSelectCustomFields extracts and parses multi-select custom field data from a given bytes.Buffer from multiple issues.&#x20;

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.&#x20;

* 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.

{% code overflow="wrap" fullWidth="true" %}

```go
_, 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)
	}
}
```

{% endcode %}

### ParseSelectCustomFields  <a href="#parse-select-customfields" id="parse-select-customfields"></a>

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.

{% code overflow="wrap" fullWidth="true" %}

```go
_, 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)
}
```

{% endcode %}

### ParseCascadingCustomFields  <a href="#parse-cascading-customfields" id="parse-cascading-customfields"></a>

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.

{% code overflow="wrap" fullWidth="true" %}

```go
_, 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)
}
```

{% endcode %}

### ParseMultiUserPickerCustomFields  <a href="#parse-multi-userpicker-customfields" id="parse-multi-userpicker-customfields"></a>

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.&#x20;

* 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.&#x20;
* If the custom field data cannot be parsed successfully, an error is returned.

{% code overflow="wrap" fullWidth="true" %}

```go
_, 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)
	}
}
```

{% endcode %}

### ParseDatePickerCustomFields  <a href="#parse-datepicker-customfields" id="parse-datepicker-customfields"></a>

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.&#x20;
* The function parses this structure to extract and organize the custom field values.&#x20;
* If the custom field data cannot be parsed successfully, an error is returned.

{% code overflow="wrap" fullWidth="true" %}

```go
_, 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())
}
```

{% endcode %}

### ParseDateTimeCustomFields  <a href="#parse-datetime-customfields" id="parse-datetime-customfields"></a>

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.&#x20;
* The function parses this structure to extract and organize the custom field values.&#x20;
* If the custom field data cannot be parsed successfully, an error is returned.

{% code overflow="wrap" fullWidth="true" %}

```go
_, 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())
}
```

{% endcode %}

### ParseMultiGroupPickerCustomFields  <a href="#parse-grouppicker-customfields" id="parse-grouppicker-customfields"></a>

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.&#x20;

* 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.&#x20;
* The function parses this structure to extract and organize the custom field values.&#x20;
* If the custom field data cannot be parsed successfully, an error is returned.

{% code overflow="wrap" fullWidth="true" %}

```go
_, 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)
	}
}
```

{% endcode %}

### ParseFloatCustomFields  <a href="#parse-float-customfields" id="parse-float-customfields"></a>

ParseFloatCustomFields extracts and parses the float customfield information from multiple issues using a bytes.Buffer.&#x20;

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.&#x20;

* 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.&#x20;
* The function parses this structure to extract and organize the custom field values.&#x20;
* If the custom field data cannot be parsed successfully, an error is returned.

{% code overflow="wrap" fullWidth="true" %}

```go
_, 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)
}
```

{% endcode %}

### ParseStringCustomFields  <a href="#parse-textfield-customfields" id="parse-textfield-customfields"></a>

ParseStringCustomFields extracts and parses the textfield customfield information from multiple issues using a bytes.Buffer.&#x20;

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.&#x20;
* The function parses this structure to extract and organize the custom field values.&#x20;
* If the custom field data cannot be parsed successfully, an error is returned.

{% code overflow="wrap" fullWidth="true" %}

```go
_, 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)
}
```

{% endcode %}

### ParseUserPickerCustomFields <a href="#parse-userpicker-customfields" id="parse-userpicker-customfields"></a>

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.&#x20;
* The function parses this structure to extract and organize the custom field values.&#x20;
* If the custom field data cannot be parsed successfully, an error is returned.

{% code overflow="wrap" fullWidth="true" %}

```go
_, 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)
}
```

{% endcode %}

### ParseSprintCustomFields  <a href="#parse-sprints-customfields" id="parse-sprints-customfields"></a>

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.&#x20;
* The function parses this structure to extract and organize the custom field values.&#x20;
* If the custom field data cannot be parsed successfully, an error is returned.

{% code overflow="wrap" fullWidth="true" %}

```go
_, 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)
	}
}
```

{% endcode %}

### ParseLabelCustomFields  <a href="#parse-labels-customfields" id="parse-labels-customfields"></a>

ParseLabelCustomFields extracts and parses the label customfield information from multiple issues using a bytes.Buffer.&#x20;

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.&#x20;
* The function parses this structure to extract and organize the custom field values.&#x20;
* If the custom field data cannot be parsed successfully, an error is returned.

{% code overflow="wrap" fullWidth="true" %}

```go
_, 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)
}
```

{% endcode %}

### ParseMultiVersionCustomFields  <a href="#parse-versionpicker-customfields" id="parse-versionpicker-customfields"></a>

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.&#x20;
* The function parses this structure to extract and organize the custom field values.&#x20;
* If the custom field data cannot be parsed successfully, an error is returned.

{% code overflow="wrap" fullWidth="true" %}

```go
_, 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)
	}
}
```

{% endcode %}

### ParseAssetCustomFields  <a href="#parse-assets-customfields" id="parse-assets-customfields"></a>

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.

{% code overflow="wrap" fullWidth="true" %}

```go
_, 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)
	}
}
```

{% endcode %}


# Upload Content Attachment

In this article, I would be showing you how to upload an attachment in a Confluence content using the "go-atlassian" library.

## Step 1: Set up the project

1. Create a new directory for your project.
2. Open a terminal and navigate to the project directory.
3. Initialize a new Go module using the following command:

```bash
go mod init <module-name>
```

## Step 2: Install the "go-atlassian" library

In the terminal, run the following command to install the "go-atlassian" library:

```bash
go get -v github.com/ctreminiom/go-atlassian
```

## Step 3: Import the necessary packages

1. Create a new Go file (e.g., `main.go`) in your project directory.
2. Open the file and import the required packages:

{% code fullWidth="true" %}

```go
package main

import (
	"github.com/ctreminiom/go-atlassian/confluence"
	"log"
	"os"
)
```

{% endcode %}

## Step 4: Authenticate with Confluence

In the `main` function, create a new Confluence client and authenticate using your Atlassian URL, username, and API token:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Step 5: Upload an attachment to a Confluence page

* Define the necessary variables for the page ID, file path, and file name:

{% code fullWidth="true" %}

```go
pageID := "76513281"
filePath := "confluence/mocks/mock.png"
fileName := "mock-00.png"
```

{% endcode %}

* Open the file using the provided file path:

{% code fullWidth="true" %}

```go
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()
```

{% endcode %}

* Upload the attachment using the `Content.Attachment.Create()`method and provide the page ID, file name, and file content:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

{% hint style="info" %}
Make sure to replace `<CONFLUENCE_PAGE_ID>`, `<FILE_PATH>`, and `<FILE_NAME>` with the actual values for your use case.
{% endhint %}

## Step 6: Run the program

1. Save the `main.go` file.
2. In the terminal, navigate to your project directory.
3. Execute the following command to run the program:

```bash
go run main.go
```

This will upload the specified file as an attachment to the Confluence page with the provided page ID.


# Create Jira ITSM Request

In this article, I would be showing you how to create a Service Management customer request with custom-fields.

## Step 1: Set up the project

1. Create a new directory for your project.
2. Open a terminal and navigate to the project directory.
3. Initialize a new Go module using the following command:

```bash
go mod init <module-name>
```

## Step 2: Install the "go-atlassian" library

In the terminal, run the following command to install the "go-atlassian" library:

```bash
go get -v github.com/ctreminiom/go-atlassian
```

## Step 3: Import the necessary packages

1. Create a new Go file (e.g., `main.go`) in your project directory.
2. Open the file and import the required packages:

{% code fullWidth="true" %}

```go
package main

import (
	"fmt"
	"github.com/ctreminiom/go-atlassian/jira/sm"
	"github.com/ctreminiom/go-atlassian/pkg/infra/models"
)
```

{% endcode %}

## Step 4: Authenticate with Jira

In the `main` function, create a new Jira client and authenticate using your Jira URL, username, and API token:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Step 5: Create an ITSM customer request with custom fields

Define the fields you want to set:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

{% hint style="info" %}
A list of the fields required by a customer request type can be obtained using the `sm.RequestType.Fields` method.
{% endhint %}

* Create a new issue using the `Create` method and set the custom fields:

{% code fullWidth="true" %}

```go

ticket, response, err := atlassian.Request.Create(context.Background(), payload, form)
if err != nil {
	log.Fatal(err)
}
```

{% endcode %}

## Step 6: Run the program

1. Save the `main.go` file.
2. In the terminal, navigate to your project directory.
3. Execute the following command to run the program:

```bash
go run main.go
```

This will create a new ITSM customer request in Jira with the specified custom field values.

<figure><img src="/files/6otffTkwKNfLMuAiiBBG" alt=""><figcaption></figcaption></figure>


# Edit Jira Issue (Explicit)

In this article, I would be showing you how to edit a Jira issue using the "go-atlassian" library.

## Step 1: Set up the project

1. Create a new directory for your project.
2. Open a terminal and navigate to the project directory.
3. Initialize a new Go module using the following command:

```bash
go mod init <module-name>
```

## Step 2: Install the "go-atlassian" library

In the terminal, run the following command to install the "go-atlassian" library:

```bash
go get -v github.com/ctreminiom/go-atlassian
```

## Step 3: Import the necessary packages

1. Create a new Go file (e.g., `main.go`) in your project directory.
2. Open the file and import the required packages:

{% code fullWidth="true" %}

```go
package main

import (
	"fmt"
	"log"
	"os"

	jira "github.com/ctreminiom/go-atlassian/jira/v2"
)
```

{% endcode %}

{% hint style="warning" %}
You can use the V2 and V3 Jira endpoint versions.
{% endhint %}

## Step 4: Authenticate with Jira

In the `main` function, create a new Jira client and authenticate using your Jira URL, username, and API token:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Step 5: Create Issue Payload

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:

{% code fullWidth="true" %}

```go
var payload = models.IssueSchemeV2{
	Fields: &models.IssueFieldsSchemeV2{
		Summary:  "New summary test",
		Priority: &models.PriorityScheme{Name: "Minor"},
	},
}
```

{% endcode %}

* For custom-fields, you can use the \&models.CustomFields struct to inyect the customfield's by type, something like this:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

* Finally, call the Issue.Update() method and update the issue

{% code fullWidth="true" %}

```go
_, err = atlassian.Issue.Update(context.Background(), "KP-2", false, &payload, &customFields, nil)
if err != nil {
	log.Fatal(err)
}
```

{% endcode %}

## Step 6: Run the program

1. Save the `main.go` file.
2. In the terminal, navigate to your project directory.
3. Execute the following command to run the program:

```bash
go run main.go
```


# Edit Jira Issue (Implicit)

In this article, I would be showing you how to edit a Jira issue with the VERB operation using the "go-atlassian" library.

## Step 1: Set up the project

1. Create a new directory for your project.
2. Open a terminal and navigate to the project directory.
3. Initialize a new Go module using the following command:

```bash
go mod init <module-name>
```

## Step 2: Install the "go-atlassian" library

In the terminal, run the following command to install the "go-atlassian" library:

```bash
go get -v github.com/ctreminiom/go-atlassian
```

## Step 3: Import the necessary packages

1. Create a new Go file (e.g., `main.go`) in your project directory.
2. Open the file and import the required packages:

{% code fullWidth="true" %}

```go
package main

import (
	"fmt"
	"log"
	"os"

	jira "github.com/ctreminiom/go-atlassian/jira/v2"
)
```

{% endcode %}

{% hint style="warning" %}
You can use the V2 and V3 Jira endpoint versions.
{% endhint %}

## Step 4: Authenticate with Jira

In the `main` function, create a new Jira client and authenticate using your Jira URL, username, and API token:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Step 5: Create Issue Payload

The fields of an issue may also be updated in more flexible ways using the <mark style="color:blue;">**SET**</mark>, <mark style="color:blue;">**ADD**</mark> and <mark style="color:blue;">**REMOVE**</mark> operations. Not all fields support all operations, but as a general rule single value fields support <mark style="color:blue;">**SET**</mark>, whereas multi-value fields support <mark style="color:blue;">**SET**</mark>, <mark style="color:blue;">**ADD**</mark> and <mark style="color:blue;">**REMOVE**</mark>, where <mark style="color:blue;">**SET**</mark> replaces the field contents while <mark style="color:blue;">**ADD**</mark> and <mark style="color:blue;">**REMOVE**</mark> add or remove one or more values from the the current list of values.

{% code fullWidth="true" %}

```go
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",
		},
	},
})
```

{% endcode %}

{% code fullWidth="true" %}

```go
var payload = models.IssueSchemeV2{
	Fields: &models.IssueFieldsSchemeV2{
		Summary:  "New summary test",
		Priority: &models.PriorityScheme{Name: "Minor"},
	},
}
```

{% endcode %}

* Finally, call the Issue.Update() method and update the issue

{% code fullWidth="true" %}

```go
_, err = client.Issue.Update(context.Background(), "KP-2", false, &payload, nil, operations)
if err != nil {
	log.Fatal(err)
}
```

{% endcode %}

## Step 6: Run the program

1. Save the `main.go` file.
2. In the terminal, navigate to your project directory.
3. Execute the following command to run the program:

```bash
go run main.go
```


# Create Jira Workflow

In this article, I would be showing you how to create Jira workflow and append transitions using `go-atlassian`

## Step 1: Create a new Go project

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:

```bash
go mod init your-module-name
```

## Step 2: Install the "go-atlassian" library&#x20;

To use the "go-atlassian" library, you need to install it as a dependency in your project. Run the following command:

```bash
go get github.com/ctreminiom/go-atlassian
```

## Step 3: Import the required packages&#x20;

Create a new Go file, e.g., `main.go`, and import the necessary packages:

{% code fullWidth="true" %}

```go
package main

import (
	"fmt"
	"log"

	jira "github.com/ctreminiom/go-atlassian/jira/v2"
)
```

{% endcode %}

## Step 4: Set up Jira API client&#x20;

Initialize the Jira API client with your Jira base URL and API token:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Step 5: Create a workflow&#x20;

To create a new workflow, we need to the create the `models.WorkflowPayloadScheme` payload struct with the following information.

1. Worfklow Name.
2. Workflow Description.
3. Workflow Statuses.
4. Workflow Transitions.

Let's try to create a workflow with **directed** transitions and **all-to-all** transitions, something like this:

<div data-full-width="true"><figure><img src="/files/Mz5iGQ1dHRRb1GNtdvnu" alt=""><figcaption></figcaption></figure></div>

### Step 5.1: Extract the status ID's

The first step to create a Jira workflow is recognize what's gonna be the statuses you want to use.

{% hint style="info" %} <mark style="color:blue;">**Statuses**</mark> represent the different stages that an issue can go through in a workflow.
{% endhint %}

In this particular example, we're needed to use the following statuses:

* Open
* In Progress
* QA
* Waiting for approval
* Escalated
* Closed
* Resolved

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

&#x20;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.

<div align="left" data-full-width="false"><figure><img src="/files/WaxZ8uWwFaO63FXCtyMq" alt=""><figcaption></figcaption></figure></div>

With the status ID's, we can proceed with the creation of the workflow statuses payload

{% code fullWidth="true" %}

```go
var workflowStatuses []*models.WorkflowTransitionScreenScheme
for _, status := range statusesAsMap {

	workflowStatuses = append(workflowStatuses, &models.WorkflowTransitionScreenScheme{
		ID:         status.ID,
		Properties: nil,
	})
}
```

{% endcode %}

### Step 5.2: Create the workflow transitions

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.&#x20;

**For example:** an issue in the "**Open**" status can transition to the "**In Progress**" status when work begins on it.&#x20;

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.

{% code fullWidth="true" %}

```go
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",
})
```

{% endcode %}

### Step 5.3: Create the workflow&#x20;

In conclusion, we can combine the statuses and transitions structs and create the workflow using the structs created on the previous steps.

{% code fullWidth="true" %}

```go
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)
```

{% endcode %}

<div data-full-width="true"><figure><img src="/files/quuNNwT0mFQcfCptpnvr" alt=""><figcaption></figcaption></figure></div>

## Git Gist File

{% embed url="<https://gist.github.com/ctreminiom/9b2f06be03ebf71278373bbbb5b06aee>" fullWidth="false" %}


# Add CustomField to Screen

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.

1. **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.
2. **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.
3. **Screen Tab Fields:**
   * Screen tab fields are the individual fields (e.g., standard or custom fields) displayed within a screen tab.

## Step 1: Create a new Go project

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:

```bash
go mod init your-module-name
```

## Step 2: Install the "go-atlassian" library&#x20;

To use the "go-atlassian" library, you need to install it as a dependency in your project. Run the following command:

```bash
go get github.com/ctreminiom/go-atlassian
```

## Step 3: Import the required packages&#x20;

Create a new Go file, e.g., `main.go`, and import the necessary packages:

{% code fullWidth="true" %}

```go
package main

import (
	"fmt"
	"log"

	jira "github.com/ctreminiom/go-atlassian/jira/v2"
)
```

{% endcode %}

## Step 4: Set up Jira API client&#x20;

Initialize the Jira API client with your Jira base URL and API token:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Step 5: Extract the issue type screen scheme

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.

{% code fullWidth="true" %}

```go
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
		}
	}
}
```

{% endcode %}

## Step 6: Extract the screen schemes

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

{% code fullWidth="true" %}

```go
// --------------------------------------------------
// 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)
}
```

{% endcode %}

## Step 7: Extract the screen IDs

The next step is extract the screen ID's from the screen schemes, you can use this code to extract the screen IDs.

{% code fullWidth="true" %}

```go
// --------------------------------------------------
// 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)
```

{% endcode %}

## Step 8: Add the fields on the project screens

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:

{% code fullWidth="true" %}

```go
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)
	}
```

{% endcode %}

When you run the code, the custom-fields selected will be available on the project :thumbsup::tada:.

<div data-full-width="true"><figure><img src="/files/Pf4pfWBYqGZ4tGPIw5rb" alt=""><figcaption></figcaption></figure></div>

<div data-full-width="true"><figure><img src="/files/1AcBsXWchiZqMD3gQ1Go" alt=""><figcaption></figcaption></figure></div>


# Search Project Boards

In this article, I would be showing you how to extract the boards associated with a Jira project using `go-atlassian`

## Step 1: Create a new Go project

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:

```bash
go mod init your-module-name
```

## Step 2: Install the "go-atlassian" library&#x20;

To use the "go-atlassian" library, you need to install it as a dependency in your project. Run the following command:

```bash
go get github.com/ctreminiom/go-atlassian
```

## Step 3: Import the required packages&#x20;

Create a new Go file, e.g., `main.go`, and import the necessary packages:

{% code fullWidth="true" %}

```go
package main

import (
	"fmt"
	"log"

	jira "github.com/ctreminiom/go-atlassian/agile"
)
```

{% endcode %}

## Step 4: Set up Jira Agile API client&#x20;

Initialize the Jira Agile API client with your Jira base URL and API token:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Step 5: Extract the boards

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.

{% code fullWidth="true" %}

```go
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
}
```

{% endcode %}


# Get User Last-Login 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`

## Step 1: Create a new Go project

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:

```bash
go mod init your-module-name
```

## Step 2: Install the "go-atlassian" library&#x20;

To use the "go-atlassian" library, you need to install it as a dependency in your project. Run the following command:

```bash
go get github.com/ctreminiom/go-atlassian
```

## Step 3: Import the required packages&#x20;

Create a new Go file, e.g., `main.go`, and import the necessary packages:

{% code fullWidth="true" %}

```go
package main

import (
	"fmt"
	"log"

	"github.com/ctreminiom/go-atlassian/admin"
)
```

{% endcode %}

## Step 4: Set up Cloud Admin client&#x20;

Initialize the Atlassian Admin client with your API token:

{% code fullWidth="true" %}

```go
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")
}
```

{% endcode %}

## Step 5: Extract the organization ID

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:

<figure><img src="/files/8cSgTiDKJglG3wNNCiQX" alt=""><figcaption></figcaption></figure>

## Step 6: Extract the organization users

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.

{% code fullWidth="true" %}

```go
// 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)
}
```

{% endcode %}

## Step 7: Extract the last-login date

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:

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}


# Remove User Access


# Suspend User Access


# Restore User Access


# Extract Project Administrators


# Search Jira User By Email


# Search Contents By CQL


# Cascade Permissions from Parent to Child


# Page Permission Helper


# Atlassian SCIM Onboarding


# Create User via SCIM


# Issue Permission Helper


# Introduction

## Overview

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.

## ADF Format

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.

{% code fullWidth="true" %}

```go
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",
		},
	},
})
```

{% endcode %}

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.

{% embed url="<https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/>" %}
Official Documentation
{% endembed %}

<table data-view="cards"><thead><tr><th></th></tr></thead><tbody><tr><td><code>body</code> in comments, including where comments are used in issue, issue link, and transition resources.</td></tr><tr><td><code>comment</code> in worklogs</td></tr><tr><td><code>description</code> and <code>environment</code> fields in issues.</td></tr></tbody></table>

To search issues using a JQL query, use the **Issue.Search** service function.

{% code fullWidth="true" %}

```go
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)
```

{% endcode %}


# Announcement Banner

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 announcement banner configuration

`GET /rest/api/{2/3}/announcementBanner`

Get returns the current announcement banner configuration.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

### Update announcement banner configuration

`PUT /rest/api/{2-3}/announcementBanner`

Update updates the announcement banner configuration.

{% code fullWidth="true" %}

```go
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)
}

```

{% endcode %}

<div data-full-width="true"><figure><img src="/files/z5uhL5hpIo0UpJJBIa4z" alt=""><figcaption></figcaption></figure></div>


# Application Roles

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.&#x20;

<figure><img src="/files/IM6XSkycZPzLxq2v6eD7" alt=""><figcaption></figcaption></figure>

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 all application roles

`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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get application role

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# 🛡️ Audit records

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:

<table data-view="cards"><thead><tr><th></th></tr></thead><tbody><tr><td>User login and logout events</td></tr><tr><td>Issue creation, modification, and deletion events</td></tr><tr><td>Workflow transition events</td></tr><tr><td>Project creation, modification, and deletion events</td></tr><tr><td>User management events such as user creation, modification, and deletion</td></tr><tr><td>User management events such as user creation, modification, and deletion</td></tr></tbody></table>

<figure><img src="/files/GDM2wKdMhaibSCumdngY" alt=""><figcaption></figcaption></figure>

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 audit records

`GET /rest/api/{2-3}/auditing/record`

This method allows you to retrieve the audit records for specific activities that have occurred within Jira.&#x20;

{% code fullWidth="true" %}

```go
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")
	}
}
```

{% endcode %}


# Dashboards

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.

![.gif created using the video https://www.youtube.com/watch?v=VswPTqLQzqA](/files/-MXwwXJJmMHzytdvgCZA)

Here are some key elements of Jira dashboards:

1. **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.
2. **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.
3. **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.
4. **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 all dashboards

`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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Create dashboard

`POST /rest/api/{2-3}/dashboard`

{% hint style="warning" %}
This is an experimental endpoint
{% endhint %}

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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Search for dashboards

`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.&#x20;

For example, dashboards with a particular name. When multiple attributes are specified only filters matching all attributes are returned.

{% code fullWidth="true" %}

```go
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)
			}
		}
	}
}
```

{% endcode %}

## Get dashboard

`GET /rest/api/{2-3}/dashboard/{id}`

Returns a dashboard using the *dashboard-id*

{% hint style="warning" %}
&#x20;However, to get a dashboard, the dashboard must be shared with the user or the user must own it. Note, users with ***Administer Jira*** [global permission](https://confluence.atlassian.com/x/x4dKLg) are considered owners of the System dashboard. The System dashboard is considered to be shared with all other users.
{% endhint %}

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Update dashboard

`PUT /rest/api/{2-3}/dashboard/{id}`

{% hint style="warning" %}
This is an experimental endpoint
{% endhint %}

Updates a dashboard, replacing all the dashboard details with those provided. **The dashboard to be updated must be owned by the user.**

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete dashboard

`DELETE /rest/api/{2-3}/dashboard/{id}`

{% hint style="warning" %}
This is an experimental endpoint
{% endhint %}

Deletes a dashboard, t**he dashboard to be deleted must be owned by the user.**

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Copy dashboard

`POST /rest/api/{2-3}/dashboard/{id}/copy`

{% hint style="warning" %}
This is an experimental endpoint
{% endhint %}

Copies a dashboard. Any values provided in the `dashboard` parameter replace those in the copied dashboard.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Filters

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.<br>

<figure><img src="/files/sTJyPRUl5dUTz7hrq4UU" alt=""><figcaption></figcaption></figure>

## Create Filter

`POST /rest/api/{2-3}/filter`

This method creates a new filter. The filter is shared according to the [default share scope](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-filters/#api-rest-api-3-filter-post). The filter is not selected as a favorite, the method returns the following information:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

<div data-full-width="true"><img src="/files/-MXzEBfn_bsnfE6eR7oU" alt="Filter permissions on the UI interface"></div>

## Get Favorites

`GET /rest/api/3/filter/favourite`

This method returns the visible favorite filters of the user, the method returns the following information:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get My Filters

`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:

{% code fullWidth="true" %}

```go
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)
		}
	}
}
```

{% endcode %}

## Search Filters

`GET /rest/api/{2-3}/filter/search`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) 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](https://confluence.atlassian.com/x/yodKLg)

    for.
  * filters shared with a public project.
  * filters shared with the public.

{% code fullWidth="true" %}

```go
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))
}
```

{% endcode %}

## Get Filter

`GET /rest/api/{2-3}/filter/{id}`

This method returns a filter using the ID as a parameter, the method returns the following information:

{% code fullWidth="true" %}

```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() {

	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)
}
```

{% endcode %}

## Update Filter

`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:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete Filter

`DELETE /rest/api/{2-3}/filter/{id}`

{% code fullWidth="true" %}

```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() {

	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)
}
```

{% endcode %}

## Change filter owner

`PUT /rest/api/{2-3}/filter/{id}/owner`

{% hint style="warning" %}
This is an experimental endpoint
{% endhint %}

Changes the owner of the filter.

{% code fullWidth="true" %}

```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() {

	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)
}
```

{% endcode %}


# Sharing

This resource represents options for sharing filters. Use it to get share scopes as well as add and remove share scopes from filters.

## Get default share scope

`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:

{% code fullWidth="true" %}

```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() {

	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)
}
```

{% endcode %}

## Get share permissions

`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:

{% code fullWidth="true" %}

```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() {

	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)
	}
}
```

{% endcode %}

## Add share permission

`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:

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get share permission

`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.&#x20;

Sharing with all logged-in users or the public is known as global share permission, the method returns the following information:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete share permission

`DELETE /rest/api/3/filter/{id}/permission/{permissionId}`

Deletes share permission from a filter.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Set default share scope

`PUT /rest/api/3/filter/defaultShareScope`

Sets the default sharing for new filters and dashboards for a user.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Groups

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:

1. **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.
2. **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.
3. **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.
4. **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.

## Create Group

`POST /rest/api/{2-3}/group`

Creates a group

{% code fullWidth="true" %}

```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() {

	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)
}
```

{% endcode %}

## Remove group

`DELETE /rest/api/{2-3}/group`

Deletes a group

{% code fullWidth="true" %}

```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() {

	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)
}

```

{% endcode %}

## Bulk Groups

`GET /rest/api/{2-3}/group/bulk`

{% hint style="warning" %}
This is an experimental endpoint
{% endhint %}

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of groups, the method returns the following information:

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get users from groups

`GET /rest/api/{2-3}/group/member`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of all users in a group

{% code fullWidth="true" %}

```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() {

	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)
	}
}
```

{% endcode %}

## Add user to group

`POST /rest/api/{2-3}/group/user`

Adds a user to a group

{% code fullWidth="true" %}

```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() {

	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)
}
```

{% endcode %}

## Remove user from group

`DELETE /rest/api/{2-3}/group/user`

Removes a user from a group

{% code fullWidth="true" %}

```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() {

	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)
}
```

{% endcode %}


# Issues

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.

![Issue View](/files/-MY1ajXFui4jRhqUZbJI)

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.

## Custom Fields

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.

{% hint style="info" %}
**Note:** For example, the "Story points" custom field with ID = "10000" is referenced as customfield\_10000 for REST calls. You can get this reference identifier by requesting the create metadata for the issue type.
{% endhint %}

{% hint style="success" %}
We support the following custom field types.

* Group(s) Picker
* User(s) Picker
* URL's
* Text&#x20;
* Number
* Date
* DateTime
* Select
* MultiSelect
* RadioButton
* CheckBox
* Cascading Multiselect
  {% endhint %}

The examples below show how to set the values for different types of custom fields in the input data.

{% code fullWidth="true" %}

```go
// 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)
}
```

{% endcode %}

## Create Issue

`POST /rest/api/{2-3}/issue`

Creates an issue or, where the option to create subtasks is enabled in Jira, a subtask

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Bulk create issue

`POST /rest/api/{2-3}/issue/bulk`

Creates issues and, where the option to create subtasks is enabled in Jira, subtasks.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get issue

`GET /rest/api/{2-3}/issue/{issueIdOrKey}`

Returns the details for an issue.

{% code fullWidth="true" %}

```go
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)
		}
	}
}
```

{% endcode %}

## Edit issue

`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**.

### Simple update (implicit set via "fields") <a href="#simple-update-implicit-set-via-fields" id="simple-update-implicit-set-via-fields"></a>

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:

```go
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.

### Operation (verb) based update (explicit verb via "update") <a href="#operation-verb-based-update-explicit-verb-via-update" id="operation-verb-based-update-explicit-verb-via-update"></a>

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.&#x20;

{% hint style="warning" %}
The *editmeta* endpoint is not mapped, yet refer to this [**ticket**](https://github.com/ctreminiom/go-atlassian/issues/18)
{% endhint %}

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:

<pre class="language-go" data-full-width="true"><code class="lang-go">//Issue Update Operations
var operations = &#x26;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.
<strong>err = operations.AddMultiRawOperation("fixVersions", []map[string]interface{}{
</strong>	{
		"remove": map[string]interface{}{
			"name": "Version 00",
		},
	},
	
	{
		"remove": map[string]interface{}{
			"name": "Version 101",
		},
	},
	
	{
		"add": map[string]interface{}{
			"name": "Version 301",
		},
	},
})
</code></pre>

* **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).

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete issue

`DELETE /rest/api/{2-3}/issue/{issueIdOrKey}`

Deletes an issue.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Assign issue

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Send notification for issue

`POST /rest/api/{2-3}/issue/{issueIdOrKey}/notify`

Creates an email notification for an issue and adds it to the mail queue.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get transitions

`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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Transition issue

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Attachments

## Get Jira attachment settings

`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:

{% code fullWidth="true" %}

```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() {

	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)
}
```

{% endcode %}

## Get attachment metadata

`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:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get all metadata for an expanded attachment

`GET /rest/api/{2-3}/attachment/{id}/expand/human`

{% hint style="warning" %}
This is an experimental endpoint
{% endhint %}

Returns the metadata for the contents of an attachment, if it is an archive, and metadata for the attachment itself.&#x20;

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:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete attachment

`DELETE /rest/api/{2-3}/attachment/{id}`

Deletes an attachment from an issue, the method returns the following information:

{% code fullWidth="true" %}

```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() {

	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)
}
```

{% endcode %}

## Add attachment

`POST /rest/api/{2-3}/issue/{issueIdOrKey}/attachments`&#x20;

Adds one or more attachments to an issue. Attachments are posted as multipart/form-data ([RFC 1867](https://www.ietf.org/rfc/rfc1867.txt)).

* The request must have a `X-Atlassian-Token: no-check` header, if not it is blocked. See [Special headers](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#special-request-headers) for more information.
* The name of the multipart/form-data parameter that contains the attachments must be `file`.

{% hint style="warning" %}
It only accepts one attachment at once
{% endhint %}

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Download Attachment

`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.&#x20;

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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}


# Comments

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:

1. Providing context or additional details about an issue.
2. Sharing progress or updates on the issue's status.
3. Asking questions or requesting feedback from other team members.
4. Acknowledging or responding to other comments or feedback.
5. Notifying other users of relevant information or changes.

![](/files/-MY2fjZYYWfGw-qELzwQ)

* **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 comments

`GET /rest/api/{2-3}/issue/{issueIdOrKey}/comment`

Returns all comments for an issue.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get comment

`GET /rest/api/{2-3}/issue/{issueIdOrKey}/comment/{id}`

Returns a comment.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete comment

`DELETE /rest/api/{2-3}/issue/{issueIdOrKey}/comment/{id}`

Deletes a comment.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Add comment

`POST /rest/api/{2-3}/issue/{issueIdOrKey}/comment`

Adds a comment to an issue.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Atlassian Document Format <a href="#atlassian-document-format" id="atlassian-document-format"></a>

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.

### Example 1

![](/files/-MWakTXijeMBnp_lAzxQ)

{% code fullWidth="true" %}

```go
	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/"},
									},
								},
							},
						},
					},
				},
			},
		},
	})
```

{% endcode %}

### Example 2

![](/files/-MWatUwZ9Aq3NaSDhtWe)

{% code fullWidth="true" %}

```go
	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},
	})
```

{% endcode %}


# Fields

## Get fields

`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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Create custom field

`POST /rest/api/{2-3}/field`

Creates a custom field, the method returns the following information:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get fields paginated

`GET /rest/api/{2-3}/field/search`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) 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:

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Delete Field

`DELETE /rest/api/{2-3}/field/{id}`

Deletes a custom field. The custom field is deleted whether it is in the trash or not.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Configuration

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 all Field Configurations

`GET /rest/api/{2-3}/fieldconfiguration`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) 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.

{% hint style="info" %}
Only field configurations used in company-managed (classic) projects are returned
{% endhint %}

This method uses the following parameters:

<table data-view="cards"><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><code>startAt</code></td><td>The index of the first item to return in a page of results (page offset).</td></tr><tr><td><code>maxResults</code></td><td>The maximum number of items to return per page.</td></tr><tr><td><code>id's</code></td><td>The list of field configuration IDs.</td></tr><tr><td><code>isDefault</code></td><td>If <em>true</em> returns default field configurations only.</td></tr><tr><td><code>query</code></td><td>The query string used to match against field configuration names and descriptions.</td></tr></tbody></table>

{% code fullWidth="true" %}

```go
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)
	}

}
```

{% endcode %}

## Create Field 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.

{% hint style="info" %}
Only field configurations used in company-managed (classic) projects are returned
{% endhint %}

This method uses the following parameters:

<table data-view="cards"><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><code>description</code></td><td>The description of the field configuration.</td></tr><tr><td><code>name</code></td><td>The name of the field configuration. Must be unique.</td></tr></tbody></table>

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Update Field Configuration

`PUT /rest/api/{2-3}/fieldconfiguration/{id}`

Updates a field configuration. The name and the description provided in the request override the existing values.

{% hint style="info" %}
Only field configurations used in company-managed (classic) projects are returned
{% endhint %}

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete Field Configuration

`DELETE /rest/api/{2-3}/fieldconfiguration/{id}`

Deletes a field configuration.

{% hint style="info" %}
Only field configurations used in company-managed (classic) projects are returned
{% endhint %}

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Items

## Get Field Configuration Items

`GET /rest/api/{2-3}/fieldconfiguration/{id}/fields`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of all fields for a configuration.

{% hint style="info" %}
Only field configurations used in company-managed (classic) projects are returned
{% endhint %}

{% code fullWidth="true" %}

```go
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("----------------------")
	}
}
```

{% endcode %}

## Update Field Configuration Items

`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`).

{% hint style="info" %}
Only field configurations used in company-managed (classic) projects are returned
{% endhint %}

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Schemes

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 Field Configuration Schemes

`GET /rest/api/{2-3}/fieldconfigurationscheme`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of field configuration schemes.

{% code fullWidth="true" %}

```go
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)
	}

}
```

{% endcode %}

## Create Field Configuration Scheme

`POST /rest/api/{2-3}/fieldconfigurationscheme`

Creates a field configuration scheme.

{% hint style="info" %}
This operation can only create field configuration schemes used in company-managed (classic) projects.
{% endhint %}

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get Field Configuration Scheme Mapping

`GET /rest/api/{2-3}/fieldconfigurationscheme/mapping`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of field configuration issue type items.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get Field Configuration Schemes by Project

`GET /rest/api/{2-3}/fieldconfigurationscheme/project`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) 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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Assign 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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Update Field Configuration Scheme

`PUT /rest/api/{2-3}/fieldconfigurationscheme/{id}`

Updates a field configuration scheme.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete Field Configuration Scheme

`DELETE /rest/api/{2-3}/fieldconfigurationscheme/{id}`

Deletes a field configuration scheme.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Assign issue types to field configuration

`PUT /rest/api/{2-3}/fieldconfigurationscheme/{id}/mapping`

Assigns issue types to field configurations on field configuration scheme.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Remove issue types to field configuration

`POST /rest/api/{2-3}/fieldconfigurationscheme/{id}/mapping/delete`

Removes issue types from the field configuration scheme.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Context

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.

<figure><img src="/files/1AVg7vLSBBqalXVB3Oo5" alt=""><figcaption><p>Official Documentation</p></figcaption></figure>

## Get custom field contexts

`GET /rest/api/{2-3}/field/{fieldId}/context`&#x20;

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of [contexts](https://confluence.atlassian.com/adminjiracloud/what-are-custom-field-contexts-991923859.html)

&#x20;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)

{% code fullWidth="true" %}

```go
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)
	}

}
```

{% endcode %}

## Create custom field context

`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:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get custom field contexts default values

`GET /rest/api/{2-3}/field/{fieldId}/context/defaultValue`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) 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.

{% code fullWidth="true" %}

```go
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)
	}

}
```

{% endcode %}

## Set custom field contexts default values

`PUT /rest/api/{2-3}/field/{fieldId}/context/defaultValue`

Sets default for contexts of a custom field. Default is defined using these objects:

<table data-full-width="true"><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><p><code>CustomFieldContextDefaultValueSingleOption</code></p></td><td><p></p><p><code>option.single</code></p></td><td><p></p><p>For single choice select lists and radio buttons.</p></td></tr><tr><td><p></p><p><code>CustomFieldContextDefaultValueMultipleOption</code></p></td><td><p></p><p><code>option.multiple</code></p></td><td><p></p><p>For multiple-choice select lists and checkboxes.</p></td></tr><tr><td><p></p><p><code>CustomFieldContextDefaultValueCascadingOption</code></p></td><td><p></p><p><code>option.cascading</code></p></td><td><p></p><p>For cascading select lists.</p></td></tr></tbody></table>

{% hint style="info" %}
Only one type of default object can be included in a request. To remove a default for a context, set the default parameter to `null`.
{% endhint %}

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Update custom field context

`PUT /rest/api/{2-3}/field/{fieldId}/context/{contextId}`&#x20;

Updates a [custom field context](https://confluence.atlassian.com/adminjiracloud/what-are-custom-field-contexts-991923859.html).

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete custom field context

`DELETE /rest/api/{2-3}/field/{fieldId}/context/{contextId}`&#x20;

Deletes a [custom field context](https://confluence.atlassian.com/adminjiracloud/what-are-custom-field-contexts-991923859.html).

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Add issue types to context

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Remove issue types from context

`POST /rest/api/{2-3}/field/{fieldId}/context/{contextId}/issuetype/remove`

Removes issue types from a custom field context.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Assign custom field context to projects

`PUT /rest/api/{2-3}/field/{fieldId}/context/{contextId}/project`

Assigns a custom field context to projects.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Remove custom field context from projects

`POST /rest/api/{2-3}/field/{fieldId}/context/{contextId}/project/remove`

Removes a custom field context from projects.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get project mappings for custom field context

`GET /rest/api/{2-3}/field/{fieldId}/context/projectmapping`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) 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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Option

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 custom field options

`GET /rest/api/{2-3}/field/{fieldId}/context/{contextId}/option`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) 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:

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Create custom field options&#x20;

`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.&#x20;

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:

<pre class="language-go" data-full-width="true"><code class="lang-go"><strong>package main
</strong>
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 = &#x26;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)
	}
}
</code></pre>

## Update custom field options

`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.

{% hint style="warning" %}
Note that this operation **only works for issue field select list options created in Jira or using operations from the** [**Issue custom field options**](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-custom-field-options/#api-group-issue-custom-field-options) **resource**, it cannot be used with issue field select list options created by Connect apps.
{% endhint %}

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Delete custom field options

`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.

{% hint style="warning" %}
&#x20;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** [**Issue custom field options (apps)**](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-custom-field-options/#api-rest-api-3-field-fieldid-context-contextid-option-optionid-delete) **operations.**
{% endhint %}

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Reorder custom field options

`PUT /rest/api/{2-3}/field/{fieldId}/context/{contextId}/option/move`

Changes the order of custom field options or cascading options in a context.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Trash

## Search Fields In Trash

`GET /rest/api/{2-3}/field/search/trashed`

Search returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of fields in the trash. The list may be restricted to fields whose field name or description partially match a string.&#x20;

Only custom fields can be queried, `type` must be set to `custom`.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Move Field To Trash

`POST /rest/api/{2-3}/field/{id}/trash`

Move moves a custom field to trash

{% code fullWidth="true" %}

```go
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)
}

```

{% endcode %}

## Restore Field

`POST /rest/api/{2-3}/field/{id}/restore`

POST /rest/api/3/field/{id}/restoreRestore restores a custom field from trash

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# 🏷️ Labels

This resource represents available labels. Use it to get available labels for the global label field.

## Get all labels

`GET /rest/api/{2-3}/label`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of labels.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}


# Link

You can link issues to keep track of duplicate or related work. You can, for example:&#x20;

* 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.

![](/files/-MYB2g0VNNbpsHnfovnz)

{% hint style="info" %}
This resource represents links between issues. Use it to get, create, and delete links between issues.To use this resource, the site must have issue linking enabled.
{% endhint %}

## Create issue link

`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:

{% hint style="warning" %}
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.
{% endhint %}

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get issue links

`GET /rest/api/{2-3}/issue?fields=issuelinks`

Return the issue links associated with a Jira Issue, the method returns the following information:

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get issue link

`GET /rest/api/{2-3}/issueLink/{linkId}`

Returns an issue link, the method returns the following information:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete issue link

`DELETE /rest/api/{2-3}/issueLink/{linkId}`

Deletes an issue link, the method returns the following information:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Remote

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 remote issue links <a href="#get-remote-issue-links" id="get-remote-issue-links"></a>

`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.

{% hint style="info" %}
Where a global ID includes reserved URL characters these must be escaped in the request.
{% endhint %}

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Create remote issue link <a href="#create-remote-issue-link" id="create-remote-issue-link"></a>

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete remote issue link by ID <a href="#delete-remote-issue-link-by-id" id="delete-remote-issue-link-by-id"></a>

`DELETE /rest/api/{2-3}/issue/{issueIdOrKey}/remotelink/{linkId}`

Delete deletes a remote issue link from an issue.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get remote issue link <a href="#get-remote-issue-link" id="get-remote-issue-link"></a>

`GET /rest/api/{2-3}/issue/{issueIdOrKey}/remotelink/{linkId}`

Get returns a remote issue link for an issue.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Update remote issue link

`PUT /rest/api/{2-3}/issue/{issueIdOrKey}/remotelink/{linkId}`

Update updates a remote issue link for an issue.

{% hint style="info" %}
Fields without values in the request are set to null.
{% endhint %}

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Delete remote issue link by Global ID

`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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}


# Types

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 issue link types

`GET /rest/api/{2-3}/issueLinkType`

Returns a list of all issue link types, the method returns the following information:

{% code fullWidth="true" %}

```go
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)
	}

}
```

{% endcode %}

## Create issue link type

`POST /rest/api/{2-3}/issueLinkType`

Creates an issue link type. Use this operation to create descriptions of the reasons why issues are linked.&#x20;

The issue link type consists of a name and descriptions for a link's inward and outward relationships, the method returns the following information:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get issue link type

`GET /rest/api/{2-3}/issueLinkType/{issueLinkTypeId}`

Returns an issue link type, the method returns the following information:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Update issue link type

`PUT /rest/api/{2-3}/issueLinkType/{issueLinkTypeId}`

Updates an issue link type, the method returns the following information:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete issue link type

`DELETE /rest/api/{2-3}/issueLinkType/{issueLinkTypeId}`

Deletes an issue link type, the method returns the following information:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Metadata

## Get create metadata issue types for a project

`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 [Create issue](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-post) and [Create issues](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-bulk-post). This operation can be accessed anonymously.

#### &#x20;<a href="#api-rest-api-3-issue-createmeta-projectidorkey-issuetypes-get" id="api-rest-api-3-issue-createmeta-projectidorkey-issuetypes-get"></a>

{% code fullWidth="true" %}

```go
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("------------")

	}
}
```

{% endcode %}

## Get create field metadata for a project and issue type id

`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 [Create issue](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-post) and [Create issues](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-bulk-post). This operation can be accessed anonymously.

{% code fullWidth="true" %}

```go
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("------------")
	}

}
```

{% endcode %}

## Get Edit Issue Metadata

`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 [Edit issue](https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issues/#api-rest-api-2-issue-issueidorkey-put).

{% code fullWidth="true" %}

```go
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())
		}
	}
}
```

{% endcode %}

## Get Create Issue Metadata

`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 [Create issue](https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issues/#api-rest-api-2-issue-post) and [Create issues](https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issues/#api-rest-api-2-issue-bulk-post).

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Priorities

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.

![](/files/-MYBH49Kx4IbHYKbsRB9)

## Get priorities

`GET /rest/api/{2-3}/priority`

Returns the list of all issue priorities, the method returns the following information:

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get priority

`GET /rest/api/{2-3}/priority/{id}`

Returns an issue priority, the method returns the following information:

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Create priority

`POST /rest/api/3/priority`

Creates an issue priority.

> No implemented,  yet. Feel free to open a new PR or issue

## Set default priority

`PUT /rest/api/3/priority/default`

Sets default issue priority.

> No implemented,  yet. Feel free to open a new PR or issue

## Move priorities

`PUT /rest/api/3/priority/move`

Changes the order of issue priorities.

> No implemented,  yet. Feel free to open a new PR or issue

## Search priorities

`GET /rest/api/3/priority/search`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) 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

## Update priority

`PUT /rest/api/3/priority/{id}`

Updates an issue priority.

> No implemented,  yet. Feel free to open a new PR or issue

## Delete priority

`DELETE /rest/api/3/priority/{id}`

Deletes an issue priority.

{% hint style="info" %}
This operation is [asynchronous](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#async). Follow the `location` link in the response to determine the status of the task and use [Get task](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-tasks/#api-rest-api-3-task-taskid-get) to obtain subsequent updates.
{% endhint %}

> No implemented,  yet. Feel free to open a new PR or issue


# Resolutions

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 resolutions

`GET /rest/api/{2-3}/resolution`

Returns a list of all issue resolution values, the method returns the following information:

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get resolution

`GET /rest/api/{2-3}/resolution/{id}`

Returns an issue resolution value

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Create resolution

> No implemented, yet, feel free to open a PR or issue

## Set default resolution

> No implemented, yet, feel free to open a PR or issue

## Move resolutions

> No implemented, yet, feel free to open a PR or issue

## Search resolutions

> No implemented, yet, feel free to open a PR or issue

## Update resolution

> No implemented, yet, feel free to open a PR or issue

## Delete resolution

> No implemented, yet, feel free to open a PR or issue


# Search

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.

## Search for issues using JQL (GET)

`GET /rest/api/{2-3}/search`

Searches for issues using [JQL](https://confluence.atlassian.com/x/egORLQ). If the JQL query expression is too large to be encoded as a query parameter, use the [POST](https://docs.go-atlassian.io/jira-software-cloud/issues/search#search-for-issues-using-jql-post) version of this resource.

{% code fullWidth="true" %}

```go
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)
		}
	}
}
```

{% endcode %}

## Search for issues using JQL (POST)

`POST /rest/api/{2-3}/search`

Searches for issues using [JQL](https://confluence.atlassian.com/x/egORLQ). There is a [GET](https://docs.go-atlassian.io/jira-software-cloud/issues/search#search-for-issues-using-jql-get) version of this resource that can be used for smaller JQL query expressions.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Check issues against JQL

`POST /rest/api/{2-3}/jql/match`

Checks whether one or more issues would be returned by one or more JQL queries.

{% code fullWidth="true" %}

```go
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)
	}
}

```

{% endcode %}


# Type

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.

![](/files/-MYBNvK5LM3MOmu0Quwc)

## Get all issue types for user

`GET /rest/api/{2-3}/issuetype`

Returns all issue types.

{% code fullWidth="true" %}

```go

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)
	}
}
```

{% endcode %}

## Create issue type

`POST /rest/api/{2-3}/issuetype`

Creates an issue type and adds it to the default issue type scheme.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get issue type

`GET /rest/api/{2-3}/issuetype/{id}`

Returns an issue type.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Update issue type

`PUT /rest/api/{2-3}/issuetype/{id}`

Updates the issue type.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete issue type

`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`).&#x20;

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get alternative issue types

`GET /rest/api/{2-3}/issuetype/{id}/alternatives`

Returns a list of issue types that can be used to replace the issue type.&#x20;

The alternative issue types are those assigned to the same workflow scheme, field configuration scheme, and screen scheme.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}


# Scheme

This resource represents issue type schemes in classic projects

## Get all issue type schemes

`GET /rest/api/{2-3}/issuetypescheme`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of issue type schemes.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Create issue type scheme

`POST /rest/api/{2-3}/issuetypescheme`

Creates an issue type scheme.

{% code fullWidth="true" %}

```go
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)

}
```

{% endcode %}

## Get issue type scheme items

`GET /rest/api/{2-3}/issuetypescheme/mapping`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of issue-type scheme items. Only issue type scheme items used in classic projects are returned.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get issue type schemes for projects

`GET /rest/api/{2-3}/issuetypescheme/project`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) 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.

{% code fullWidth="true" %}

```go

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)
	}

}
```

{% endcode %}

## Assign issue type scheme to project

`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.&#x20;

To complete the assignment those issues must be updated to use issue types in the new scheme.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Update issue type scheme

`PUT /rest/api/{2-3}/issuetypescheme/{issueTypeSchemeId}`

Updates an issue type scheme.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete issue type scheme

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Add issue types to issue type scheme

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Remove issue type from issue type scheme

`DELETE /rest/api/{2-3}/issuetypescheme/{issueTypeSche}/issuetype/{issueType}`

Removes an issue type from an issue type scheme.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Change order of issue types

> Not implemented, yet. Feel free to open a PR or issue


# Screen Scheme

This resource represents issue type screen schemes.

## Get issue type screen schemes

`GET /rest/api/{2-3}/issuetypescreenscheme`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of issue type screen schemes. Only issue type screen schemes used in classic projects are returned.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Create issue type screen scheme

`POST /rest/api/{2-3}/issuetypescreenscheme`

Creates an issue-type screen scheme.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get issue type screen scheme items

`GET /rest/api/{2-3}/issuetypescreenscheme/mapping`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of issue-type screen scheme items. Only issue type screen schemes used in classic projects are returned.

{% code fullWidth="true" %}

```go
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)
	}

}
```

{% endcode %}

## Assign issue type screen scheme to project

`PUT /rest/api/{2-3}/issuetypescreenscheme/project`

Assigns an issue-type screen scheme to a project.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get issue type screen schemes for projects

`GET /rest/api/{2-3}/issuetypescreenscheme/project`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) 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.

{% hint style="warning" %}
CREATE THE CODE SAMPLE
{% endhint %}

## Update issue type screen scheme

`PUT /rest/api/{2-3}/issuetypescreenscheme/{issueTypeScreenSchemeId}`

Updates an issue type screen scheme.

<pre class="language-go" data-full-width="true"><code class="lang-go"><strong>package main
</strong>
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)
}
</code></pre>

## Delete issue type screen scheme

`DELETE /rest/api/{2-3}/issuetypescreenscheme/{issueTypeScreenSchemeId}`

Deletes an issue type screen scheme.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Append mappings to issue type screen scheme

`PUT /rest/api/{2-3}/issuetypescreenscheme/{issueTypeScreenSchemeId}/mapping`

Appends issue type to screen scheme mappings to an issue type screen scheme.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Update issue type screen scheme default screen scheme

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Remove mappings from issue type screen scheme

`POST /rest/api/{2-3}/issuetypescreenscheme/{issueTypeScreenSc}/mapping/remove`

Removes issue type to screen scheme mappings from an issue type screen scheme.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get issue type screen scheme projects

`GET /rest/api/{2-3}/issuetypescreenscheme/{issueTypeScreenSchemeId}/project`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of projects associated with an issue-type screen scheme. Only company-managed projects associated with an issue-type screen scheme are returned.

{% hint style="warning" %}
CREATE THE CODE SAMPLE
{% endhint %}


# Vote

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 votes

`GET /rest/api/{2-3}/issue/{issueIdOrKey}/votes`

Returns details about the votes on an issue.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Add vote

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete vote

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Watcher

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 issue watchers

`GET /rest/api/{2-3}/issue/{issueIdOrKey}/watchers`

Returns the watchers for an issue.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Add watcher

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete watcher

`DELETE /rest/api/{2-3}/issue/{issueIdOrKey}/watchers`

Deletes a user as a watcher of an issue.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get is watching issue bulk

`POST /rest/api/{2-3}/issue/watching`

> Not implemented, yet. Feel free to open a PR or issue


# Worklogs

## Get Issue Worklogs

`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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Add Worklog

`POST /rest/api/{2-3}/issue/{issueIdOrKey}/worklog`

Adds a worklog to an issue.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get Worklog

`GET /rest/api/{2-3}/issue/{issueIdOrKey}/worklog/{id}`

Returns a worklog.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Update Worklog

`PUT /rest/api/{2-3}/issue/{issueIdOrKey}/worklog/{id}`

Updates a worklog.

{% code fullWidth="true" %}

```go
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)

}
```

{% endcode %}

## Delete Worklog

`DELETE /rest/api/{2-3}/issue/{issueIdOrKey}/worklog/{id}`

Deletes a worklog from an issue.

{% code fullWidth="true" %}

```go
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)
}

```

{% endcode %}

## Get ID's of deleted worklogs

`GET /rest/api/{2-3}/worklog/deleted`

Returns a list of IDs and delete timestamps for worklogs deleted after a date and time.

{% code fullWidth="true" %}

```go
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)
}

```

{% endcode %}

## Get Worklogs

`POST /rest/api/{2-3}/worklog/list`

Returns worklog details for a list of worklog IDs.

{% code fullWidth="true" %}

```go
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)
	}
}

```

{% endcode %}

## Get ID's of updated worklogs

`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

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Properties

### Get issue property keys

`GET /rest/api/{2-3}/issue/{issueIdOrKey}/properties`

Gets returns the URLs and keys of an issue's properties.

{% code fullWidth="true" %}

```go
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)
	}
}

```

{% endcode %}

### Get issue property

`GET /rest/api/{2-3}/issue/{issueIdOrKey}/properties/{propertyKey}`

Get returns the key and value of an issue's property.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

### Set issue property

`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.

{% hint style="info" %}
The value of the request body must be a [valid](http://tools.ietf.org/html/rfc4627), non-empty JSON blob. The maximum length is 32768 characters.
{% endhint %}

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

### Delete issue property

`DELETE /rest/api/{2-3}/issue/{issueIdOrKey}/properties/{propertyKey}`

Deletes deletes an issue's property.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Archiving

## Archive issues by issue ID/Key

`PUT /rest/api/{2-3}/issue/archive`

Preserve archives the given issues based on their issue IDs or keys.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Archive issues by JQL

`POST /rest/api/{2-3}/issue/archive`

PreserveByJQL archives issues than match the provided JQL query.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Restore issues by issue ID/Key

`PUT /rest/api/{2-3}/issue/unarchive`

Restore brings back the given archived issues using their issue IDs or keys.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Export archived issues

`PUT /rest/api/{2-3}/issues/archive/export`

Export generates an export of archived issues based on the provided payload.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Permissions

This resource represents permissions. Use it to obtain details of all permissions and determine whether the user has certain permissions.

## Get my 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.

{% code fullWidth="true" %}

```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() {

	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)
	}
}
```

{% endcode %}

## Check permissions

`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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get permitted projects

`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.

{% hint style="warning" %}
CREATE THE CODE SAMPLE
{% endhint %}


# Scheme

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`):

<table data-view="cards" data-full-width="true"><thead><tr><th>name</th><th>description</th></tr></thead><tbody><tr><td>name</td><td>description</td></tr><tr><td> <code>anyone</code></td><td>Grant for anonymous users.</td></tr><tr><td> <code>applicationRole</code></td><td> Grant for users with access to the specified application (application name). See <a href="https://confluence.atlassian.com/x/3YxjL">Update product access settings</a> for more information.</td></tr><tr><td> <code>assignee</code></td><td>Grant for the user currently assigned to an issue.</td></tr><tr><td> <code>group</code></td><td>Grant for the specified group (group name).</td></tr><tr><td> <code>groupCustomField</code></td><td>Grant for a user in the group selected in the specified custom field (custom field ID).</td></tr><tr><td> <code>projectLead</code></td><td>Grant for a project lead.</td></tr><tr><td> <code>projectRole</code></td><td>Grant for the specified project role (project role ID).</td></tr><tr><td> <code>reporter</code></td><td>Grant for the user who reported the issue.</td></tr><tr><td> <code>sd.customer.portal.only</code></td><td>Jira Service Desk only. Grants customers permission to access the customer portal but not Jira</td></tr><tr><td> <code>user</code></td><td>Grant for the specified user (user ID - historically this was the userkey but that is deprecated and the account ID should be used).</td></tr><tr><td> <code>userCustomField</code></td><td>Grant for a user selected in the specified custom field (custom field ID).</td></tr></tbody></table>

## Get all permission schemes

`GET /rest/api/{2-3}/permissionscheme`

Returns all permission schemes.

{% code fullWidth="true" %}

```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)

	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)
	}
}
```

{% endcode %}

## Get permission scheme

`GET /rest/api/{2-3}/permissionscheme/{schemeId}`

Returns a permission scheme.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}

## Create permission scheme

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete permission scheme

`DELETE /rest/api/{2-3}/permissionscheme/{schemeId}`

Deletes a permission scheme.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}

## Update permission scheme

`PUT /rest/api/{2-3}/permissionscheme/{schemeId}`

Updates a permission scheme

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}


# Grant

## Get permission scheme grants

`GET /rest/api/{2-3}/permissionscheme/{schemeId}/permission`

Returns all permission grants for a permission scheme.

{% code fullWidth="true" %}

```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)

	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)
	}
}
```

{% endcode %}

## Create permission grant

`POST /rest/api/{2-3}/permissionscheme/{schemeId}/permission`

Creates a permission grant in a permission scheme.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get permission scheme grant

`GET /rest/api/{2-3}/permissionscheme/{schemeId}/permission/{permissionId}`

Returns a permission grant.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}

## Delete permission scheme grant

`DELETE /rest/api/{2-3}/permissionscheme/{schemeId}/permission/{permissionId}`

Deletes a permission grant from a permission scheme

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}


# Projects

## Create project

`POST /rest/api/{2-3}/project`

Creates a project based on a project type template

{% code fullWidth="true" %}

```go
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"
)
```

{% endcode %}

{% code fullWidth="true" %}

```go
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("-------------------")
}
```

{% endcode %}

## Get projects paginated

`GET /rest/api/{2-3}/project/search`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of projects visible to the user.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get project

`GET /rest/api/{2-3}/project/{projectIdOrKey}`&#x20;

Returns the [project details](https://confluence.atlassian.com/x/ahLpNw)

{% code fullWidth="true" %}

```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)

	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)
	}
}
```

{% endcode %}

## Update project

`PUT /rest/api/{2-3}/project/{projectIdOrKey}`

Updates the [project details](https://confluence.atlassian.com/x/ahLpNw) of a project.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete project

`DELETE /rest/api/{2-3}/project/{projectIdOrKey}`

Deletes a project.

{% code fullWidth="true" %}

```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() {

	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)
}
```

{% endcode %}

## Archive project

`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.

{% code fullWidth="true" %}

```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)

	response, err := atlassian.Project.Archive(context.Background(), "PK")
	if err != nil {
		log.Fatal(err)
	}

	log.Println("HTTP Endpoint Used", response.Endpoint)
}
```

{% endcode %}

## Delete project asynchronously

`POST /rest/api/{2-3}/project/{projectIdOrKey}/delete`

Deletes a project asynchronously.

{% code fullWidth="true" %}

```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() {

	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)
}
```

{% endcode %}

## Restore deleted project

`POST /rest/api/{2-3}/project/{projectIdOrKey}/restore`

Restores a project from the Jira recycle bin.

{% code fullWidth="true" %}

```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() {

	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)

}
```

{% endcode %}

## Get all statuses for project

`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.

{% code fullWidth="true" %}

```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)

	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)
	}
}
```

{% endcode %}

## Get project notification scheme

`GET /rest/api/{2-3}/project/{projectKeyOrId}/notificationscheme`

Gets a [notification scheme](https://confluence.atlassian.com/x/8YdKLg) associated with the project.&#x20;

{% code fullWidth="true" %}

```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)

	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)
		}
	}
}
```

{% endcode %}


# Categories

## Get all project categories

`GET /rest/api/{2-3}/projectCategory`

Returns all project categories.

<pre class="language-go" data-full-width="true"><code class="lang-go">package main
<strong>
</strong>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("----------------")
	}
}
</code></pre>

## Create project category

`POST /rest/api/{2-3}/projectCategory`

Creates a project category.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get project category by ID

`GET /rest/api/{2-3}/projectCategory/{id}`

Returns a project category.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}

## Update project category

`PUT /rest/api/{2-3}/projectCategory/{id}`

Updates a project category.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete project category

`DELETE /rest/api/{2-3}/projectCategory/{id}`

Deletes a project category.

{% code fullWidth="true" %}

```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)

	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())
}
```

{% endcode %}


# Components

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.

## Create component

`POST /rest/api/{2-3}/component`

Creates a component. Use components to provide containers for issues within a project.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get component

`GET /rest/api/{2-3}/component/{id}`

Returns a component.

{% code fullWidth="true" %}

```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)

	component, response, err := atlassian.Project.Component.Get(context.Background(), "10006")
	if err != nil {
		log.Fatal(err)
	}

	log.Println(component)
	log.Println(response.Endpoint)
}
```

{% endcode %}

## Update component

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete component

`DELETE /rest/api/{2-3}/component/{id}`

Deletes a component.

{% code fullWidth="true" %}

```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)

	response, err := atlassian.Project.Component.Delete(context.Background(), "10006")
	if err != nil {
		log.Fatal(err)
	}

	log.Println("HTTP Endpoint Used", response.Endpoint)
}
```

{% endcode %}

## Get component issues count

`GET /rest/api/{2-3}/component/{id}/relatedIssueCounts`

Returns the counts of issues assigned to the component.

{% code fullWidth="true" %}

```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)

	count, response, err := atlassian.Project.Component.Count(context.Background(), "10005")
	if err != nil {
		log.Fatal(err)
	}

	log.Println(count)
	log.Println(response.Endpoint)
}
```

{% endcode %}

## Get project components <a href="#get-project-components" id="get-project-components"></a>

`GET /rest/api/{2-3}/project/{projectIdOrKey}/components`

Returns all components in a project.

{% code overflow="wrap" lineNumbers="true" fullWidth="true" %}

```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)

	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)
	}
}
```

{% endcode %}


# Permission Schemes

This resource represents permission schemes for a project.

## Get assigned permission scheme

`GET /rest/api/{2-3}/project/{projectKeyOrId}/permissionscheme`&#x20;

Gets the [permission scheme](https://confluence.atlassian.com/x/yodKLg) associated with the project.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}

## Assign permission scheme

`PUT /rest/api/{2-3}/project/{projectKeyOrId}/permissionscheme`

Assigns a permission scheme with a project

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}

## Get project issue security levels

`GET /rest/api/{2-3}/project/{projectKeyOrId}/securitylevel`

Returns all [issue security](https://confluence.atlassian.com/x/J4lKLg) levels for the project that the user has access to.

{% code fullWidth="true" %}

```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)

	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)
	}
}
```

{% endcode %}


# Notification Schemes

## Get Notification schemes

`GET /rest/api/{2-3}/notificationscheme`

Search returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v2/intro/#pagination) list of [notification schemes](https://confluence.atlassian.com/x/8YdKLg) ordered by the display name.

<pre class="language-go" data-full-width="true"><code class="lang-go"><strong>package main
</strong>
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 := &#x26;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)
	}
}
</code></pre>

## Create Notification scheme

`POST /rest/api/{2-3}/notificationscheme`

Create creates a notification scheme with notifications. You can create up to 1000 notifications per request.

{% code fullWidth="true" %}

```go

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)
}
```

{% endcode %}

## Get Project notification schemes

`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.&#x20;

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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get Notification scheme

`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.

{% code fullWidth="true" %}

```go
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)
	}

}
```

{% endcode %}

## Update Notification scheme

`PUT /rest/api/{2-3}/notificationscheme/{id}`

Update updates a notification scheme.

<pre class="language-go" data-full-width="true"><code class="lang-go"><strong>package main
</strong>
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)
}
</code></pre>

## Delete Notification scheme

`DELETE /rest/api/{2-3}/notificationscheme/{notificationSchemeId}`

Delete deletes a notification scheme.

{% code fullWidth="true" %}

```go
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)
	}

}
```

{% endcode %}

## Append Notifications to 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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Remove Notifications to scheme

`DELETE /rest/api/{2-3}/notificationscheme/{notificationSchemeId}/notification/{notificationId}`

Remove removes a notification from a notification scheme.

{% code fullWidth="true" %}

```go
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)
	}

}
```

{% endcode %}


# Roles

## Get project roles for project

`GET /rest/api/{2-3}/project/{projectIdOrKey}/role`

Returns a list of [project roles](https://confluence.atlassian.com/x/3odKLg) for the project returning the name and self URL for each role.

{% code fullWidth="true" %}

```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)
	}
}
```

{% endcode %}

## Get project role for project

`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.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}

## Get project role details

`GET /rest/api/{2-3}/project/{projectIdOrKey}/roledetails`

Returns all [project roles](https://confluence.atlassian.com/x/3odKLg) and the details for each role. Note that the list of project roles is common to all projects.

{% code fullWidth="true" %}

```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)

	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)
	}
}
```

{% endcode %}

## Get all project roles

`GET /rest/api/{2-3}/role`

Gets a list of all project roles, complete with project role details and default actors.

{% code fullWidth="true" %}

```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.Global(context.Background())
	if err != nil {
		log.Fatal(err)
	}

	log.Println("HTTP Endpoint Used", response.Endpoint)

	for _, role := range roles {
		log.Println(role)
	}
}
```

{% endcode %}

## Create project role

`POST /rest/api/{2-3}/role`

Creates a new project role with no [default actors](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-resolutions/#api-rest-api-3-resolution-get).&#x20;

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Actors

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

## Add actors to project role

`POST /rest/api/{2-3}/project/{projectIdOrKey}/role/{id}`

Adds actors to a project role for the project.

{% code fullWidth="true" %}

```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)

	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)
	}
}
```

{% endcode %}

## Delete actors from project role

`DELETE /rest/api/{2-3}/project/{projectIdOrKey}/role/{id}`

Deletes actors from a project role for the project.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}


# Types

## Get all project types

`GET /rest/api/{2-3}/project/type`&#x20;

Returns all [project types](https://confluence.atlassian.com/x/Var1Nw)

{% code fullWidth="true" %}

```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)

	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)
	}
}
```

{% endcode %}

## Get licensed project types

`GET /rest/api/{2-3}/project/type/accessible`&#x20;

Returns all [project types](https://confluence.atlassian.com/x/Var1Nw)

{% code fullWidth="true" %}

```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)

	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)
	}
}
```

{% endcode %}

## Get project type by key

`GET /rest/api/{2-3}/project/type/{projectTypeKey}`&#x20;

Returns a [project type](https://confluence.atlassian.com/x/Var1Nw)

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}

## Get accessible project type by key

`GET /rest/api/{2-3}/project/type/{projectTypeKey}/accessible`

Returns a [project type](https://confluence.atlassian.com/x/Var1Nw)

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}


# Versions

## Get project versions

`GET /rest/api/{2-3}/project/{projectIdOrKey}/versions`

Returns all versions in a project. The response is not paginated.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Create version

`POST /rest/api/{2-3}/version`

Creates a project version.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get version

`GET /rest/api/{2-3}/version/{id}`

Returns a project version.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}

## Update version

`PUT /rest/api/{2-3}/version/{id}`

Updates a project version.

<pre class="language-go" data-full-width="true"><code class="lang-go"><strong>package main
</strong>
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 := &#x26;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)
}
</code></pre>

## Merge versions

`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`.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}

## Get version's related issues count

`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.

{% code fullWidth="true" %}

```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)

	count, response, err := atlassian.Project.Version.RelatedIssueCounts(context.Background(), "10002")
	if err != nil {
		log.Fatal(err)
	}

	log.Println(response.Endpoint)
	log.Println(count)

}
```

{% endcode %}

## Get version's unresolved issues count

`GET /rest/api/{2-3}/version/{id}/unresolvedIssueCount`

Returns counts of the issues and unresolved issues for the project version.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Validation

## Validate project key

`GET /rest/api/{2-3}/projectvalidate/key`

Validates a project key by confirming the key is a valid string and not in use.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}

## Get valid project key

`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.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}

## Get valid project name

`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.

{% code fullWidth="true" %}

```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)

	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)
}

```

{% endcode %}


# Features

## Get project features

`GET /rest/api/{2-3}/project/{projectIdOrKey}/features`

Returns the list of features for a project.

{% code fullWidth="true" %}

```go
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)
	}
}

```

{% endcode %}

## Set project feature state

`PUT /rest/api/{2-3}/project/{projectIdOrKey}/features/{featureKey}`

Sets the state of a project feature.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}


# Properties

## Get project properties keys

`GET /rest/api/{2-3}/project/{projectIdOrKey}/properties`

Returns all keys for the project.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get project property

`GET /rest/api/{2-3}/project/{projectIdOrKey}/properties/{propertyKey}`

Returns the value of a [project property](https://developer.atlassian.com/cloud/jira/platform/storing-data-without-a-database/#a-id-jira-entity-properties-a-jira-entity-properties).

<pre class="language-go" data-full-width="true"><code class="lang-go">package main
<strong>
</strong>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)
}

</code></pre>

## Set project property

`PUT /rest/api/{2-3}/project/{projectIdOrKey}/properties/{propertyKey}`

Sets the value of the [project property](https://developer.atlassian.com/cloud/jira/platform/storing-data-without-a-database/#a-id-jira-entity-properties-a-jira-entity-properties). You can use project properties to store custom data against the project.

{% code fullWidth="true" %}

```go
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)
}

```

{% endcode %}

## Delete project property

`DELETE /rest/api/{2-3}/project/{projectIdOrKey}/properties/{propertyKey}`

Deletes the [property](https://developer.atlassian.com/cloud/jira/platform/storing-data-without-a-database/#a-id-jira-entity-properties-a-jira-entity-properties) from a project.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Screens

This resource represents the screens used to record issue details

## Get screens for a field

`GET /rest/api/{2-3}/field/{fieldId}/screens`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of the screens a field is used in.

{% code fullWidth="true" %}

```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)

	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)
	}
}
```

{% endcode %}

## Get screens

`GET /rest/api/{2-3}/screens`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of all screens or those specified by one or more screen IDs.

{% code fullWidth="true" %}

```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)
	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)
	}
}
```

{% endcode %}

## Create screen

`POST /rest/api/{2-3}/screens`

Creates a screen with a default field tab.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}

## Add field to default screen

`POST /rest/api/{2-3}/screens/addToDefault/{fieldId}`

Adds a field to the default tab of the default screen.

<pre class="language-go" data-full-width="true"><code class="lang-go"><strong>package main
</strong>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)
}
</code></pre>

## Update screen

`PUT /rest/api/{2-3}/screens/{screenId}`

Updates a screen. Only screens used in classic projects can be updated.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}

## Delete screen

`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.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}

## Get available screen fields

`GET /rest/api/{2-3}/screens/{screenId}/availableFields`

Returns the fields that can be added to a tab on a screen.

{% code fullWidth="true" %}

```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)

	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)
	}
}
```

{% endcode %}


# Tabs

## Get all screen tabs

`GET /rest/api/{2-3}/screens/{screenId}/tabs`

Returns the list of tabs for a screen.

<pre class="language-go" data-full-width="true"><code class="lang-go">package main
<strong>
</strong>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)
	}
	
}
</code></pre>

## Create screen tab

`POST /rest/api/{2-3}/screens/{screenId}/tabs`

Creates a tab for a screen.

{% code fullWidth="true" %}

```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)

	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)
}

```

{% endcode %}

## Update screen tab

`PUT /rest/api/{2-3}/screens/{screenId}/tabs/{tabId}`

Updates the name of a screen tab.

{% code fullWidth="true" %}

```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)

	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)
}

```

{% endcode %}

## Delete screen tab

`DELETE /rest/api/{2-3}/screens/{screenId}/tabs/{tabId}`

Deletes a screen tab.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}

## Move screen tab

`POST /rest/api/{2-3}/screens/{screenId}/tabs/{tabId}/move/{pos}`

Moves a screen tab.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}


# Fields

## Get all screen tab fields

`GET /rest/api/{2-3}/screens/{screenId}/tabs/{tabId}/fields`

Returns all fields for a screen tab.

{% code fullWidth="true" %}

```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)

	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)
	}
}
```

{% endcode %}

## Add screen tab field

`POST /rest/api/{2-3}/screens/{screenId}/tabs/{tabId}/fields`

Adds a field to a screen tab.

<pre class="language-go" data-full-width="true"><code class="lang-go"><strong>package main
</strong>
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)
}

</code></pre>

## Remove screen tab field

`DELETE /rest/api/{2-3}/screens/{screenId}/tabs/{tabId}/fields/{id}`

Removes a field from a screen tab.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}


# Schemes

## Get screen schemes

`GET /rest/api/{2-3}/screenscheme`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of screen schemes. Only screen schemes used in classic projects are returned.

{% code fullWidth="true" %}

```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)

	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)
	}
}
```

{% endcode %}

## Create screen scheme

`POST /rest/api/{2-3}/screenscheme`

Creates a screen scheme.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Update      een scheme

`PUT /rest/api/{2-3}/screenscheme/{screenSchemeId}`

Updates a screen scheme. Only screen schemes used in classic projects can be updated.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete screen scheme

`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.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}


# Server

This resource provides information about the Jira instance.

## Get Jira instance info

`GET /rest/api/{2-3}/serverInfo`

Returns information about the Jira instance.

{% code fullWidth="true" %}

```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)

	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)
}
```

{% endcode %}


# JQL

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.

## Parse JQL Query

`POST /rest/api/{2-3}/jql/parse`

Parses and validates JQL queries. The validation is performed in context of the current user.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}


# Tasks

This resource represents a long-running asynchronous tasks. Use it to obtain details about the progress of a long-running task or cancel a long-running task.

## Get task

`GET /rest/api/{2-3}/task/{taskId}`

Returns the status of a [long-running asynchronous task](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#async).

{% hint style="info" %}
When a task has finished, this operation returns the JSON blob applicable to the task. See the documentation of the operation that created the task for details. Task details are not permanently retained. As of September 2019, details are retained for 14 days although this period may change without notice.
{% endhint %}

{% code fullWidth="true" %}

```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)

	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)

}
```

{% endcode %}

## Cancel task

`POST /rest/api/{2-3}/task/{taskId}/cancel`

Cancels a task.

{% code fullWidth="true" %}

```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)

	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)

}
```

{% endcode %}


# Users

## Get user

`GET /rest/api/{2-3}/user`

Returns a user.

{% code fullWidth="true" %}

```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)

	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)

}
```

{% endcode %}

## Create user

`POST /rest/api/{2-3}/user`

Creates a user. This resource is retained for legacy compatibility. As soon as a more suitable alternative is available this resource will be deprecated.

{% code fullWidth="true" %}

```go
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: "example1@go-atlassian.io",
		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)
}
```

{% endcode %}

## Delete user

`DELETE /rest/api/{2-3}/user`

Deletes a user.

{% code fullWidth="true" %}

```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)

	response, err := atlassian.User.Delete(context.Background(), "607b98df2ad11c0072664322")
	if err != nil {
		log.Fatal(err)
	}

	log.Println("HTTP Endpoint Used", response.Endpoint)
}
```

{% endcode %}

## Bulk get users

`GET /rest/api/{2-3}/user/bulk`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of the users specified by one or more account IDs.

{% code fullWidth="true" %}

```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)

	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)
	}
}
```

{% endcode %}

## Get user groups

`GET /rest/api/{2-3}/user/groups`

Returns the groups to which a user belongs.

{% code fullWidth="true" %}

```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)

	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)
	}

}

```

{% endcode %}

## Get all users

`GET /rest/api/{2-3}/users/search`

Returns a list of all (active and inactive) users.

{% code fullWidth="true" %}

```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)

	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)
	}
}
```

{% endcode %}


# Search

## Find users assignable to projects

`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.

{% code fullWidth="true" %}

```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)
	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)
	}
}
```

{% endcode %}

## Find users

`GET /rest/api/{2-3}/user/search`

Returns a list of users that match the search string and property.

{% code fullWidth="true" %}

```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)
	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)
	}
}
```

{% endcode %}

## Find users with permissions

`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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}


# Workflow

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](https://confluence.atlassian.com/adminjiracloud/issue-workflow-schemes-844500788.html).

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.

## Create Workflow

`POST /rest/api/{2-3}/workflow`

{% hint style="warning" %}
Deprecated
{% endhint %}

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

Conditions enable workflow rules that govern whether a transition can execute.

#### Always false conditions

A condition that always fails.

{% code overflow="wrap" %}

```go
{
	Type: "RemoteOnlyCondition",
},
```

{% endcode %}

#### Block transition until approval

A condition that blocks issue transition if there is a pending approval.

```go
{
    Type: "BlockInProgressApprovalCondition",
}
```

#### Compare number custom field condition

A condition that allows transition if a comparison between a number custom field and a value is true.

```go
{
	Type: "CompareNumberCFCondition",
	Configuration: map[string]interface{}{
		"comparator": "=",
		"fieldId":    "customfield_10029",
		"fieldValue": 2,
	},
}
```

#### Hide from user condition

A condition that hides a transition from users. The transition can only be triggered from a workflow function or REST API operation.

```go
{
    Type: "RemoteOnlyCondition",
}
```

#### Only assignee condition

A condition that allows only the assignee to execute a transition.

```go
{
    Type: "AllowOnlyAssignee",
}
```

#### **Only reporter condition**

A condition that allows only the reporter to execute a transition.

```go
{
    Type: "AllowOnlyReporter",
}
```

#### **Permission condition**

A condition that allows only users with a permission to execute a transition.

```go
{
	Type: "PermissionCondition",
	Configuration: map[string]interface{}{
		"permissionKey": "BROWSE_PROJECTS",
	},
},
```

#### **Previous status condition**

A condition that allows a transition based on whether an issue has or has not transitioned through a status.

```go
{
	Type: "PreviousStatusCondition",
	Configuration: map[string]interface{}{
		"ignoreLoopTransitions": true,
		"includeCurrentStatus":  true,
		"mostRecentStatusOnly":  true,
		"reverseCondition":      true,
		"previousStatus": map[string]interface{}{
			"id": "5",
		},
	},
}
```

#### **Separation of duties condition**

A condition that prevents a user to perform the transition, if the user has already performed a transition on the issue.

```go
{
	Type: "SeparationOfDutiesCondition",
	Configuration: map[string]interface{}{
		"fromStatus": map[string]interface{}{"id": "5"},
		"toStatus":   map[string]interface{}{"id": "6"},
	},
}
```

#### **Subtask blocking condition**

A condition that blocks transition on a parent issue if any of its subtasks are in any of one or more statuses.

```go
{
	Type: "SubTaskBlockingCondition",
	Configuration: map[string]interface{}{
		"statuses": []map[string]interface{}{
			{
				"id": "1",
			},
			{
				"id": "3",
			},
		},
	},
},
```

#### **User is in any group condition**

A condition that allows users belonging to any group from a list of groups to execute a transition.

```go
{
	Type: "UserInAnyGroupCondition",
	Configuration: map[string]interface{}{
		"groups": []string{"administrators", "atlassian-addons-admin"},
	},
}
```

#### **User is in any project role condition**

A condition that allows only users with at least one project roles from a list of project roles to execute a transition.

```go
{
	Type: "InAnyProjectRoleCondition",
	Configuration: map[string]interface{}{
		"projectRoles": []map[string]interface{}{
			{
				"id": "10002",
			},
			{
				"id": "10003",
			},
			{
				"id": "10012",
			},
			{
				"id": "10013",
			},
		},
	},
}
```

#### **User is in custom field condition**

A condition that allows only users listed in a given custom field to execute the transition.

```go
{
	Type: "UserIsInCustomFieldCondition",
	Configuration: map[string]interface{}{
		"allowUserInField": false,
		"fieldId":          "customfield_10010",
	},
}
```

#### **User is in group condition**

A condition that allows users belonging to a group to execute a transition.

```go
{
	Type: "UserInGroupCondition",
	Configuration: map[string]interface{}{
		"group": "administrators",
	},
}
```

#### **User is in group custom field condition**

A condition that allows users belonging to a group specified in a custom field to execute a transition.

```go
{
	Type: "InGroupCFCondition",
	Configuration: map[string]interface{}{
		"fieldId": "customfield_10012",
	},
}
```

#### **User is in project role condition**

A condition that allows users with a project role to execute a transition.

```go
{
	Type: "InProjectRoleCondition",
	Configuration: map[string]interface{}{
		"projectRole": map[string]interface{}{
			"id": "10002",
		},
	},
}
```

#### **Value field condition**

A conditions that allows a transition to execute if the value of a field is equal to a constant value or simply set.

```go
{
	Type: "ValueFieldCondition",
	Configuration: map[string]interface{}{
		"fieldId":        "assignee",
		"fieldValue":     "qm:6e1ecee6-8e64-4db6-8c85-916bb3275f51:54b56885-2bd2-4381-8239-78263442520f",
		"comparisonType": "NUMBER",
		"comparator":     "=",
	},
}
```

### **Validators**

Validators check that any input made to the transition is valid before the transition is performed.

#### **Date field validator**

A validator that compares two dates.

```go
{
	Type: "DateFieldValidator",
	Configuration: map[string]interface{}{
		"comparator":  ">",
		"date1":       "updated",
		"date2":       "created",
		"expression":  "1d",
		"includeTime": true,
	},
}
```

#### **Windows date validator**

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.

```go
{
	Type: "WindowsDateValidator",
	Configuration: map[string]interface{}{
		"date1":       "customfield_10009",
		"date2":       "created",
		"windowsDays": 5,
	},
}
```

#### **Field required validator**

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.

```go
{
	Type: "FieldRequiredValidator",
	Configuration: map[string]interface{}{
		"ignoreContext": true,
		"errorMessage":  "Hey",
		"fieldIds": []string{
			"versions",
			"customfield_10037",
			"customfield_10003",
		},
	},
}
```

#### **Field changed validator**

A validator that checks that a field value is changed. However, this validation can be ignored for users from a list of groups.

```go
{
	Type: "FieldChangedValidator",
	Configuration: map[string]interface{}{
		"fieldId":      "comment",
		"errorMessage": "Hey",
		"exemptedGroups": []string{
			"administrators",
			"atlassian-addons-admin",
		},
	},
}
```

#### **Field has single value validator**

A validator that checks that a multi-select field has only one value. Optionally, the validation can ignore values copied from subtasks.

```go
{
	Type: "FieldHasSingleValueValidator",
	Configuration: map[string]interface{}{
		"fieldId":         "attachment",
		"excludeSubtasks": true,
	},
}
```

#### **Parent status validator**

A validator that checks the status of the parent issue of a subtask. Ìf the issue is not a subtask, no validation is performed.

```go
{
	Type: "ParentStatusValidator",
	Configuration: map[string]interface{}{
		"parentStatuses": []map[string]interface{}{
			{
				"id": "2",
			},
			{
				"id": "1",
			},
		},
	},
}
```

#### **Permission validator**

A validator that checks the user has a permission.

```go
{
	Type: "PermissionValidator",
	Configuration: map[string]interface{}{
		"permissionKey": "ADMINISTER_PROJECTS",
	},
},
```

#### **Previous status validator**

A validator that checks if the issue has held a status.

```gn
{
	Type: "PreviousStatusValidator",
	Configuration: map[string]interface{}{
		"mostRecentStatusOnly": false,
		"previousStatus":       map[string]interface{}{"id": "15"},
	},
},
```

#### **Regular expression validator**

A validator that checks the content of a field against a regular expression.

```go
{
	Type: "RegexpFieldValidator",
	Configuration: map[string]interface{}{
		"regExp":  "[0-9]",
		"fieldId": "customfield_10029",
	},
},
```

#### **User permission validator**

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.

```go
{
	Type: "UserPermissionValidator",
	Configuration: map[string]interface{}{
		"permissionKey": "BROWSE_PROJECTS",
		"nullAllowed":   false,
		"username":      "TestUser",
	},
},
```

### **Post functions**

Post functions carry out any additional processing required after a Jira workflow transition is executed.

#### **Fire issue event function**

A post function that fires an event that is processed by the listeners.

```go
{
	Type: "FireIssueEventFunction",
	Configuration: map[string]interface{}{
		"event": map[string]interface{}{"id": "1"},
	},
},
```

#### **Update issue status**

A post function that sets issue status to the linked status of the destination workflow status.

```go
{
    Type: "UpdateIssueStatusFunction",
}
```

{% hint style="info" %}
This post function is a default function in global and directed transitions. It can only be added to the initial transition and can only be added once.
{% endhint %}

#### **Create comment**

A post function that adds a comment entered during the transition to an issue.

```go
{
    Type: "CreateCommentFunction",
}
```

{% hint style="info" %}
This post function is a default function in global and directed transitions. It can only be added to the initial transition and can only be added once.
{% endhint %}

#### **Store issue**

A post function that stores updates to an issue.

```go
{
    Type: "CreateCommentFunction",
}
```

{% hint style="info" %}
This post function can only be added to the initial transition and can only be added once.
{% endhint %}

#### **Assign to current user function**

A post function that assigns the issue to the current user if the current user has the `ASSIGNABLE_USER` permission.

```go
{
    Type: "CreateCommentFunction",
}
```

{% hint style="info" %}
This post function can be included once in a transition.
{% endhint %}

#### **Assign to lead function**

A post function that assigns the issue to the project or component lead developer.

```go
{
    Type: "CreateCommentFunction",
}
```

{% hint style="info" %}
This post function can be included once in a transition.
{% endhint %}

#### **Assign to reporter function**

A post function that assigns the issue to the reporter.

```go
{
    Type: "CreateCommentFunction",
}
```

{% hint style="info" %}
This post function can be included once in a transition.
{% endhint %}

#### **Clear field value function**

A post function that clears the value from a field.

```go
{
	Type: "ClearFieldValuePostFunction",
	Configuration: map[string]interface{}{
		"fieldId": "assignee",
	},
},
```

#### **Copy value from other field function**

A post function that copies the value of one field to another, either within an issue or from parent to subtask.

```go
{
	Type: "CopyValueFromOtherFieldPostFunction",
	Configuration: map[string]interface{}{
		"sourceFieldId":      "assignee",
		"destinationFieldId": "creator",
		"copyType":           "same",
	},
},
```

#### **Update issue custom field function**

A post function that updates the content of an issue custom field.

```go
{
	Type: "UpdateIssueCustomFieldPostFunction",
	Configuration: map[string]interface{}{
		"mode":       "append",
		"fieldId":    "customfield_10003",
		"fieldValue": "yikes",
	},
},
```

#### **Update issue field function**

A post function that updates a simple issue field.

```go
{
	Type: "UpdateIssueFieldFunction",
	Configuration: map[string]interface{}{
		"fieldId":    "assignee",
		"fieldValue": "5f0c277e70b8a90025a00776",
	},
},
```

{% code fullWidth="true" %}

```go
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)
}

```

{% endcode %}

## Search Workflows

`GET /rest/api/{2-3}/workflow/search`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of published classic workflows. When workflow names are specified, details of those workflows are returned. Otherwise, all published classic workflows are returned.

{% hint style="warning" %}
This operation does not return next-gen workflows, Deprecated
{% endhint %}

{% code fullWidth="true" %}

```go
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))
	}
}
```

{% endcode %}

## Delete Workflow

`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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Bulk Get Workflows

`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**](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#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

{% code fullWidth="true" %}

```go
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))
	}
}
```

{% endcode %}

## Get Workflow Capabilities

`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.&#x20;

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).

### **Validators**

A validator rule that checks if a user has the required permissions to execute the transition in the workflow.

{% tabs %}
{% tab title="Permission validator" %}
A validator rule that checks if a user has the required permissions to execute the transition in the workflow.

```json
{
   "ruleKey": "system:check-permission-validator",
   "parameters": {
     "permissionKey": "ADMINISTER_PROJECTS"
   }
 }
```

**Parameters**:

* `permissionKey` The permission required to perform the transition. Allowed values: [built-in Jira permissions](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-permission-schemes/#built-in-permissions).
  {% endtab %}

{% tab title="Parent or child blocking validator" %}
A validator to block the child issue\u2019s transition depending on the parent issue\u2019s status.

```json
{
   "ruleKey" : "system:parent-or-child-blocking-validator"
   "parameters" : {
     "blocker" : "PARENT"
     "statusIds" : "1,2,3"
   }
}
```

{% endtab %}

{% tab title="Previous status validator" %}
A validator that checks if an issue has transitioned through specified previous status(es) before allowing the current transition to occur.

```json
{
   "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`.
  {% endtab %}

{% tab title="Validate a field value" %}
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**

```json

{
   "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).
  {% endtab %}
  {% endtabs %}

{% code fullWidth="true" %}

```go
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))
}
```

{% endcode %}

## Bulk Create Workflows

`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**](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#permissions) **required:**

* *Administer Jira* project permission to create all, including global-scoped, workflows
* *Administer projects* project permissions to create project-scoped workflows

### Key Helper Methods

#### AddStatus() <a href="#add-status" id="add-status"></a>

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.

```go
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.

#### AddTransition()

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".

```go
// 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.

#### AddWorkflow()

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.

```go
// 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.

### Considerations

* Any status used within a workflow (through transitions or initial states) **must** be included in the `statuses` tag under the `WorkflowCreatesPayload` struct.&#x20;
  * 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.

{% code fullWidth="true" %}

```go

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))
}
```

{% endcode %}

## Validate Create Workflows

`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.&#x20;

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**](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#permissions) **required:**

* *Administer Jira* project permission to create all, including global-scoped, workflows
* *Administer projects* project permissions to create project-scoped workflows

{% code fullWidth="true" %}

```go
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))
	}
}
```

{% endcode %}

## Bulk Update Workflows

`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.

{% code fullWidth="true" %}

```go
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))
}
```

{% endcode %}

## Validate Update Workflows

`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.&#x20;

The validation checks for potential issues that could prevent the workflows from being updated successfully. The validation process will check for conditions such as:&#x20;

* Whether the transitions are valid.&#x20;
* Whether the status and transition names are unique within the workflow.&#x20;
* If the validation fails, a list of validation errors is returned, which should be resolved before applying the changes.

{% code fullWidth="true" %}

```go
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))
}
```

{% endcode %}


# Scheme

## Gets Workflows Schemes

`GET /rest/api/{2-3}/workflowscheme`

Returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of all workflow schemes, not including draft workflow schemes.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Create Workflows Scheme

`POST /rest/api/{2-3}/workflowscheme`

Creates a workflow scheme.

<pre class="language-go" data-full-width="true"><code class="lang-go">package main
<strong>
</strong>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 := &#x26;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)
}
</code></pre>

## Get Workflow Scheme

`GET /rest/api/{2-3}/workflowscheme/{id}`

Returns a workflow scheme.

{% code fullWidth="true" %}

```go
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)
}

```

{% endcode %}

## Update Workflow Scheme

`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`.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete Workflow Scheme

`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).

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get Workflow Schemes Associations

`GET /rest/api/{2-3}/workflowscheme/project`

Associations returns a list of the workflow schemes associated with a list of projects.&#x20;

* 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.

{% hint style="info" %}
If the project is associated with the `Default Workflow Scheme` no ID is returned. This is because the way the `Default Workflow Scheme` is stored means it has no ID.
{% endhint %}

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Assign Workflow Scheme

`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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}


# Issue Type

## Get workflow for issue type in workflow scheme

`GET /rest/api/{2-3}/workflowscheme/{id}/issuetype/{issueType}`

Get returns the issue type-workflow mapping for an issue type in a workflow scheme.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Set workflow for issue type in workflow scheme

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Delete workflow for issue type in workflow scheme

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get issue types for workflows in workflow scheme

`GET /rest/api/{2-3}/workflowscheme/{id}/workflow`

Mapping returns the workflow-issue type mappings for a workflow scheme.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Set issue types for workflow in workflow scheme

{% hint style="warning" %}
Not implemented, feel free to open a PR :thumbsup:
{% endhint %}

## Delete issue types for workflow in workflow scheme

{% hint style="warning" %}
Not implemented, feel free to open a PR :thumbsup:
{% endhint %}


# Status

{% @github-files/github-code-block url="<https://github.com/ctreminiom/go-atlassian/issues/140>" %}

## Search Workflow Statuses

`GET /rest/api/{2-3}/statuses/search`

Search returns a [paginated](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#pagination) list of statuses that match a search on name or project.

{% code fullWidth="true" %}

```go
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("--------------------------------")
	}
}
```

{% endcode %}

## Gets Workflow Statuses

`GET /rest/api/{2-3}/statuses`

Get returns a list of the statuses specified by one or more status IDs.

{% code fullWidth="true" %}

```go
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("--------------------------------")
	}
}
```

{% endcode %}

## Create Workflow Statuses

`POST /rest/api/{2-3}/statuses`

Create creates statuses for a global or project scope.&#x20;

{% code fullWidth="true" %}

```go
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("--------------------------------")
	}
}
```

{% endcode %}

## Update Workflow Statuses

`PUT /rest/api/{2-3}/statuses`

Update updates statuses by ID.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Delete Workflow Statuses

`DELETE /rest/api/{2-3}/statuses`

Delete deletes statuses by ID.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Bulk Workflow Statuses

`GET /rest/api/{2-3}/status`

Bulk returns a list of all statuses associated with active workflows.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get Workflow Status

`GET /rest/api/{2-3}/status/{idOrName}`

Get returns a status.&#x20;

* 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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Myself

## Get Current User

`GET /rest/api/{2-3}/myself`

Returns details for the current user.

{% code fullWidth="true" %}

```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() {

	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)
}
```

{% endcode %}


# Teams

{% hint style="info" %}
This document refers to Advanced Roadmaps API's, which is a cross-project planning tool only available as part of Jira Software Cloud Premium and Enterprise.
{% endhint %}

{% hint style="warning" %}
This is an experimental API,
{% endhint %}

## Overview

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.

<figure><img src="/files/WeCmn40YkC3aBqa7bQsl" alt=""><figcaption></figcaption></figure>

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.

### Get Teams

`POST /rest/teams/1.0/teams/find`

Gets returns the Teams information from the *Jira Advanced Roadmaps* application.&#x20;

* 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

{% code fullWidth="true" %}

```go
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)
   }
}
```

{% endcode %}

### Create Team

`POST /rest/teams/1.0/teams/create`

Create create creates a team on the Advanced Roadmaps.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Introduction

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.

<figure><img src="/files/6T7Nc8qBHn0ZqRzLyjqJ" alt=""><figcaption><p>Kanban Board Sample</p></figcaption></figure>

Here's a brief introduction to some key concepts in Jira Agile Rest API:

1. **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.
2. **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.
3. **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.
4. **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.
5. **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.
6. **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.


# Boards

A board displays issues from one or more projects, giving you a flexible way of viewing, managing, and reporting on work in progress.

## Get issues for backlog

`GET /rest/agile/1.0/board/{boardId}/backlog`

Returns all issues from the board's backlog, for the given board ID.&#x20;

* This only includes issues that the user has permission to view.&#x20;
* The backlog contains incomplete issues that are not assigned to any future or active sprint.&#x20;

{% hint style="info" %}
Note, if the user does not have permission to view the board, no issues will be returned at all.&#x20;
{% endhint %}

Issues returned from this resource include Agile fields, like sprint, closedSprints, flagged, and epic. By default, the returned issues are ordered by rank.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get configuration

`GET /rest/agile/1.0/board/{boardId}/configuration`

Get the board configuration.&#x20;

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Create board

`POST /rest/agile/1.0/board`

Creates a new board. Board name, type ,and filter ID is required

{% code fullWidth="true" %}

```go
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)
}

```

{% endcode %}

## Get epics

`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.

{% code fullWidth="true" %}

```go
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)
	}
}

```

{% endcode %}

## Get board by filter id

`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.

{% code fullWidth="true" %}

```go
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)
	}
}

```

{% endcode %}

## Get board

`GET /rest/agile/1.0/board/{boardId}`

Returns the board for the given board ID.&#x20;

* This board will only be returned if the user has permission to view it.&#x20;
* 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).

{% code fullWidth="true" %}

```go
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())

}

```

{% endcode %}

## Get issues for board

`GET /rest/agile/1.0/board/{boardId}/issue`

Returns all issues from a board, for a given board ID.&#x20;

* This only includes issues that the user has permission to view.&#x20;
* An issue belongs to the board if its status is mapped to the board's column.&#x20;
* Epic issues do not belongs to the scrum boards.&#x20;
* Issues returned from this resource include Agile fields, like sprint, closedSprints, flagged, and epic. By default, the returned issues are ordered by rank.

{% hint style="info" %}
**Note**, if the user does not have permission to view the board, no issues will be returned at all.&#x20;
{% endhint %}

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get board issues for epic

`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.&#x20;

* This only includes issues that the user has permission to view.&#x20;
* Issues returned from this resource include Agile fields, like sprint, closedSprints, flagged, and epic. By default, the returned issues are ordered by rank.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get board issues for sprint

`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.&#x20;

* 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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get issues without epic for board

`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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Move issues to backlog for board

`POST /rest/agile/1.0/board/{boardId}/issue`

Move issues to the backlog of a particular board (if they are already on that board).&#x20;

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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get projects

`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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Get all sprints

`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.

{% code fullWidth="true" %}

```go
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())
}
```

{% endcode %}

## Get all versions

`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.

{% code fullWidth="true" %}

```go
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())
}
```

{% endcode %}

## Delete Board

`DELETE /rest/agile/1.0/board/{boardId}`

Delete deletes the board. Admin without the view permission can still remove the board.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get Boards

`GET /rest/agile/1.0/board`

Gets returns all boards. This only includes boards that the user has permission to view.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}


# Backlog

In <mark style="color:blue;">Jira</mark>, 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.

<figure><img src="https://wac-cdn.atlassian.com/dam/jcr:6e0122d0-c7fe-4b32-bcfb-20b480780e51/AgileBacklogManyEpics.svg?cdnVersion=1004" alt="" width="563"><figcaption></figcaption></figure>

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.

### Move issues to backlog

`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.

<pre class="language-go" data-full-width="true"><code class="lang-go"><strong>package main
</strong>
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
}
</code></pre>

### Move issues to a board backlog

`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.

{% code fullWidth="true" %}

```go
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
}
```

{% endcode %}


# Sprints

## Create sprint <a href="#create-print" id="create-print"></a>

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get sprint

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Update 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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Partially update sprint

`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.

<pre class="language-go" data-full-width="true"><code class="lang-go"><strong>package main
</strong>
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 := &#x26;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)
}
</code></pre>

## Get issues for sprint <a href="#get-issues-for-sprint" id="get-issues-for-sprint"></a>

`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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Start sprint

`GET /rest/agile/1.0/sprint/{sprintId}/issue`

<pre class="language-go" data-full-width="true"><code class="lang-go"><strong>package main
</strong>
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)

}
</code></pre>

## Close Sprint

`GET /rest/agile/1.0/sprint/{sprintId}/issue`

{% code fullWidth="true" %}

```go
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)

}
```

{% endcode %}

## Delete Sprint

`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.

{% code fullWidth="true" %}

```go
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)

}
```

{% endcode %}

## Move Issues To Sprint

`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.

{% code fullWidth="true" %}

```go
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)

}
```

{% endcode %}


# Epics

## Get Epic

`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.

{% hint style="warning" %}
**Note:** This operation does not work for epics in next-gen projects.
{% endhint %}

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get Issues for epic

`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.

{% hint style="warning" %}
**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.&#x20;
{% endhint %}

{% hint style="warning" %}
Build your JQL query using the parent clause. For more information on the parent JQL field, see Advanced searching.
{% endhint %}

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}

## Move issues to Epic

`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.&#x20;

{% hint style="info" %}
This operation does not work for epics in next-gen projects.
{% endhint %}

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Introduction

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.

<figure><img src="/files/zMf46RscgS0it8Z0E1q8" alt=""><figcaption><p>Request Sample</p></figcaption></figure>

Here are some key components and concepts related to the Jira Service Management REST API:

1. **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.
2. **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.
3. **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.
4. **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.
5. **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.
6. **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.


# Customer

{% embed url="<https://github.com/ctreminiom/go-atlassian/blob/main/pkg/infra/models/sm_customer.go>" %}
SM Customer Models
{% endembed %}

## Create customer

`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.

{% code fullWidth="true" %}

```go
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       = "example12@gmail.com"
		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("-------------------------")

}
```

{% endcode %}

## Add customers

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}

## Get customers

`GET /rest/servicedeskapi/servicedesk/{serviceDeskId}/customer`

This method returns a list of the customers on a service desk.

{% code fullWidth="true" %}

```go
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)
	}

}
```

{% endcode %}

## Remove customers

`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.

{% code fullWidth="true" %}

```go
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)
}
```

{% endcode %}


# Info

{% embed url="<https://github.com/ctreminiom/go-atlassian/blob/main/pkg/infra/models/sm_info.go>" %}
SM Info Models
{% endembed %}

## Get info

`GET /rest/servicedeskapi/info`

This method retrieves information about the Jira Service Management instance such as software version, builds, and related links.

{% code fullWidth="true" %}

```go
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       = "example12@gmail.com"
		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("-------------------------")
}
```

{% endcode %}


# Knowledgebase

## Search articles

`GET /rest/servicedeskapi/knowledgebase/article`

Returns articles that match the given query string across all service desks.

{% code fullWidth="true" %}

```go
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)
	}

}
```

{% endcode %}

## Get articles

`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.

{% code fullWidth="true" %}

```go
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)
	}
}
```

{% endcode %}


# Organization

## Get organizations

`GET /rest/servicedeskapi/organization`

This method returns a list of organizations in the Jira Service Management instance. Use this method when you want to present a list of organizations or want to locate an organization by name.

{% code fullWidth="true" %}

```go
package main

import (
	"context"
	"github.com/ctreminiom/go-atlassian/jira/sm"
	"log"
	"os"
)

func main() {

	var (
		host  = os.Getenv("HOST")
		mail  = os.Getenv("MAIL")
		token = os.Getenv("TOKEN")
	)

	atlassian, err := sm.New(nil, host)
	if err != nil {
		return
	}

	atlassian.Auth.SetBasicAuth(mail, token)
	atlassian.Auth.SetUserAgent("curl/7.54.0")

	var (
		accountID = ""
		start     = 0
		limit     = 50
	)

	organizations, response, err := atlassian.Organization.Gets(context.Background(), accountID, start, limit)
	if err != nil {
		if response != nil {
			log.Println("Response HTTP Response", response.Bytes.String())
			log.Println("HTTP Endpoint Used", response.Endpoint)
		}
		log.Fatal(err)
	}

	log.Println("Response HTTP Code", response.Code)
	log.Println("HTTP Endpoint Used", response.Endpoint)

	for _, organization := range organizations.Values {
		log.Println(organization)
	}
}
```

{% endcode %}

## Create organization

`POST /rest/servicedeskapi/organization`

This method creates an organization by passing the name of the organization.

{% code fullWidth="true" %}

```go
package main

import (
	"context"
	"github.com/ctreminiom/go-atlassian/jira/sm"
	"log"
	"os"
)

func main() {

	var (
		host  = os.Getenv("HOST")
		mail  = os.Getenv("MAIL")
		token = os.Getenv("TOKEN")
	)

	atlassian, err := sm.New(nil, host)
	if err != nil {
		return
	}

	atlassian.Auth.SetBasicAuth(mail, token)
	atlassian.Auth.SetUserAgent("curl/7.54.0")

	var organizationName = "Organization Name"

	newOrganization, response, err := atlassian.Organization.Create(context.Background(), organizationName)
	if err != nil {
		if response != nil {
			log.Println("Response HTTP Response", response.Bytes.String())
			log.Println("HTTP Endpoint Used", response.Endpoint)
		}
		log.Fatal(err)
	}

	log.Println("Response HTTP Code", response.Code)
	log.Println("HTTP Endpoint Used", response.Endpoint)
	log.Printf("The organization has been created: %v", newOrganization.ID)
}
```

{% endcode %}

## Get organization

`GET /rest/servicedeskapi/organization/{organizationId}`

Get returns details of an organization. Use this method to get organization details whenever your application component is passed an organization ID but needs to display other organization details.

{% code fullWidth="true" %}

```go
package main

import (
	"context"
	"github.com/ctreminiom/go-atlassian/jira/sm"
	"log"
	"os"
)

func main()  {

	var (
		host  = os.Getenv("HOST")
		mail  = os.Getenv("MAIL")
		token = os.Getenv("TOKEN")
	)

	atlassian, err := sm.New(nil, host)
	if err != nil {
		return
	}

	atlassian.Auth.SetBasicAuth(mail, token)
	atlassian.Auth.SetUserAgent("curl/7.54.0")

	organization, response, err := atlassian.Organization.Get(context.Background(), 2)
	if err != nil {
		if response != nil {
			log.Println("Response HTTP Response", response.Bytes.String())
			log.Println("HTTP Endpoint Used", response.Endpoint)
		}
		log.Fatal(err)
	}

	log.Println("Response HTTP Code", response.Code)
	log.Println("HTTP Endpoint Used", response.Endpoint)
	log.Println(organization.ID, organization.Name, organization.Links.Self)
}
```

{% endcode %}

## Delete Organization

`DELETE /rest/servicedeskapi/organization/{organizationId}`

This method deletes an organization. Note that the organization is deleted regardless of other associations it may have. For example, associations with service desks.

{% code fullWidth="true" %}

```go
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")

	response, err := atlassian.Organization.Delete(context.Background(), 2)
	if err != nil {
		if response != nil {
			log.Println("Response HTTP Response", response.Bytes.String())
			log.Println("HTTP Endpoint Used", response.Endpoint)
		}
		log.Fatal(err)
	}
}
```

{% endcode %}

## Get organizations

`GET /rest/servicedeskapi/servicedesk/{serviceDeskId}/organization`

This method returns a list of all organizations associated with a service desk.

{% code fullWidth="true" %}

```go
package main

import (
	"context"
	"github.com/ctreminiom/go-atlassian/jira/sm"
	"log"
	"os"
)

func main() {

	var (
		host  = os.Getenv("HOST")
		mail  = os.Getenv("MAIL")
		token = os.Getenv("TOKEN")
	)

	atlassian, err := sm.New(nil, host)
	if err != nil {
		return
	}

	atlassian.Auth.SetBasicAuth(mail, token)
	atlassian.Auth.SetUserAgent("curl/7.54.0")

	var (
		accountID = ""
		projectID = 1
		start     = 0
		limit     = 50
	)

	organizations, response, err := atlassian.Organization.Project(
		context.Background(),
		accountID,
		projectID,
		start,
		limit,
	)

	if err != nil {
		if response != nil {
			log.Println("Response HTTP Response", response.Bytes.String())
			log.Println("HTTP Endpoint Used", response.Endpoint)
		}
		log.Fatal(err)
	}

	log.Println("Response HTTP Code", response.Code)
	log.Println("HTTP Endpoint Used", response.Endpoint)

	for _, organization := range organizations.Values {
		log.Printf(organization.ID)
	}

}
```

{% endcode %}

## Associate organization

`POST /rest/servicedeskapi/servicedesk/{serviceDeskId}/organization`

This method adds an organization to a service desk. If the organization ID is already associated with the service desk, no change is made and the resource returns a 204 success code.

{% code fullWidth="true" %}

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

{% endcode %}

## Detach organization

`DELETE /rest/servicedeskapi/servicedesk/{serviceDeskId}/organization`

This method removes an organization from a service desk. If the organization ID does not match an organization associated with the service desk, no change is made and the resource returns a 204 success code.

{% code fullWidth="true" %}

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

{% endcode %}

## Get Project Organizations

## Get users in organization

`GET /rest/servicedeskapi/organization/{organizationId}/user`

This method returns all the users associated with an organization. Use this method where you want to provide a list of users for an organization or determine if a user is associated with an organization.

{% code fullWidth="true" %}

```go
package main

import (
	"context"
	"github.com/ctreminiom/go-atlassian/jira/sm"
	"log"
	"os"
)

func main() {

	var (
		host  = os.Getenv("HOST")
		mail  = os.Getenv("MAIL")
		token = os.Getenv("TOKEN")
	)

	atlassian, err := sm.New(nil, host)
	if err != nil {
		return
	}

	atlassian.Auth.SetBasicAuth(mail, token)
	atlassian.Auth.SetUserAgent("curl/7.54.0")

	var (
		organizationID = 2
		start          = 0
		limit          = 50
	)

	users, response, err := atlassian.Organization.Users(context.Background(), organizationID, start, limit)
	if err != nil {
		if response != nil {
			log.Println("Response HTTP Response", response.Bytes.String())
			log.Println("HTTP Endpoint Used", response.Endpoint)
		}
		log.Fatal(err)
	}

	log.Println("Response HTTP Code", response.Code)
	log.Println("HTTP Endpoint Used", response.Endpoint)

	for _, user := range users.Values {
		log.Printf(user.DisplayName, user.EmailAddress)
	}
}
```

{% endcode %}

## Add users to organization

`POST /rest/servicedeskapi/organization/{organizationId}/user`

This method adds users to an organization.

<pre class="language-go" data-full-width="true"><code class="lang-go"><strong>package main
</strong>
import (
	"context"
	"github.com/ctreminiom/go-atlassian/jira/sm"
	"log"
	"os"
)

func main() {

	var (
		host  = os.Getenv("HOST")
		mail  = os.Getenv("MAIL")
		token = os.Getenv("TOKEN")
	)

	atlassian, err := sm.New(nil, host)
	if err != nil {
		return
	}

	atlassian.Auth.SetBasicAuth(mail, token)
	atlassian.Auth.SetUserAgent("curl/7.54.0")

	var (
		accountIDs     = []string{"5b86be50b8e3cb5895860d6d"}
		organizationID = 2
	)

	response, err := atlassian.Organization.Add(context.Background(), organizationID, accountIDs)
	if err != nil {
		if response != nil {
			log.Println("Response HTTP Response", response.Bytes.String())
			log.Println("HTTP Endpoint Used", response.Endpoint)
		}
		log.Fatal(err)
	}

	log.Println("Response HTTP Code", response.Code)
	log.Println("HTTP Endpoint Used", response.Endpoint)
}
</code></pre>

## Remove users from organization

`DELETE /rest/servicedeskapi/organization/{organizationId}/user`

This method removes users from an organization.

{% code fullWidth="true" %}

```go
package main

import (
	"context"
	"github.com/ctreminiom/go-atlassian/jira/sm"
	"log"
	"os"
)

func main() {

	var (
		host  = os.Getenv("HOST")
		mail  = os.Getenv("MAIL")
		token = os.Getenv("TOKEN")
	)

	atlassian, err := sm.New(nil, host)
	if err != nil {
		return
	}

	atlassian.Auth.SetBasicAuth(mail, token)
	atlassian.Auth.SetUserAgent("curl/7.54.0")

	var (
		accountIDs     = []string{"5b86be50b8e3cb5895860d6d"}
		organizationID = 2
	)

	response, err := atlassian.Organization.Remove(context.Background(), organizationID, accountIDs)
	if err != nil {
		if response != nil {
			log.Println("Response HTTP Response", response.Bytes.String())
			log.Println("HTTP Endpoint Used", response.Endpoint)
		}
		log.Fatal(err)
	}

	log.Println("Response HTTP Code", response.Code)
	log.Println("HTTP Endpoint Used", response.Endpoint)
}
```

{% endcode %}


# Request

## Get customer requests

`GET /rest/servicedeskapi/request`

This method returns all customer requests for the user executing the query.

{% code fullWidth="true" %}

```go
package main

import (
	"context"
	"encoding/json"
	"github.com/ctreminiom/go-atlassian/jira/sm"
	"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 := sm.New(nil, host)
	if err != nil {
		return
	}

	atlassian.Auth.SetBasicAuth(mail, token)
	atlassian.Auth.SetUserAgent("curl/7.54.0")

	options := &models.ServiceRequestOptionScheme{
		SearchTerm:        "",
		RequestOwnerships: []string{"OWNED_REQUESTS"},
		RequestStatus:     "ALL_REQUESTS",
		ApprovalStatus:    "",
		OrganizationID:    0,
		ServiceDeskID:     0,
		RequestTypeID:     0,
		Expand:            []string{"serviceDesk", "requestType", "status", "action"},
	}

	customerRequests, response, err := atlassian.Request.Gets(context.Background(), options, 0, 50)
	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 _, customRequest := range customerRequests.Values {

		dataAsJson, err := json.MarshalIndent(customRequest, "", "\t")
		if err != nil {
			log.Fatal(err)
		}

		log.Println(string(dataAsJson))
	}
}
```

{% endcode %}

## Get customer request by id or key

`GET /rest/servicedeskapi/request/{issueIdOrKey}`

This method returns a customer request.

{% code fullWidth="true" %}

```go
package main

import (
	"context"
	"encoding/json"
	"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 (
		issueKey = "DESK-11"
		expand   = []string{"serviceDesk", "requestType"}
	)

	request, response, err := atlassian.Request.Get(context.Background(), issueKey, expand)
	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)

	dataAsJson, err := json.MarshalIndent(request, "", "\t")
	if err != nil {
		log.Fatal(err)
	}

	log.Println(string(dataAsJson))
}
```

{% endcode %}

## Subscribe

`PUT /rest/servicedeskapi/request/{issueIdOrKey}/notification`

This method subscribes the user to receiving notifications from a customer request.

{% code fullWidth="true" %}

```go
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")
	
	response, err := atlassian.Request.Subscribe(context.Background(), "DUMMY-4")
	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)
}
```

{% endcode %}

## Unsubscribe

`DELETE /rest/servicedeskapi/request/{issueIdOrKey}/notification`

This method unsubscribes the user from notifications from a customer request.

{% code fullWidth="true" %}

```go
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")
	response, err := atlassian.Request.Unsubscribe(context.Background(), "DUMMY-4")
	if err != nil {
		if response != nil {
			log.Println("Response HTTP Response", string(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)
}

```

{% endcode %}

## Get customer transitions

`GET /rest/servicedeskapi/request/{issueIdOrKey}/transition`

This method returns a list of transitions, the workflow processes that moves a customer request from one status to another, that the user can perform on a request.&#x20;

* Use this method to provide a user with a list if the actions they can take on a customer request.

{% code fullWidth="true" %}

```go
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 (
		issueKeyOrID = "DESK-3"
		start        = 0
		limit        = 50
	)

	transitions, response, err := atlassian.Request.Transitions(context.Background(), issueKeyOrID, 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 _, transition := range transitions.Values {
		log.Println(transition.ID, transition.Name)
	}
}
```

{% endcode %}

## Perform customer transition

`POST /rest/servicedeskapi/request/{issueIdOrKey}/transition`

This method performs a customer transition for a given request and transition. An optional comment can be included to provide a reason for the transition.

{% code fullWidth="true" %}

```go
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 (
		issueKeyOrID = "DESK-3"
		transitionID = "921"
		comment      = "lorem"
	)

	response, err := atlassian.Request.Transition(context.Background(), issueKeyOrID, transitionID, comment)
	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)
}
```

{% endcode %}

## Create Customer Request

`POST /rest/servicedeskapi/request`

This method creates a customer request at a service desk.&#x20;

* The payload must include the service desk and customer request type, as well as any fields that are required for the request type.&#x20;
* A list of the fields required by a customer request type can be obtained using the `sm.RequestType.Fields` method.

{% code fullWidth="true" %}

```go
package main

import (
	"context"
	"fmt"
	"github.com/ctreminiom/go-atlassian/jira/sm"
	"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")
	)

	atlassian, err := sm.New(nil, host)
	if err != nil {
		return
	}

	atlassian.Auth.SetBasicAuth(mail, token)
	atlassian.Auth.SetUserAgent("curl/7.54.0")

	form := &models.CustomerRequestFields{Fields: make(map[string]interface{})}

	if err := form.Text("summary", "Summary Sample"); err != nil {
		log.Fatal(err)
	}

	if err := form.Date("duedate", time.Now()); err != nil {
		log.Fatal(err)
	}

	if err := form.Components([]string{"Intranet"}); err != nil {
		log.Fatal(err)
	}

	if err := form.Labels([]string{"label-00", "label-01"}); err != nil {
		log.Fatal(err)
	}

	payload := &models.CreateCustomerRequestPayloadScheme{
		RequestParticipants: nil,
		ServiceDeskID:       "1",
		RequestTypeID:       "10",
	}

	ticket, response, err := atlassian.Request.Create(context.Background(), payload, form)
	if err != nil {
		log.Fatal(err)
	}

	log.Println("Response HTTP Code", response.Code)
	log.Println("HTTP Endpoint Used", response.Endpoint)

	fmt.Println("IssueID", ticket.IssueID)
	fmt.Println("IssueKey", ticket.IssueKey)
	fmt.Println("Reporter.EmailAddress", ticket.Reporter.EmailAddress)
	fmt.Println("CreatedDate.Friendly", ticket.CreatedDate.Friendly)

	for _, field := range ticket.RequestFieldValues {
		fmt.Println(field)
	}
}
```

{% endcode %}


# Approval

## Get approvals

`GET /rest/servicedeskapi/request/{issueIdOrKey}/approval`

This method returns all approvals on a customer request.

{% code fullWidth="true" %}

```go
package main

import (
	"context"
	"encoding/json"
	"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 issueKey = "DESK-12"

	approvals, response, err := atlassian.Request.Approval.Gets(context.Background(), issueKey, 0, 50)
	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 _, customRequest := range approvals.Values {
		dataAsJson, err := json.MarshalIndent(customRequest, "", "\t")
		if err != nil {
			log.Fatal(err)
		}
		log.Println(string(dataAsJson))
	}
}
```

{% endcode %}

## Get approval by id

`GET /rest/servicedeskapi/request/{issueIdOrKey}/approval/{approvalId}`

This method returns an approval. Use this method to determine the status of an approval and the list of approvers.

{% code fullWidth="true" %}

```go
package main

import (
	"context"
	"encoding/json"
	"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 (
		issueKey   = "DESK-12"
		approvalID = 2
	)

	approvalsMembers, response, err := atlassian.Request.Approval.Get(context.Background(), issueKey, approvalID)
	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)

	dataAsJson, err := json.MarshalIndent(approvalsMembers, "", "\t")
	if err != nil {
		log.Fatal(err)
	}
	log.Println(string(dataAsJson))
}
```

{% endcode %}

## Answer approval

`POST /rest/servicedeskapi/request/{issueIdOrKey}/approval/{approvalId}`

This method enables a user to **Approve** or **Decline** an approval on a customer request. The approval is assumed to be owned by the user making the call.

{% code fullWidth="true" %}

```go
package main

import (
	"context"
	"encoding/json"
	"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 (
		issueKey   = "DESK-12"
		approvalID = 2
	)

	approvalsMembers, response, err := atlassian.Request.Approval.Answer(context.Background(), issueKey, approvalID, true)
	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)

	dataAsJson, err := json.MarshalIndent(approvalsMembers, "", "\t")
	if err != nil {
		log.Fatal(err)
	}
	log.Println(string(dataAsJson))
}
```

{% endcode %}




---

[Next Page](/llms-full.txt/1)

