Sample code for 30+ languages & platforms
DataFlex Requires Chilkat v11.0.0+

Jira Cloud: Discover Issue Types and Required Fields

See more Jira Examples

List a project's available issue types, then retrieve the creation fields for the type selected by name. Required fields and allowed values depend on project configuration. Inspect the returned field metadata before adapting the create-issue example. The current project-scoped metadata endpoints replace the deprecated general create-metadata endpoint.

The code lists field IDs and required flags, plus the full field metadata for each page (including schemas and allowed values). Field names are display labels; submit the returned field ID, such as customfield_10042. A field can be absent from the create screen or require a project-specific value.

The code uses an Atlassian account email and an API token without scopes with the site URL. For a scoped API token, keep Basic authentication and change baseUrl to https://api.atlassian.com/ex/jira/YOUR_CLOUD_ID. For OAuth2, use that gateway URL, omit Login/Password/BasicAuth, and set http.AuthToken to the access token. See API token authentication and OAuth2 authorization. The account must have permission for the operation; OAuth scopes do not grant additional Jira permissions.

Targets Jira Cloud. Jira Data Center has a separate REST API and may require different paths, authentication, or payloads.

Atlassian REST API documentation

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttp
    String sBaseUrl
    Handle hoUrl
    Variant vResp
    Handle hoResp
    Handle hoReply
    String sIssueTypeName
    String sIssueTypeId
    Integer iMatches
    Integer iTypesStart
    Boolean iTypesMore
    Handle hoTypesOffset
    Integer iTypesCount
    Integer iTypesIndex
    Integer iFieldsStart
    Boolean iFieldsMore
    Handle hoFieldsOffset
    Integer iFieldsCount
    Integer iFieldsIndex
    String sTemp1
    String sTemp2
    Integer iTemp1
    Integer iTemp2
    Boolean bTemp1

    Move False To iSuccess

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End
    Set ComRequireSslCertVerify Of hoHttp To True
    Set ComBasicAuth Of hoHttp To True
    //  Read these credentials from private application configuration.
    Set ComLogin Of hoHttp To "YOUR_ATLASSIAN_EMAIL"
    Set ComPassword Of hoHttp To "YOUR_API_TOKEN"
    Move "https://your-domain.atlassian.net" To sBaseUrl
    Set ComAccept Of hoHttp To "application/json"
    Get Create (RefClass(cComChilkatStringBuilder)) To hoUrl
    If (Not(IsComObjectCreated(hoUrl))) Begin
        Send CreateComObject of hoUrl
    End
    Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
    If (Not(IsComObjectCreated(hoResp))) Begin
        Send CreateComObject of hoResp
    End
    Get Create (RefClass(cComChilkatJsonObject)) To hoReply
    If (Not(IsComObjectCreated(hoReply))) Begin
        Send CreateComObject of hoReply
    End
    Get ComSetUrlVar Of hoHttp "projectKey" "PROJECT" To iSuccess
    Move "Task" To sIssueTypeName
    Move "" To sIssueTypeId
    Move 0 To iMatches
    Move 0 To iTypesStart
    Move True To iTypesMore
    Get Create (RefClass(cComChilkatStringBuilder)) To hoTypesOffset
    If (Not(IsComObjectCreated(hoTypesOffset))) Begin
        Send CreateComObject of hoTypesOffset
    End
    While (iTypesMore = True)
        Send ComClear To hoTypesOffset
        Get ComAppendInt Of hoTypesOffset iTypesStart To iSuccess
        Get ComGetAsString Of hoTypesOffset To sTemp1
        Get ComSetUrlVar Of hoHttp "offset" sTemp1 To iSuccess
        Get ComSetString Of hoUrl sBaseUrl To iSuccess
        Get ComAppend Of hoUrl "/rest/api/3/issue/createmeta/{$projectKey}/issuetypes?startAt={$offset}&maxResults=50" To iSuccess
        Get ComGetAsString Of hoUrl To sTemp1
        Get pvComObject of hoResp to vResp
        Get ComHttpNoBody Of hoHttp "GET" sTemp1 vResp To iSuccess
        Get ComStatusCode Of hoResp To iTemp1
        If (iTemp1 = 0) Begin
            Showln "No HTTP response was received. Check connectivity and TLS settings."
            Procedure_Return
        End

        Get ComStatusCode Of hoResp To iTemp1
        Get ComStatusCode Of hoResp To iTemp2
        If ((iSuccess <> True) Or (iTemp1 < 200) Or (iTemp2 >= 300)) Begin
            Get ComStatusCode Of hoResp To iTemp1
            Showln "Request failed. HTTP " iTemp1
            Get ComStatusCode Of hoResp To iTemp1
            If (iTemp1 = 429) Begin
                Get ComGetHeaderField Of hoResp "Retry-After" To sTemp1
                Showln "Rate limited. Retry-After: " sTemp1
            End

            //  Inspect this response locally; it can contain private Jira data.
            Get ComBodyStr Of hoResp To sTemp1
            Showln sTemp1
            Procedure_Return
        End

        Get ComBodyStr Of hoResp To sTemp1
        Get ComLoad Of hoReply sTemp1 To iSuccess
        If (iSuccess <> True) Begin
            Showln "Expected a JSON object in the response."
            Procedure_Return
        End

        Get ComJsonTypeOf Of hoReply "issueTypes" To iTemp1
        If (iTemp1 <> 4) Begin
            Showln "Expected an array: issueTypes"
            Procedure_Return
        End

        Get ComSizeOfArray Of hoReply "issueTypes" To iTypesCount
        Move 0 To iTypesIndex
        While (iTypesIndex < iTypesCount)
            Set ComI Of hoReply To iTypesIndex
            Get ComStringOf Of hoReply "issueTypes[i].name" To sTemp1
            Get ComStringOf Of hoReply "issueTypes[i].id" To sTemp2
            Showln sTemp1 "  ID: " sTemp2
            Get ComStringOfEquals Of hoReply "issueTypes[i].name" sIssueTypeName True To bTemp1
            If (bTemp1 = True) Begin
                Get ComStringOf Of hoReply "issueTypes[i].id" To sIssueTypeId
                Move (iMatches + 1) To iMatches
            End

            Move (iTypesIndex + 1) To iTypesIndex
        Loop

        Move (iTypesStart + iTypesCount) To iTypesStart
        Get ComIntOf Of hoReply "total" To iTemp1
        Move ((iTypesStart < iTemp1)) To iTypesMore
        If ((iTypesMore = True) And (iTypesCount = 0)) Begin
            Showln "Pagination made no progress; stopping."
            Procedure_Return
        End

    Loop

    If (iMatches <> 1) Begin
        Showln "Select one unambiguous issue type from the returned list."
        Procedure_Return
    End

    Get ComSetUrlVar Of hoHttp "issueTypeId" sIssueTypeId To iSuccess
    Move 0 To iFieldsStart
    Move True To iFieldsMore
    Get Create (RefClass(cComChilkatStringBuilder)) To hoFieldsOffset
    If (Not(IsComObjectCreated(hoFieldsOffset))) Begin
        Send CreateComObject of hoFieldsOffset
    End
    While (iFieldsMore = True)
        Send ComClear To hoFieldsOffset
        Get ComAppendInt Of hoFieldsOffset iFieldsStart To iSuccess
        Get ComGetAsString Of hoFieldsOffset To sTemp1
        Get ComSetUrlVar Of hoHttp "offset" sTemp1 To iSuccess
        Get ComSetString Of hoUrl sBaseUrl To iSuccess
        Get ComAppend Of hoUrl "/rest/api/3/issue/createmeta/{$projectKey}/issuetypes/{$issueTypeId}?startAt={$offset}&maxResults=50" To iSuccess
        Get ComGetAsString Of hoUrl To sTemp1
        Get pvComObject of hoResp to vResp
        Get ComHttpNoBody Of hoHttp "GET" sTemp1 vResp To iSuccess
        Get ComStatusCode Of hoResp To iTemp1
        If (iTemp1 = 0) Begin
            Showln "No HTTP response was received. Check connectivity and TLS settings."
            Procedure_Return
        End

        Get ComStatusCode Of hoResp To iTemp1
        Get ComStatusCode Of hoResp To iTemp2
        If ((iSuccess <> True) Or (iTemp1 < 200) Or (iTemp2 >= 300)) Begin
            Get ComStatusCode Of hoResp To iTemp1
            Showln "Request failed. HTTP " iTemp1
            Get ComStatusCode Of hoResp To iTemp1
            If (iTemp1 = 429) Begin
                Get ComGetHeaderField Of hoResp "Retry-After" To sTemp1
                Showln "Rate limited. Retry-After: " sTemp1
            End

            //  Inspect this response locally; it can contain private Jira data.
            Get ComBodyStr Of hoResp To sTemp1
            Showln sTemp1
            Procedure_Return
        End

        Get ComBodyStr Of hoResp To sTemp1
        Get ComLoad Of hoReply sTemp1 To iSuccess
        If (iSuccess <> True) Begin
            Showln "Expected a JSON object in the response."
            Procedure_Return
        End

        Get ComJsonTypeOf Of hoReply "fields" To iTemp1
        If (iTemp1 <> 4) Begin
            Showln "Expected an array: fields"
            Procedure_Return
        End

        //  Full metadata includes field schemas and allowed values.
        Get ComEmit Of hoReply To sTemp1
        Showln sTemp1
        Get ComSizeOfArray Of hoReply "fields" To iFieldsCount
        Move 0 To iFieldsIndex
        While (iFieldsIndex < iFieldsCount)
            Set ComI Of hoReply To iFieldsIndex
            Get ComStringOf Of hoReply "fields[i].fieldId" To sTemp1
            Get ComStringOf Of hoReply "fields[i].name" To sTemp2
            Get ComBoolOf Of hoReply "fields[i].required" To bTemp1
            Showln sTemp1 "  " sTemp2 "  Required: " bTemp1
            Move (iFieldsIndex + 1) To iFieldsIndex
        Loop

        Move (iFieldsStart + iFieldsCount) To iFieldsStart
        Get ComIntOf Of hoReply "total" To iTemp1
        Move ((iFieldsStart < iTemp1)) To iFieldsMore
        If ((iFieldsMore = True) And (iFieldsCount = 0)) Begin
            Showln "Pagination made no progress; stopping."
            Procedure_Return
        End

    Loop



End_Procedure