All pages
Powered by GitBook
1 of 4

Loading...

Loading...

Loading...

Loading...

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.

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.

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.

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.

Set issue types for workflow in workflow scheme

Not implemented, feel free to open a PR 👍

Delete issue types for workflow in workflow scheme

Not implemented, feel free to open a PR 👍

Scheme

Gets Workflows Schemes

GET /rest/api/{2-3}/workflowscheme

Returns a list of all workflow schemes, not including draft workflow schemes.

package main

import (
	"context"
	"fmt"
	v3 "github.com/ctreminiom/go-atlassian/v2/jira/v3"
	"log"
	"os"
)

func main() {

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

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

	instance.Auth.SetBasicAuth(mail, token)
	instance.Auth.SetUserAgent("curl/7.54.0")

	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)
}
Create Workflows Scheme

POST /rest/api/{2-3}/workflowscheme

Creates a workflow scheme.

Get Workflow Scheme

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

Returns a workflow scheme.

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.

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

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.

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

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.

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.

paginated
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)
}
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)
}
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)
	}
}
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)
}
package main

import (
	"context"
	"fmt"
	v3 "github.com/ctreminiom/go-atlassian/v2/jira/v3"
	"github.com/ctreminiom/go-atlassian/pkg/infra/models"
	"log"
	"os"
)

func main() {

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

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

	instance.Auth.SetBasicAuth(mail, token)
	instance.Auth.SetUserAgent("curl/7.54.0")

	payload := &models.WorkflowSchemePayloadScheme{
		DefaultWorkflow: "jira",
		Name:            "Example workflow scheme",
		Description:     "The description of the example workflow scheme.",
		IssueTypeMappings: map[string]interface{}{
			"10002": "PV: Project Management Workflow",
			"10005": "Software Simplified Workflow for Project K2",
		},
	}

	newWorkflowScheme, response, err := instance.Workflow.Scheme.Create(context.Background(), payload)
	if err != nil {
		if response != nil {
			log.Println(response.Bytes.String())
			log.Println(response.Code)
		}

		log.Fatal(err)
	}

	fmt.Println(newWorkflowScheme.Name)
	fmt.Println(newWorkflowScheme.Description)
	fmt.Println(newWorkflowScheme.ID)
	fmt.Println(newWorkflowScheme.Self)
	fmt.Println(newWorkflowScheme.DefaultWorkflow)
}
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)
}
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)
}
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)
	}
}
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)
	}
}
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)
	}
}

Status

Search Workflow Statuses

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

Search returns a paginated list of statuses that match a search on name or project.

Gets Workflow Statuses

GET /rest/api/{2-3}/statuses

Get returns a list of the statuses specified by one or more status IDs.

Create Workflow Statuses

POST /rest/api/{2-3}/statuses

Create creates statuses for a global or project scope.

Update Workflow Statuses

PUT /rest/api/{2-3}/statuses

Update updates statuses by ID.

Delete Workflow Statuses

DELETE /rest/api/{2-3}/statuses

Delete deletes statuses by ID.

Bulk Workflow Statuses

GET /rest/api/{2-3}/status

Bulk returns a list of all statuses associated with active workflows.

Get Workflow Status

GET /rest/api/{2-3}/status/{idOrName}

Get returns a status.

  • The status must be associated with an active workflow to be returned.

  • If a name is used on more than one status, only the status found first is returned. Therefore, identifying the status by its ID may be preferable.

package main

import (
	"context"
	"fmt"
	v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
	"github.com/ctreminiom/go-atlassian/pkg/infra/models"
	"log"
	"os"
)

func main() {

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

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

	atlassian.Auth.SetBasicAuth(mail, token)
	
	options := &models.WorkflowStatusSearchParams{
		ProjectID:      "10000",
		StatusCategory: "IN_PROGRESS",
		Expand:         []string{"usages"},
	}

	var projectStatuses []*models.WorkflowStatusDetailScheme
	var startAt int

	for {

		page, response, err := atlassian.Workflow.Status.Search(context.Background(), options, startAt, 50)
		if err != nil {
			log.Println(response.Code)
			log.Println(response.Endpoint)
			log.Fatal(err)
		}

		projectStatuses = append(projectStatuses, page.Values...)

		if page.IsLast {
			break
		}

		startAt = startAt + 50
	}

	for _, status := range projectStatuses {
		fmt.Println(status.Name, status.ID, status.StatusCategory)


		fmt.Println("--------------------------------")
		fmt.Println("Status Name:", status.Name)
		fmt.Println("Status ID:", status.ID)
		fmt.Println("Status Category:", status.StatusCategory)

		for index, project := range status.Usages {

			fmt.Println("--- Project Usage #", index)
			fmt.Println("----  Project ID:", project.Project.ID)
			fmt.Println("----  Project IssueTypes:", project.IssueTypes)
		}
		fmt.Println("--------------------------------")
	}
}
package main

import (
	"context"
	"fmt"
	v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
	"log"
	"os"
)

func main() {

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

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

	atlassian.Auth.SetBasicAuth(mail, token)

	statuses, response, err := atlassian.Workflow.Status.Gets(context.Background(), []string{"401", "400", "10008"}, []string{"usages"})
	if err != nil {
		log.Println(response.Code)
		log.Println(response.Endpoint)
		log.Fatal(err)
	}

	for _, status := range statuses {
		fmt.Println(status.Name, status.ID, status.StatusCategory)

		fmt.Println("--------------------------------")
		fmt.Println("Status Name:", status.Name)
		fmt.Println("Status ID:", status.ID)
		fmt.Println("Status Category:", status.StatusCategory)

		for index, project := range status.Usages {

			fmt.Println("--- Project Usage #", index)
			fmt.Println("----  Project ID:", project.Project.ID)
			fmt.Println("----  Project IssueTypes:", project.IssueTypes)
		}
		fmt.Println("--------------------------------")
	}
}
package main

import (
	"context"
	"fmt"
	v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
	"github.com/ctreminiom/go-atlassian/pkg/infra/models"
	"log"
	"os"
)

func main() {

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

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

	atlassian.Auth.SetBasicAuth(mail, token)

	payload := &models.WorkflowStatusPayloadScheme{
		Statuses: []*models.WorkflowStatusNodeScheme{
			{
				Name:           "UAT TEST",
				StatusCategory: "IN_PROGRESS",
				Description: "status description",
			},
			{
				Name:           "Stage TEST",
				StatusCategory: "IN_PROGRESS",
				Description: "status description",
			},
		},
		Scope: &models.WorkflowStatusScopeScheme{
			Type: "GLOBAL",
		},
	}

	statuses, response, err := atlassian.Workflow.Status.Create(context.Background(), payload)
	if err != nil {
		log.Println(response.Code)
		log.Println(response.Endpoint)
		log.Println(response.Bytes.String())
		log.Fatal(err)
	}

	for _, status := range statuses {
		fmt.Println(status.Name, status.ID, status.StatusCategory)

		fmt.Println("--------------------------------")
		fmt.Println("Status Name:", status.Name)
		fmt.Println("Status ID:", status.ID)
		fmt.Println("Status Category:", status.StatusCategory)
		fmt.Println("--------------------------------")
	}
}
package main

import (
	"context"
	v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
	"github.com/ctreminiom/go-atlassian/pkg/infra/models"
	"log"
	"os"
)

func main() {

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

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

	atlassian.Auth.SetBasicAuth(mail, token)

	payload := &models.WorkflowStatusPayloadScheme{
		Statuses: []*models.WorkflowStatusNodeScheme{
			{
				ID:             "10013",
				Name:           "UAT Finished",
				StatusCategory: "DONE",
				Description:    "status description",
			},
			{
				ID:             "10014",
				Name:           "Stage Finished",
				StatusCategory: "DONE",
				Description:    "status description",
			},
		},
	}

	response, err := atlassian.Workflow.Status.Update(context.Background(), payload)
	if err != nil {
		log.Println(response.Code)
		log.Println(response.Endpoint)
		log.Println(response.Bytes.String())
		log.Fatal(err)
	}
}
package main

import (
	"context"
	v2 "github.com/ctreminiom/go-atlassian/v2/jira/v2"
	"log"
	"os"
)

func main() {

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

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

	atlassian.Auth.SetBasicAuth(mail, token)

	response, err := atlassian.Workflow.Status.Delete(context.Background(), []string{"10013", "10014"})
	if err != nil {
		log.Println(response.Code)
		log.Println(response.Endpoint)
		log.Println(response.Bytes.String())
		log.Fatal(err)
	}
}
package main

import (
	"context"
	"fmt"
	v3 "github.com/ctreminiom/go-atlassian/v2/jira/v3"
	"log"
	"os"
)

func main() {

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

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

	instance.Auth.SetBasicAuth(mail, token)
	instance.Auth.SetUserAgent("curl/7.54.0")

	activeStatuses, response, err := instance.Workflow.Status.Bulk(context.Background())
	if err != nil {
		if response != nil {
			log.Println(response.Bytes.String())
			log.Println(response.Code)
		}

		log.Fatal(err)
	}

	for _, status := range activeStatuses {
		fmt.Println(status.Name, status.ID)
	}
}
package main

import (
	"context"
	"fmt"
	v3 "github.com/ctreminiom/go-atlassian/v2/jira/v3"
	"log"
	"os"
)

func main() {

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

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

	instance.Auth.SetBasicAuth(mail, token)
	instance.Auth.SetUserAgent("curl/7.54.0")

	status, response, err := instance.Workflow.Status.Get(context.Background(), "Open")
	if err != nil {
		if response != nil {
			log.Println(response.Bytes.String())
			log.Println(response.Code)
		}

		log.Fatal(err)
	}

	fmt.Println(status.Name, status.ID)
}

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.

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

Deprecated

Create creates a workflow. You can define transition rules using the shapes detailed in the following sections. If no transitional rules are specified the default system transition rules are used.

Conditions

Conditions enable workflow rules that govern whether a transition can execute.

Always false conditions

A condition that always fails.

Block transition until approval

A condition that blocks issue transition if there is a pending approval.

Compare number custom field condition

A condition that allows transition if a comparison between a number custom field and a value is true.

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.

Only assignee condition

A condition that allows only the assignee to execute a transition.

Only reporter condition

A condition that allows only the reporter to execute a transition.

Permission condition

A condition that allows only users with a permission to execute a transition.

Previous status condition

A condition that allows a transition based on whether an issue has or has not transitioned through a status.

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.

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.

User is in any group condition

A condition that allows users belonging to any group from a list of groups to execute a transition.

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.

User is in custom field condition

A condition that allows only users listed in a given custom field to execute the transition.

User is in group condition

A condition that allows users belonging to a group to execute a transition.

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.

User is in project role condition

A condition that allows users with a project role to execute a transition.

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.

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.

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.

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.

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.

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.

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.

Permission validator

A validator that checks the user has a permission.

Previous status validator

A validator that checks if the issue has held a status.

Regular expression validator

A validator that checks the content of a field against a regular expression.

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.

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.

Update issue status

A post function that sets issue status to the linked status of the destination workflow status.

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.

Create comment

A post function that adds a comment entered during the transition to an issue.

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.

Store issue

A post function that stores updates to an issue.

This post function can only be added to the initial transition and can only be added once.

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.

This post function can be included once in a transition.

Assign to lead function

A post function that assigns the issue to the project or component lead developer.

This post function can be included once in a transition.

Assign to reporter function

A post function that assigns the issue to the reporter.

This post function can be included once in a transition.

Clear field value function

A post function that clears the value from a field.

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.

Update issue custom field function

A post function that updates the content of an issue custom field.

Update issue field function

A post function that updates a simple issue field.

Search Workflows

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

Returns a list of published classic workflows. When workflow names are specified, details of those workflows are returned. Otherwise, all published classic workflows are returned.

This operation does not return next-gen workflows, Deprecated

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.

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.

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

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.

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.

A validator rule that checks if a user has the required permissions to execute the transition in the workflow.

Parameters:

  • permissionKey The permission required to perform the transition. Allowed values: .

A validator to block the child issue\u2019s transition depending on the parent issue\u2019s status.

A validator that checks if an issue has transitioned through specified previous status(es) before allowing the current transition to occur.

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.

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

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.

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

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.

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.

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

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.

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.

required:

  • Administer Jira project permission to create all, including global-scoped, workflows

  • Administer projects project permissions to create project-scoped workflows

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.

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.

The validation checks for potential issues that could prevent the workflows from being updated successfully. The validation process will check for conditions such as:

  • Whether the transitions are valid.

  • Whether the status and transition names are unique within the workflow.

  • If the validation fails, a list of validation errors is returned, which should be resolved before applying the changes.

Parameters:
  • previousStatusIds a comma-separated list of status IDs, currently only support one ID.

  • mostRecentStatusOnly when true only considers the most recent status for the condition evaluation. Allowed values: true, false.

A validation that ensures a specific field's value meets the defined criteria before allowing an issue to transition in the workflow.

Depending on the rule type, the result will vary:

Field required

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

paginated
Permissions
built-in Jira permissions
Permissions
Permissions

{
   "ruleKey": "system:validate-field-value",
   "parameters": {
     "ruleType": "fieldRequired",
     "fieldsRequired": "assignee",
     "ignoreContext": "true",
     "errorMessage": "An assignee must be set!"
   }
 }
{
	Type: "RemoteOnlyCondition",
},
{
    Type: "BlockInProgressApprovalCondition",
}
{
	Type: "CompareNumberCFCondition",
	Configuration: map[string]interface{}{
		"comparator": "=",
		"fieldId":    "customfield_10029",
		"fieldValue": 2,
	},
}
{
    Type: "RemoteOnlyCondition",
}
{
    Type: "AllowOnlyAssignee",
}
{
    Type: "AllowOnlyReporter",
}
{
	Type: "PermissionCondition",
	Configuration: map[string]interface{}{
		"permissionKey": "BROWSE_PROJECTS",
	},
},
{
	Type: "PreviousStatusCondition",
	Configuration: map[string]interface{}{
		"ignoreLoopTransitions": true,
		"includeCurrentStatus":  true,
		"mostRecentStatusOnly":  true,
		"reverseCondition":      true,
		"previousStatus": map[string]interface{}{
			"id": "5",
		},
	},
}
{
	Type: "SeparationOfDutiesCondition",
	Configuration: map[string]interface{}{
		"fromStatus": map[string]interface{}{"id": "5"},
		"toStatus":   map[string]interface{}{"id": "6"},
	},
}
{
	Type: "SubTaskBlockingCondition",
	Configuration: map[string]interface{}{
		"statuses": []map[string]interface{}{
			{
				"id": "1",
			},
			{
				"id": "3",
			},
		},
	},
},
{
	Type: "UserInAnyGroupCondition",
	Configuration: map[string]interface{}{
		"groups": []string{"administrators", "atlassian-addons-admin"},
	},
}
{
	Type: "InAnyProjectRoleCondition",
	Configuration: map[string]interface{}{
		"projectRoles": []map[string]interface{}{
			{
				"id": "10002",
			},
			{
				"id": "10003",
			},
			{
				"id": "10012",
			},
			{
				"id": "10013",
			},
		},
	},
}
{
	Type: "UserIsInCustomFieldCondition",
	Configuration: map[string]interface{}{
		"allowUserInField": false,
		"fieldId":          "customfield_10010",
	},
}
{
	Type: "UserInGroupCondition",
	Configuration: map[string]interface{}{
		"group": "administrators",
	},
}
{
	Type: "InGroupCFCondition",
	Configuration: map[string]interface{}{
		"fieldId": "customfield_10012",
	},
}
{
	Type: "InProjectRoleCondition",
	Configuration: map[string]interface{}{
		"projectRole": map[string]interface{}{
			"id": "10002",
		},
	},
}
{
	Type: "ValueFieldCondition",
	Configuration: map[string]interface{}{
		"fieldId":        "assignee",
		"fieldValue":     "qm:6e1ecee6-8e64-4db6-8c85-916bb3275f51:54b56885-2bd2-4381-8239-78263442520f",
		"comparisonType": "NUMBER",
		"comparator":     "=",
	},
}
{
	Type: "DateFieldValidator",
	Configuration: map[string]interface{}{
		"comparator":  ">",
		"date1":       "updated",
		"date2":       "created",
		"expression":  "1d",
		"includeTime": true,
	},
}
{
	Type: "WindowsDateValidator",
	Configuration: map[string]interface{}{
		"date1":       "customfield_10009",
		"date2":       "created",
		"windowsDays": 5,
	},
}
{
	Type: "FieldRequiredValidator",
	Configuration: map[string]interface{}{
		"ignoreContext": true,
		"errorMessage":  "Hey",
		"fieldIds": []string{
			"versions",
			"customfield_10037",
			"customfield_10003",
		},
	},
}
{
	Type: "FieldChangedValidator",
	Configuration: map[string]interface{}{
		"fieldId":      "comment",
		"errorMessage": "Hey",
		"exemptedGroups": []string{
			"administrators",
			"atlassian-addons-admin",
		},
	},
}
{
	Type: "FieldHasSingleValueValidator",
	Configuration: map[string]interface{}{
		"fieldId":         "attachment",
		"excludeSubtasks": true,
	},
}
{
	Type: "ParentStatusValidator",
	Configuration: map[string]interface{}{
		"parentStatuses": []map[string]interface{}{
			{
				"id": "2",
			},
			{
				"id": "1",
			},
		},
	},
}
{
	Type: "PermissionValidator",
	Configuration: map[string]interface{}{
		"permissionKey": "ADMINISTER_PROJECTS",
	},
},
{
	Type: "PreviousStatusValidator",
	Configuration: map[string]interface{}{
		"mostRecentStatusOnly": false,
		"previousStatus":       map[string]interface{}{"id": "15"},
	},
},
{
	Type: "RegexpFieldValidator",
	Configuration: map[string]interface{}{
		"regExp":  "[0-9]",
		"fieldId": "customfield_10029",
	},
},
{
	Type: "UserPermissionValidator",
	Configuration: map[string]interface{}{
		"permissionKey": "BROWSE_PROJECTS",
		"nullAllowed":   false,
		"username":      "TestUser",
	},
},
{
	Type: "FireIssueEventFunction",
	Configuration: map[string]interface{}{
		"event": map[string]interface{}{"id": "1"},
	},
},
{
    Type: "UpdateIssueStatusFunction",
}
{
    Type: "CreateCommentFunction",
}
{
    Type: "CreateCommentFunction",
}
{
    Type: "CreateCommentFunction",
}
{
    Type: "CreateCommentFunction",
}
{
    Type: "CreateCommentFunction",
}
{
	Type: "ClearFieldValuePostFunction",
	Configuration: map[string]interface{}{
		"fieldId": "assignee",
	},
},
{
	Type: "CopyValueFromOtherFieldPostFunction",
	Configuration: map[string]interface{}{
		"sourceFieldId":      "assignee",
		"destinationFieldId": "creator",
		"copyType":           "same",
	},
},
{
	Type: "UpdateIssueCustomFieldPostFunction",
	Configuration: map[string]interface{}{
		"mode":       "append",
		"fieldId":    "customfield_10003",
		"fieldValue": "yikes",
	},
},
{
	Type: "UpdateIssueFieldFunction",
	Configuration: map[string]interface{}{
		"fieldId":    "assignee",
		"fieldValue": "5f0c277e70b8a90025a00776",
	},
},
package main

import (
	"context"
	v3 "github.com/ctreminiom/go-atlassian/jira/v3"
	"github.com/ctreminiom/go-atlassian/pkg/infra/models"
	"log"
	"os"
)

func main() {

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

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

	instance.Auth.SetBasicAuth(mail, token)
	instance.Auth.SetUserAgent("curl/7.54.0")

	payload := &models.WorkflowPayloadScheme{
		Name:        "Workflow Sample",
		Description: "description of the workflow sample",
		Statuses: []*models.WorkflowTransitionScreenScheme{
			{
				ID: "1", // Open
				Properties: map[string]interface{}{
					"jira.issue.editable": true,
				},
			},
			{
				ID: "3", // In Progress
			},
		},
		Transitions: []*models.WorkflowTransitionPayloadScheme{
			{
				Name: "Open",
				To:   "1",
				Type: "initial",
			},
			{
				Name: "Open",
				From: []string{"1"},
				Properties: map[string]interface{}{
					"custom-property": "custom-value",
				},
				Rules: &models.WorkflowTransitionRulePayloadScheme{
					Conditions: &models.WorkflowConditionScheme{
						Conditions: []*models.WorkflowConditionScheme{
							{
								Type: "RemoteOnlyCondition",
							},
							{
								Configuration: map[string]interface{}{
									"groups": []string{"confluence-users", "scrum-masters"},
								},
								Type: "UserInAnyGroupCondition",
							},
						},
						Operator: "AND",
					},
				},
				To:   "3",
				Type: "directed",
			},
		},
	}

	newWorkflow, response, err := instance.Workflow.Create(context.Background(), payload)
	if err != nil {
		if response != nil {
			log.Println(response.Bytes.String())
			log.Println(response.Code)
		}

		log.Fatal(err)
	}

	log.Println(newWorkflow.Name)
	log.Println(newWorkflow.EntityID)
}
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))
	}
}
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)
	}
}
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))
	}
}
{
   "ruleKey": "system:check-permission-validator",
   "parameters": {
     "permissionKey": "ADMINISTER_PROJECTS"
   }
 }
{
   "ruleKey" : "system:parent-or-child-blocking-validator"
   "parameters" : {
     "blocker" : "PARENT"
     "statusIds" : "1,2,3"
   }
}
{
   "ruleKey": "system:previous-status-validator",
   "parameters": {
     "previousStatusIds": "10014",
     "mostRecentStatusOnly": "true"
   }
 }
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))
}
payload.AddStatus(&models.WorkflowStatusUpdateScheme{
    ID:              "10012",
    Name:            "To Do",
    StatusCategory:  "TODO",
    StatusReference: "f0b24de5-25e7-4fab-ab94-63d81db6c0c0",
})
// 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",
    },
})
// Adding the workflow to the payload
err := payload.AddWorkflow(epicWorkflow)
if err != nil {
    log.Fatal(err)
}

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