0

Validate update workflows

by
Published Nov 2, 2023

Validate the payload for bulk update workflows. **[Permissions](#permissions) required:** * *Administer Jira* project permission to create all, including global-scoped, workflows * *Administer projects* project permissions to create project-scoped workflows

Script jira
  • Submitted by hugo697 Typescript (fetch-only)
    Created 525 days ago
    1
    type Jira = {
    2
      username: string;
    3
      password: string;
    4
      domain: string;
    5
    };
    6
    /**
    7
     * Validate update workflows
    8
     * Validate the payload for bulk update workflows.
    9
    
    
    10
    **[Permissions](#permissions) required:**
    11
    
    
    12
     *  *Administer Jira* project permission to create all, including global-scoped, workflows
    13
     *  *Administer projects* project permissions to create project-scoped workflows
    14
     */
    15
    export async function main(
    16
      auth: Jira,
    17
      body: {
    18
        payload: {
    19
          statuses: {
    20
            description?: string;
    21
            id?: string;
    22
            name: string;
    23
            statusCategory: "TODO" | "IN_PROGRESS" | "DONE";
    24
            statusReference: string;
    25
            [k: string]: unknown;
    26
          }[];
    27
          workflows: {
    28
            defaultStatusMappings?: {
    29
              newStatusReference: string;
    30
              oldStatusReference: string;
    31
              [k: string]: unknown;
    32
            }[];
    33
            description?: string;
    34
            id: string;
    35
            startPointLayout?: { x?: number; y?: number };
    36
            statusMappings?: {
    37
              issueTypeId: string;
    38
              projectId: string;
    39
              statusMigrations: {
    40
                newStatusReference: string;
    41
                oldStatusReference: string;
    42
                [k: string]: unknown;
    43
              }[];
    44
              [k: string]: unknown;
    45
            }[];
    46
            statuses: {
    47
              layout?: { x?: number; y?: number };
    48
              properties: { [k: string]: string };
    49
              statusReference: string;
    50
              [k: string]: unknown;
    51
            }[];
    52
            transitions: {
    53
              actions?: {
    54
                id?: string;
    55
                parameters?: { [k: string]: string };
    56
                ruleKey: string;
    57
              }[];
    58
              conditions?: {
    59
                conditionGroups?: {}[];
    60
                conditions?: {
    61
                  id?: string;
    62
                  parameters?: { [k: string]: string };
    63
                  ruleKey: string;
    64
                }[];
    65
                operation: "ANY" | "ALL";
    66
              };
    67
              customIssueEventId?: string;
    68
              description?: string;
    69
              from?: { port?: number; statusReference: string }[];
    70
              id: string;
    71
              name: string;
    72
              properties?: { [k: string]: string };
    73
              to?: { port?: number; statusReference: string };
    74
              transitionScreen?: {
    75
                id?: string;
    76
                parameters?: { [k: string]: string };
    77
                ruleKey: string;
    78
              };
    79
              triggers?: {
    80
                id?: string;
    81
                parameters: { [k: string]: string };
    82
                ruleKey: string;
    83
              }[];
    84
              type: "INITIAL" | "GLOBAL" | "DIRECTED";
    85
              validators?: {
    86
                id?: string;
    87
                parameters?: { [k: string]: string };
    88
                ruleKey: string;
    89
              }[];
    90
              [k: string]: unknown;
    91
            }[];
    92
            version: { id: string; versionNumber: number };
    93
            [k: string]: unknown;
    94
          }[];
    95
        };
    96
        validationOptions?: { levels?: ("WARNING" | "ERROR")[] };
    97
      }
    98
    ) {
    99
      const url = new URL(
    100
        `https://${auth.domain}.atlassian.net/rest/api/2/workflows/update/validation`
    101
      );
    102
    
    
    103
      const response = await fetch(url, {
    104
        method: "POST",
    105
        headers: {
    106
          "Content-Type": "application/json",
    107
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    108
        },
    109
        body: JSON.stringify(body),
    110
      });
    111
      if (!response.ok) {
    112
        const text = await response.text();
    113
        throw new Error(`${response.status} ${text}`);
    114
      }
    115
      return await response.json();
    116
    }
    117