Ask or search…
K
🔮

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.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/jira/v3"
"github.com/ctreminiom/go-atlassian/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
/*
----------- Set an environment variable in git bash -----------
export HOST="https://ctreminiom.atlassian.net/"
export MAIL="MAIL_ADDRESS"
export TOKEN="TOKEN_API"
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
*/
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
atlassian.Auth.SetBasicAuth(mail, token)
payload := &models.ComponentPayloadScheme{
IsAssigneeTypeValid: false,
Name: "Component 2",
Description: "This is a Jira component",
Project: "KP",
AssigneeType: "PROJECT_LEAD",
LeadAccountID: "5b86be50b8e3cb5895860d6d",
}
newComponent, response, err := atlassian.Project.Component.Create(context.Background(), payload)
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
log.Printf("The new component has been created with the ID %v", newComponent.ID)
}

Get component

GET /rest/api/{2-3}/component/{id}
Returns a component.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/jira/v3"
"github.com/ctreminiom/go-atlassian/jira/v2"
"log"
"os"
)
func main() {
/*
----------- Set an environment variable in git bash -----------
export HOST="https://ctreminiom.atlassian.net/"
export MAIL="MAIL_ADDRESS"
export TOKEN="TOKEN_API"
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
*/
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
atlassian.Auth.SetBasicAuth(mail, token)
component, response, err := atlassian.Project.Component.Get(context.Background(), "10006")
if err != nil {
log.Fatal(err)
}
log.Println(component)
log.Println(response.Endpoint)
}

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.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/jira/v3"
"github.com/ctreminiom/go-atlassian/jira/v2"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"log"
"os"
)
func main() {
/*
----------- Set an environment variable in git bash -----------
export HOST="https://ctreminiom.atlassian.net/"
export MAIL="MAIL_ADDRESS"
export TOKEN="TOKEN_API"
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
*/
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
atlassian.Auth.SetBasicAuth(mail, token)
payload := &models.ComponentPayloadScheme{
IsAssigneeTypeValid: false,
Name: "Component 1 - UPDATED",
Description: "This is a Jira component - UPDATED",
}
componentUpdated, response, err := atlassian.Project.Component.Update(context.Background(), "10006", payload)
if err != nil {
log.Fatal(err)
}
log.Println(response.Endpoint)
log.Println(componentUpdated)
}

Delete component

DELETE /rest/api/{2-3}/component/{id}
Deletes a component.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/jira/v3"
"github.com/ctreminiom/go-atlassian/jira/v2"
"log"
"os"
)
func main() {
/*
----------- Set an environment variable in git bash -----------
export HOST="https://ctreminiom.atlassian.net/"
export MAIL="MAIL_ADDRESS"
export TOKEN="TOKEN_API"
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
*/
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
atlassian.Auth.SetBasicAuth(mail, token)
response, err := atlassian.Project.Component.Delete(context.Background(), "10006")
if err != nil {
log.Fatal(err)
}
log.Println("HTTP Endpoint Used", response.Endpoint)
}

Get component issues count

GET /rest/api/{2-3}/component/{id}/relatedIssueCounts
Returns the counts of issues assigned to the component.
package main
import (
"context"
_ "github.com/ctreminiom/go-atlassian/jira/v3"
"github.com/ctreminiom/go-atlassian/jira/v2"
"log"
"os"
)
func main() {
/*
----------- Set an environment variable in git bash -----------
export HOST="https://ctreminiom.atlassian.net/"
export MAIL="MAIL_ADDRESS"
export TOKEN="TOKEN_API"
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
*/
var (
host = os.Getenv("HOST")
mail = os.Getenv("MAIL")
token = os.Getenv("TOKEN")
)
atlassian, err := v2.New(nil, host)
if err != nil {
log.Fatal(err)
}
atlassian.Auth.SetBasicAuth(mail, token)
count, response, err := atlassian.Project.Component.Count(context.Background(), "10005")
if err != nil {
log.Fatal(err)
}
log.Println(count)
log.Println(response.Endpoint)
}

Get project components

GET /rest/api/{2-3}/project/{projectIdOrKey}/components
Returns all components in a project.
1
package main
2
3
import (
4
"context"
5
_ "github.com/ctreminiom/go-atlassian/jira/v3"
6
"github.com/ctreminiom/go-atlassian/jira/v2"
7
"log"
8
"os"
9
)
10
11
func main() {
12
13
/*
14
----------- Set an environment variable in git bash -----------
15
export HOST="https://ctreminiom.atlassian.net/"
16
export MAIL="MAIL_ADDRESS"
17
export TOKEN="TOKEN_API"
18
19
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
20
*/
21
22
var (
23
host = os.Getenv("HOST")
24
mail = os.Getenv("MAIL")
25
token = os.Getenv("TOKEN")
26
)
27
28
atlassian, err := v2.New(nil, host)
29
if err != nil {
30
log.Fatal(err)
31
}
32
33
atlassian.Auth.SetBasicAuth(mail, token)
34
35
var projectKey = "KP"
36
components, response, err := atlassian.Project.Component.Gets(context.Background(), projectKey)
37
if err != nil {
38
log.Fatal(err)
39
}
40
41
log.Println(response.Endpoint)
42
for _, component := range components {
43
log.Println(component)
44
}
45
}