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

Jira Cloud: Discover Service Desks and Request Types

See more Jira Examples

List accessible service desks, find one by its project key, list its request types, and retrieve the required fields for a request type selected by name. Use the returned service desk ID and request type ID in the customer-request creation example.

Request types are portal-facing forms and are not interchangeable with Jira issue types. Their fields, allowed values, and required flags can differ from the platform create-issue metadata. Access depends on the account's customer or agent role. OAuth integrations need the Service Management scopes documented for these operations.

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 B4X Downloads

B4X
Dim success As Boolean = False

'  Assumes Chilkat is unlocked. See Global Unlock Sample.

Dim http As ChilkatHttp
http.Initialize("http")
http.RequireSslCertVerify = True
http.BasicAuth = True
'  Read these credentials from private application configuration.
http.Login = "YOUR_ATLASSIAN_EMAIL"
http.Password = "YOUR_API_TOKEN"
Dim baseUrl As String = "https://your-domain.atlassian.net"
http.Accept = "application/json"
Dim url As ChilkatStringBuilder
url.Initialize
Dim resp As ChilkatHttpResponse
resp.Initialize
Dim reply As ChilkatJsonObject
reply.Initialize
Dim projectKey As String = "SUPPORT"
Dim requestTypeName As String = "General request"
Dim serviceDeskId As String = ""
Dim requestTypeId As String = ""
Dim deskMatches As Int = 0
Dim typeMatches As Int = 0
Dim desksStart As Int = 0
Dim desksMore As Boolean = True
Dim desksOffset As ChilkatStringBuilder
desksOffset.Initialize
Do While (desksMore = True)
    desksOffset.Clear
    desksOffset.AppendInt(desksStart)
    http.SetUrlVar("offset", desksOffset.GetAsString)
    url.SetString(baseUrl)
    url.Append("/rest/servicedeskapi/servicedesk?start={$offset}&limit=50")
    success = http.HttpNoBody("GET", url.GetAsString, resp)
    If resp.StatusCode = 0 Then
        Log("No HTTP response was received. Check connectivity and TLS settings.")
        Return
    End If

    If (success <> True) Or (resp.StatusCode < 200) Or (resp.StatusCode >= 300) Then
        Log("Request failed. HTTP " & resp.StatusCode)
        If resp.StatusCode = 429 Then
            Log("Rate limited. Retry-After: " & resp.GetHeaderField("Retry-After"))
        End If

        '  Inspect this response locally; it can contain private Jira data.
        Log(resp.BodyStr)
        Return
    End If

    success = reply.Load(resp.BodyStr)
    If success <> True Then
        Log("Expected a JSON object in the response.")
        Return
    End If

    If reply.JsonTypeOf("values") <> 4 Then
        Log("Expected an array: values")
        Return
    End If

    Dim desksCount As Int = reply.SizeOfArray("values")
    Dim desksIndex As Int = 0
    Do While (desksIndex < desksCount)
        reply.I = desksIndex
        Log(reply.StringOf("values[i].projectKey") & "  " & reply.StringOf("values[i].projectName") & "  Service desk ID: " & reply.StringOf("values[i].id"))
        If reply.StringOfEquals("values[i].projectKey", projectKey, True) = True Then
            serviceDeskId = reply.StringOf("values[i].id")
            deskMatches = deskMatches + 1
        End If

        desksIndex = desksIndex + 1
    Loop
    desksStart = desksStart + desksCount
    desksMore = (reply.BoolOf("isLastPage") <> True)
    If (desksMore = True) And (desksCount = 0) Then
        Log("Pagination made no progress; stopping.")
        Return
    End If

Loop
If deskMatches <> 1 Then
    Log("Expected exactly one matching service desk.")
    Return
End If

http.SetUrlVar("serviceDeskId", serviceDeskId)
Dim typesStart As Int = 0
Dim typesMore As Boolean = True
Dim typesOffset As ChilkatStringBuilder
typesOffset.Initialize
Do While (typesMore = True)
    typesOffset.Clear
    typesOffset.AppendInt(typesStart)
    http.SetUrlVar("offset", typesOffset.GetAsString)
    url.SetString(baseUrl)
    url.Append("/rest/servicedeskapi/servicedesk/{$serviceDeskId}/requesttype?start={$offset}&limit=50")
    success = http.HttpNoBody("GET", url.GetAsString, resp)
    If resp.StatusCode = 0 Then
        Log("No HTTP response was received. Check connectivity and TLS settings.")
        Return
    End If

    If (success <> True) Or (resp.StatusCode < 200) Or (resp.StatusCode >= 300) Then
        Log("Request failed. HTTP " & resp.StatusCode)
        If resp.StatusCode = 429 Then
            Log("Rate limited. Retry-After: " & resp.GetHeaderField("Retry-After"))
        End If

        '  Inspect this response locally; it can contain private Jira data.
        Log(resp.BodyStr)
        Return
    End If

    success = reply.Load(resp.BodyStr)
    If success <> True Then
        Log("Expected a JSON object in the response.")
        Return
    End If

    If reply.JsonTypeOf("values") <> 4 Then
        Log("Expected an array: values")
        Return
    End If

    Dim typesCount As Int = reply.SizeOfArray("values")
    Dim typesIndex As Int = 0
    Do While (typesIndex < typesCount)
        reply.I = typesIndex
        Log("Request type: " & reply.StringOf("values[i].name") & "  ID: " & reply.StringOf("values[i].id"))
        If reply.StringOfEquals("values[i].name", requestTypeName, True) = True Then
            requestTypeId = reply.StringOf("values[i].id")
            typeMatches = typeMatches + 1
        End If

        typesIndex = typesIndex + 1
    Loop
    typesStart = typesStart + typesCount
    typesMore = (reply.BoolOf("isLastPage") <> True)
    If (typesMore = True) And (typesCount = 0) Then
        Log("Pagination made no progress; stopping.")
        Return
    End If

Loop
If typeMatches <> 1 Then
    Log("Expected exactly one matching request type.")
    Return
End If

http.SetUrlVar("requestTypeId", requestTypeId)
url.SetString(baseUrl)
url.Append("/rest/servicedeskapi/servicedesk/{$serviceDeskId}/requesttype/{$requestTypeId}/field")
success = http.HttpNoBody("GET", url.GetAsString, resp)
If resp.StatusCode = 0 Then
    Log("No HTTP response was received. Check connectivity and TLS settings.")
    Return
End If

If (success <> True) Or (resp.StatusCode < 200) Or (resp.StatusCode >= 300) Then
    Log("Request failed. HTTP " & resp.StatusCode)
    If resp.StatusCode = 429 Then
        Log("Rate limited. Retry-After: " & resp.GetHeaderField("Retry-After"))
    End If

    '  Inspect this response locally; it can contain private Jira data.
    Log(resp.BodyStr)
    Return
End If

success = reply.Load(resp.BodyStr)
If success <> True Then
    Log("Expected a JSON object in the response.")
    Return
End If

If reply.JsonTypeOf("requestTypeFields") <> 4 Then
    Log("Expected an array: requestTypeFields")
    Return
End If

Dim i As Int = 0
Do While (i < reply.SizeOfArray("requestTypeFields"))
    reply.I = i
    Log(reply.StringOf("requestTypeFields[i].fieldId") & "  " & reply.StringOf("requestTypeFields[i].name") & "  Required: " & reply.BoolOf("requestTypeFields[i].required"))
    i = i + 1
Loop
'  Includes validValues and field schemas for constructing the request.
Log(reply.Emit)
Log("Service desk ID: " & serviceDeskId & "  Request type ID: " & requestTypeId)