Sample code for 30+ languages & platforms
Xojo Plugin 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 Xojo Plugin Downloads

Xojo Plugin
Dim success As Boolean
success = False

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

Dim http As New Chilkat.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
baseUrl = "https://your-domain.atlassian.net"
http.Accept = "application/json"
Dim url As New Chilkat.StringBuilder
Dim resp As New Chilkat.HttpResponse
Dim reply As New Chilkat.JsonObject
Dim projectKey As String
projectKey = "SUPPORT"
Dim requestTypeName As String
requestTypeName = "General request"
Dim serviceDeskId As String
serviceDeskId = ""
Dim requestTypeId As String
requestTypeId = ""
Dim deskMatches As Int32
deskMatches = 0
Dim typeMatches As Int32
typeMatches = 0
Dim desksStart As Int32
desksStart = 0
Dim desksMore As Boolean
desksMore = True
Dim desksOffset As New Chilkat.StringBuilder
While (desksMore = True)
    desksOffset.Clear 
    success = desksOffset.AppendInt(desksStart)
    success = http.SetUrlVar("offset",desksOffset.GetAsString())
    success = url.SetString(baseUrl)
    success = url.Append("/rest/servicedeskapi/servicedesk?start={$offset}&limit=50")
    success = http.HttpNoBody("GET",url.GetAsString(),resp)
    If (resp.StatusCode = 0) Then
        System.DebugLog("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
        System.DebugLog("Request failed. HTTP " + Str(resp.StatusCode))
        If (resp.StatusCode = 429) Then
            System.DebugLog("Rate limited. Retry-After: " + resp.GetHeaderField("Retry-After"))
        End If

        //  Inspect this response locally; it can contain private Jira data.
        System.DebugLog(resp.BodyStr)
        Return
    End If

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

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

    Dim desksCount As Int32
    desksCount = reply.SizeOfArray("values")
    Dim desksIndex As Int32
    desksIndex = 0
    While (desksIndex < desksCount)
        reply.I = desksIndex
        System.DebugLog(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
    Wend
    desksStart = desksStart + desksCount
    desksMore = (reply.BoolOf("isLastPage") <> True)
    If ((desksMore = True) And (desksCount = 0)) Then
        System.DebugLog("Pagination made no progress; stopping.")
        Return
    End If

Wend
If (deskMatches <> 1) Then
    System.DebugLog("Expected exactly one matching service desk.")
    Return
End If

success = http.SetUrlVar("serviceDeskId",serviceDeskId)
Dim typesStart As Int32
typesStart = 0
Dim typesMore As Boolean
typesMore = True
Dim typesOffset As New Chilkat.StringBuilder
While (typesMore = True)
    typesOffset.Clear 
    success = typesOffset.AppendInt(typesStart)
    success = http.SetUrlVar("offset",typesOffset.GetAsString())
    success = url.SetString(baseUrl)
    success = url.Append("/rest/servicedeskapi/servicedesk/{$serviceDeskId}/requesttype?start={$offset}&limit=50")
    success = http.HttpNoBody("GET",url.GetAsString(),resp)
    If (resp.StatusCode = 0) Then
        System.DebugLog("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
        System.DebugLog("Request failed. HTTP " + Str(resp.StatusCode))
        If (resp.StatusCode = 429) Then
            System.DebugLog("Rate limited. Retry-After: " + resp.GetHeaderField("Retry-After"))
        End If

        //  Inspect this response locally; it can contain private Jira data.
        System.DebugLog(resp.BodyStr)
        Return
    End If

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

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

    Dim typesCount As Int32
    typesCount = reply.SizeOfArray("values")
    Dim typesIndex As Int32
    typesIndex = 0
    While (typesIndex < typesCount)
        reply.I = typesIndex
        System.DebugLog("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
    Wend
    typesStart = typesStart + typesCount
    typesMore = (reply.BoolOf("isLastPage") <> True)
    If ((typesMore = True) And (typesCount = 0)) Then
        System.DebugLog("Pagination made no progress; stopping.")
        Return
    End If

Wend
If (typeMatches <> 1) Then
    System.DebugLog("Expected exactly one matching request type.")
    Return
End If

success = http.SetUrlVar("requestTypeId",requestTypeId)
success = url.SetString(baseUrl)
success = url.Append("/rest/servicedeskapi/servicedesk/{$serviceDeskId}/requesttype/{$requestTypeId}/field")
success = http.HttpNoBody("GET",url.GetAsString(),resp)
If (resp.StatusCode = 0) Then
    System.DebugLog("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
    System.DebugLog("Request failed. HTTP " + Str(resp.StatusCode))
    If (resp.StatusCode = 429) Then
        System.DebugLog("Rate limited. Retry-After: " + resp.GetHeaderField("Retry-After"))
    End If

    //  Inspect this response locally; it can contain private Jira data.
    System.DebugLog(resp.BodyStr)
    Return
End If

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

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

Dim i As Int32
i = 0
While (i < reply.SizeOfArray("requestTypeFields"))
    reply.I = i
    System.DebugLog(reply.StringOf("requestTypeFields[i].fieldId") + "  " + reply.StringOf("requestTypeFields[i].name") + "  Required: " + Str(reply.BoolOf("requestTypeFields[i].required")))
    i = i + 1
Wend
//  Includes validValues and field schemas for constructing the request.
System.DebugLog(reply.Emit())
System.DebugLog("Service desk ID: " + serviceDeskId + "  Request type ID: " + requestTypeId)