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

Delphi DLL
var
success: Boolean;
http: HCkHttp;
baseUrl: PWideChar;
url: HCkStringBuilder;
resp: HCkHttpResponse;
reply: HCkJsonObject;
projectKey: PWideChar;
requestTypeName: PWideChar;
serviceDeskId: PWideChar;
requestTypeId: PWideChar;
deskMatches: Integer;
typeMatches: Integer;
desksStart: Integer;
desksMore: Boolean;
desksOffset: HCkStringBuilder;
desksCount: Integer;
desksIndex: Integer;
typesStart: Integer;
typesMore: Boolean;
typesOffset: HCkStringBuilder;
typesCount: Integer;
typesIndex: Integer;
i: Integer;

begin
success := False;

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

http := CkHttp_Create();
CkHttp_putRequireSslCertVerify(http,True);
CkHttp_putBasicAuth(http,True);
//  Read these credentials from private application configuration.
CkHttp_putLogin(http,'YOUR_ATLASSIAN_EMAIL');
CkHttp_putPassword(http,'YOUR_API_TOKEN');
baseUrl := 'https://your-domain.atlassian.net';
CkHttp_putAccept(http,'application/json');
url := CkStringBuilder_Create();
resp := CkHttpResponse_Create();
reply := CkJsonObject_Create();
projectKey := 'SUPPORT';
requestTypeName := 'General request';
serviceDeskId := '';
requestTypeId := '';
deskMatches := 0;
typeMatches := 0;
desksStart := 0;
desksMore := True;
desksOffset := CkStringBuilder_Create();
while (desksMore = True) do
  begin
    CkStringBuilder_Clear(desksOffset);
    CkStringBuilder_AppendInt(desksOffset,desksStart);
    CkHttp_SetUrlVar(http,'offset',CkStringBuilder__getAsString(desksOffset));
    CkStringBuilder_SetString(url,baseUrl);
    CkStringBuilder_Append(url,'/rest/servicedeskapi/servicedesk?start={$offset}&limit=50');
    success := CkHttp_HttpNoBody(http,'GET',CkStringBuilder__getAsString(url),resp);
    if (CkHttpResponse_getStatusCode(resp) = 0) then
      begin
        Memo1.Lines.Add('No HTTP response was received. Check connectivity and TLS settings.');
        Exit;
      end;
    if ((success <> True) or (CkHttpResponse_getStatusCode(resp) < 200) or (CkHttpResponse_getStatusCode(resp) >= 300)) then
      begin
        Memo1.Lines.Add('Request failed. HTTP ' + IntToStr(CkHttpResponse_getStatusCode(resp)));
        if (CkHttpResponse_getStatusCode(resp) = 429) then
          begin
            Memo1.Lines.Add('Rate limited. Retry-After: ' + CkHttpResponse__getHeaderField(resp,'Retry-After'));
          end;
        //  Inspect this response locally; it can contain private Jira data.
        Memo1.Lines.Add(CkHttpResponse__bodyStr(resp));
        Exit;
      end;
    success := CkJsonObject_Load(reply,CkHttpResponse__bodyStr(resp));
    if (success <> True) then
      begin
        Memo1.Lines.Add('Expected a JSON object in the response.');
        Exit;
      end;
    if (CkJsonObject_JsonTypeOf(reply,'values') <> 4) then
      begin
        Memo1.Lines.Add('Expected an array: values');
        Exit;
      end;
    desksCount := CkJsonObject_SizeOfArray(reply,'values');
    desksIndex := 0;
    while (desksIndex < desksCount) do
      begin
        CkJsonObject_putI(reply,desksIndex);
        Memo1.Lines.Add(CkJsonObject__stringOf(reply,'values[i].projectKey') + '  ' + CkJsonObject__stringOf(reply,'values[i].projectName') + '  Service desk ID: '
             + CkJsonObject__stringOf(reply,'values[i].id'));
        if (CkJsonObject_StringOfEquals(reply,'values[i].projectKey',projectKey,True) = True) then
          begin
            serviceDeskId := CkJsonObject__stringOf(reply,'values[i].id');
            deskMatches := deskMatches + 1;
          end;
        desksIndex := desksIndex + 1;
      end;

    desksStart := desksStart + desksCount;
    desksMore := (CkJsonObject_BoolOf(reply,'isLastPage') <> True);
    if ((desksMore = True) and (desksCount = 0)) then
      begin
        Memo1.Lines.Add('Pagination made no progress; stopping.');
        Exit;
      end;
  end;

if (deskMatches <> 1) then
  begin
    Memo1.Lines.Add('Expected exactly one matching service desk.');
    Exit;
  end;
CkHttp_SetUrlVar(http,'serviceDeskId',serviceDeskId);
typesStart := 0;
typesMore := True;
typesOffset := CkStringBuilder_Create();
while (typesMore = True) do
  begin
    CkStringBuilder_Clear(typesOffset);
    CkStringBuilder_AppendInt(typesOffset,typesStart);
    CkHttp_SetUrlVar(http,'offset',CkStringBuilder__getAsString(typesOffset));
    CkStringBuilder_SetString(url,baseUrl);
    CkStringBuilder_Append(url,'/rest/servicedeskapi/servicedesk/{$serviceDeskId}/requesttype?start={$offset}&limit=50');
    success := CkHttp_HttpNoBody(http,'GET',CkStringBuilder__getAsString(url),resp);
    if (CkHttpResponse_getStatusCode(resp) = 0) then
      begin
        Memo1.Lines.Add('No HTTP response was received. Check connectivity and TLS settings.');
        Exit;
      end;
    if ((success <> True) or (CkHttpResponse_getStatusCode(resp) < 200) or (CkHttpResponse_getStatusCode(resp) >= 300)) then
      begin
        Memo1.Lines.Add('Request failed. HTTP ' + IntToStr(CkHttpResponse_getStatusCode(resp)));
        if (CkHttpResponse_getStatusCode(resp) = 429) then
          begin
            Memo1.Lines.Add('Rate limited. Retry-After: ' + CkHttpResponse__getHeaderField(resp,'Retry-After'));
          end;
        //  Inspect this response locally; it can contain private Jira data.
        Memo1.Lines.Add(CkHttpResponse__bodyStr(resp));
        Exit;
      end;
    success := CkJsonObject_Load(reply,CkHttpResponse__bodyStr(resp));
    if (success <> True) then
      begin
        Memo1.Lines.Add('Expected a JSON object in the response.');
        Exit;
      end;
    if (CkJsonObject_JsonTypeOf(reply,'values') <> 4) then
      begin
        Memo1.Lines.Add('Expected an array: values');
        Exit;
      end;
    typesCount := CkJsonObject_SizeOfArray(reply,'values');
    typesIndex := 0;
    while (typesIndex < typesCount) do
      begin
        CkJsonObject_putI(reply,typesIndex);
        Memo1.Lines.Add('Request type: ' + CkJsonObject__stringOf(reply,'values[i].name') + '  ID: ' + CkJsonObject__stringOf(reply,'values[i].id'));
        if (CkJsonObject_StringOfEquals(reply,'values[i].name',requestTypeName,True) = True) then
          begin
            requestTypeId := CkJsonObject__stringOf(reply,'values[i].id');
            typeMatches := typeMatches + 1;
          end;
        typesIndex := typesIndex + 1;
      end;

    typesStart := typesStart + typesCount;
    typesMore := (CkJsonObject_BoolOf(reply,'isLastPage') <> True);
    if ((typesMore = True) and (typesCount = 0)) then
      begin
        Memo1.Lines.Add('Pagination made no progress; stopping.');
        Exit;
      end;
  end;

if (typeMatches <> 1) then
  begin
    Memo1.Lines.Add('Expected exactly one matching request type.');
    Exit;
  end;
CkHttp_SetUrlVar(http,'requestTypeId',requestTypeId);
CkStringBuilder_SetString(url,baseUrl);
CkStringBuilder_Append(url,'/rest/servicedeskapi/servicedesk/{$serviceDeskId}/requesttype/{$requestTypeId}/field');
success := CkHttp_HttpNoBody(http,'GET',CkStringBuilder__getAsString(url),resp);
if (CkHttpResponse_getStatusCode(resp) = 0) then
  begin
    Memo1.Lines.Add('No HTTP response was received. Check connectivity and TLS settings.');
    Exit;
  end;
if ((success <> True) or (CkHttpResponse_getStatusCode(resp) < 200) or (CkHttpResponse_getStatusCode(resp) >= 300)) then
  begin
    Memo1.Lines.Add('Request failed. HTTP ' + IntToStr(CkHttpResponse_getStatusCode(resp)));
    if (CkHttpResponse_getStatusCode(resp) = 429) then
      begin
        Memo1.Lines.Add('Rate limited. Retry-After: ' + CkHttpResponse__getHeaderField(resp,'Retry-After'));
      end;
    //  Inspect this response locally; it can contain private Jira data.
    Memo1.Lines.Add(CkHttpResponse__bodyStr(resp));
    Exit;
  end;
success := CkJsonObject_Load(reply,CkHttpResponse__bodyStr(resp));
if (success <> True) then
  begin
    Memo1.Lines.Add('Expected a JSON object in the response.');
    Exit;
  end;
if (CkJsonObject_JsonTypeOf(reply,'requestTypeFields') <> 4) then
  begin
    Memo1.Lines.Add('Expected an array: requestTypeFields');
    Exit;
  end;
i := 0;
while (i < CkJsonObject_SizeOfArray(reply,'requestTypeFields')) do
  begin
    CkJsonObject_putI(reply,i);
    Memo1.Lines.Add(CkJsonObject__stringOf(reply,'requestTypeFields[i].fieldId') + '  ' + CkJsonObject__stringOf(reply,'requestTypeFields[i].name') + '  Required: '
         + IntToStr(Ord(CkJsonObject_BoolOf(reply,'requestTypeFields[i].required'))));
    i := i + 1;
  end;

//  Includes validValues and field schemas for constructing the request.
Memo1.Lines.Add(CkJsonObject__emit(reply));
Memo1.Lines.Add('Service desk ID: ' + serviceDeskId + '  Request type ID: ' + requestTypeId);

CkHttp_Dispose(http);
CkStringBuilder_Dispose(url);
CkHttpResponse_Dispose(resp);
CkJsonObject_Dispose(reply);
CkStringBuilder_Dispose(desksOffset);
CkStringBuilder_Dispose(typesOffset);