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

AutoIt
Local $bSuccess = False

;  Assumes Chilkat is unlocked. See Global Unlock Sample.

$oHttp = ObjCreate("Chilkat.Http")
$oHttp.RequireSslCertVerify = True
$oHttp.BasicAuth = True
;  Read these credentials from private application configuration.
$oHttp.Login = "YOUR_ATLASSIAN_EMAIL"
$oHttp.Password = "YOUR_API_TOKEN"
Local $sBaseUrl = "https://your-domain.atlassian.net"
$oHttp.Accept = "application/json"
$oUrl = ObjCreate("Chilkat.StringBuilder")
$oResp = ObjCreate("Chilkat.HttpResponse")
$oReply = ObjCreate("Chilkat.JsonObject")
Local $sProjectKey = "SUPPORT"
Local $sRequestTypeName = "General request"
Local $serviceDeskId = ""
Local $sRequestTypeId = ""
Local $iDeskMatches = 0
Local $iTypeMatches = 0
Local $iDesksStart = 0
Local $bDesksMore = True
$oDesksOffset = ObjCreate("Chilkat.StringBuilder")
While ($bDesksMore = True)
    $oDesksOffset.Clear 
    $oDesksOffset.AppendInt($iDesksStart)
    $oHttp.SetUrlVar("offset",$oDesksOffset.GetAsString())
    $oUrl.SetString($sBaseUrl)
    $oUrl.Append("/rest/servicedeskapi/servicedesk?start={$offset}&limit=50")
    $bSuccess = $oHttp.HttpNoBody("GET",$oUrl.GetAsString(),$oResp)
    If ($oResp.StatusCode = 0) Then
        ConsoleWrite("No HTTP response was received. Check connectivity and TLS settings." & @CRLF)
        Exit
    EndIf

    If (($bSuccess <> True) Or ($oResp.StatusCode < 200) Or ($oResp.StatusCode >= 300)) Then
        ConsoleWrite("Request failed. HTTP " & $oResp.StatusCode & @CRLF)
        If ($oResp.StatusCode = 429) Then
            ConsoleWrite("Rate limited. Retry-After: " & $oResp.GetHeaderField("Retry-After") & @CRLF)
        EndIf

        ;  Inspect this response locally; it can contain private Jira data.
        ConsoleWrite($oResp.BodyStr & @CRLF)
        Exit
    EndIf

    $bSuccess = $oReply.Load($oResp.BodyStr)
    If ($bSuccess <> True) Then
        ConsoleWrite("Expected a JSON object in the response." & @CRLF)
        Exit
    EndIf

    If ($oReply.JsonTypeOf("values") <> 4) Then
        ConsoleWrite("Expected an array: values" & @CRLF)
        Exit
    EndIf

Local $iDesksCount = $oReply.SizeOfArray("values")
Local $iDesksIndex = 0
    While ($iDesksIndex < $iDesksCount)
        $oReply.I = $iDesksIndex
        ConsoleWrite($oReply.StringOf("values[i].projectKey") & "  " & $oReply.StringOf("values[i].projectName") & "  Service desk ID: " & $oReply.StringOf("values[i].id") & @CRLF)
        If ($oReply.StringOfEquals("values[i].projectKey",$sProjectKey,True) = True) Then
            $serviceDeskId = $oReply.StringOf("values[i].id")
            $iDeskMatches = $iDeskMatches + 1
        EndIf

        $iDesksIndex = $iDesksIndex + 1
    Wend
    $iDesksStart = $iDesksStart + $iDesksCount
    $bDesksMore = ($oReply.BoolOf("isLastPage") <> True)
    If (($bDesksMore = True) And ($iDesksCount = 0)) Then
        ConsoleWrite("Pagination made no progress; stopping." & @CRLF)
        Exit
    EndIf

Wend
If ($iDeskMatches <> 1) Then
    ConsoleWrite("Expected exactly one matching service desk." & @CRLF)
    Exit
EndIf

$oHttp.SetUrlVar("serviceDeskId",$serviceDeskId)
Local $iTypesStart = 0
Local $bTypesMore = True
$oTypesOffset = ObjCreate("Chilkat.StringBuilder")
While ($bTypesMore = True)
    $oTypesOffset.Clear 
    $oTypesOffset.AppendInt($iTypesStart)
    $oHttp.SetUrlVar("offset",$oTypesOffset.GetAsString())
    $oUrl.SetString($sBaseUrl)
    $oUrl.Append("/rest/servicedeskapi/servicedesk/{$serviceDeskId}/requesttype?start={$offset}&limit=50")
    $bSuccess = $oHttp.HttpNoBody("GET",$oUrl.GetAsString(),$oResp)
    If ($oResp.StatusCode = 0) Then
        ConsoleWrite("No HTTP response was received. Check connectivity and TLS settings." & @CRLF)
        Exit
    EndIf

    If (($bSuccess <> True) Or ($oResp.StatusCode < 200) Or ($oResp.StatusCode >= 300)) Then
        ConsoleWrite("Request failed. HTTP " & $oResp.StatusCode & @CRLF)
        If ($oResp.StatusCode = 429) Then
            ConsoleWrite("Rate limited. Retry-After: " & $oResp.GetHeaderField("Retry-After") & @CRLF)
        EndIf

        ;  Inspect this response locally; it can contain private Jira data.
        ConsoleWrite($oResp.BodyStr & @CRLF)
        Exit
    EndIf

    $bSuccess = $oReply.Load($oResp.BodyStr)
    If ($bSuccess <> True) Then
        ConsoleWrite("Expected a JSON object in the response." & @CRLF)
        Exit
    EndIf

    If ($oReply.JsonTypeOf("values") <> 4) Then
        ConsoleWrite("Expected an array: values" & @CRLF)
        Exit
    EndIf

Local $iTypesCount = $oReply.SizeOfArray("values")
Local $iTypesIndex = 0
    While ($iTypesIndex < $iTypesCount)
        $oReply.I = $iTypesIndex
        ConsoleWrite("Request type: " & $oReply.StringOf("values[i].name") & "  ID: " & $oReply.StringOf("values[i].id") & @CRLF)
        If ($oReply.StringOfEquals("values[i].name",$sRequestTypeName,True) = True) Then
            $sRequestTypeId = $oReply.StringOf("values[i].id")
            $iTypeMatches = $iTypeMatches + 1
        EndIf

        $iTypesIndex = $iTypesIndex + 1
    Wend
    $iTypesStart = $iTypesStart + $iTypesCount
    $bTypesMore = ($oReply.BoolOf("isLastPage") <> True)
    If (($bTypesMore = True) And ($iTypesCount = 0)) Then
        ConsoleWrite("Pagination made no progress; stopping." & @CRLF)
        Exit
    EndIf

Wend
If ($iTypeMatches <> 1) Then
    ConsoleWrite("Expected exactly one matching request type." & @CRLF)
    Exit
EndIf

$oHttp.SetUrlVar("requestTypeId",$sRequestTypeId)
$oUrl.SetString($sBaseUrl)
$oUrl.Append("/rest/servicedeskapi/servicedesk/{$serviceDeskId}/requesttype/{$requestTypeId}/field")
$bSuccess = $oHttp.HttpNoBody("GET",$oUrl.GetAsString(),$oResp)
If ($oResp.StatusCode = 0) Then
    ConsoleWrite("No HTTP response was received. Check connectivity and TLS settings." & @CRLF)
    Exit
EndIf

If (($bSuccess <> True) Or ($oResp.StatusCode < 200) Or ($oResp.StatusCode >= 300)) Then
    ConsoleWrite("Request failed. HTTP " & $oResp.StatusCode & @CRLF)
    If ($oResp.StatusCode = 429) Then
        ConsoleWrite("Rate limited. Retry-After: " & $oResp.GetHeaderField("Retry-After") & @CRLF)
    EndIf

    ;  Inspect this response locally; it can contain private Jira data.
    ConsoleWrite($oResp.BodyStr & @CRLF)
    Exit
EndIf

$bSuccess = $oReply.Load($oResp.BodyStr)
If ($bSuccess <> True) Then
    ConsoleWrite("Expected a JSON object in the response." & @CRLF)
    Exit
EndIf

If ($oReply.JsonTypeOf("requestTypeFields") <> 4) Then
    ConsoleWrite("Expected an array: requestTypeFields" & @CRLF)
    Exit
EndIf

Local $i = 0
While ($i < $oReply.SizeOfArray("requestTypeFields"))
    $oReply.I = $i
    ConsoleWrite($oReply.StringOf("requestTypeFields[i].fieldId") & "  " & $oReply.StringOf("requestTypeFields[i].name") & "  Required: " & $oReply.BoolOf("requestTypeFields[i].required") & @CRLF)
    $i = $i + 1
Wend
;  Includes validValues and field schemas for constructing the request.
ConsoleWrite($oReply.Emit() & @CRLF)
ConsoleWrite("Service desk ID: " & $serviceDeskId & "  Request type ID: " & $sRequestTypeId & @CRLF)