Page cover

๐Ÿ”ฎ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/v2/jira/v3"
	"github.com/ctreminiom/go-atlassian/v2/jira/v2"
	"github.com/ctreminiom/go-atlassian/pkg/infra/models"
	"log"
	"os"
)

func main() {

	/*
		----------- Set an environment variable in git bash -----------
		export HOST="https://ctreminiom.atlassian.net/"
		export MAIL="MAIL_ADDRESS"
		export TOKEN="TOKEN_API"

		Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
	*/

	var (
		host  = os.Getenv("HOST")
		mail  = os.Getenv("MAIL")
		token = os.Getenv("TOKEN")
	)

	atlassian, err := v2.New(nil, host)
	if err != nil {
		log.Fatal(err)
	}

	atlassian.Auth.SetBasicAuth(mail, token)

	payload := &models.ComponentPayloadScheme{
		IsAssigneeTypeValid: false,
		Name:                "Component 2",
		Description:         "This is a Jira component",
		Project:             "KP",
		AssigneeType:        "PROJECT_LEAD",
		LeadAccountID:       "5b86be50b8e3cb5895860d6d",
	}

	newComponent, response, err := atlassian.Project.Component.Create(context.Background(), payload)
	if err != nil {
		log.Fatal(err)
	}

	log.Println("HTTP Endpoint Used", response.Endpoint)
	log.Printf("The new component has been created with the ID %v", newComponent.ID)
}

Get component

GET /rest/api/{2-3}/component/{id}

Returns a component.

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.

Delete component

DELETE /rest/api/{2-3}/component/{id}

Deletes a component.

Get component issues count

GET /rest/api/{2-3}/component/{id}/relatedIssueCounts

Returns the counts of issues assigned to the component.

Get project components

GET /rest/api/{2-3}/project/{projectIdOrKey}/components

Returns all components in a project.

Last updated

Was this helpful?