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

Lazarus Pascal
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Http,
  Chilkat.StringBuilder,
  Chilkat.HttpResponse,
  Chilkat.JsonObject;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  http: THttp;
  baseUrl: string;
  url: TStringBuilder;
  resp: THttpResponse;
  reply: TJsonObject;
  issueTypeName: string;
  issueTypeId: string;
  matches: Integer;
  typesStart: Integer;
  typesMore: Boolean;
  typesOffset: TStringBuilder;
  typesCount: Integer;
  typesIndex: Integer;
  fieldsStart: Integer;
  fieldsMore: Boolean;
  fieldsOffset: TStringBuilder;
  fieldsCount: Integer;
  fieldsIndex: Integer;

begin
  success := False;

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

  http := THttp.Create;
  http.RequireSslCertVerify := True;
  http.BasicAuth := True;
  //  Read these credentials from private application configuration.
  http.Login := 'YOUR_ATLASSIAN_EMAIL';
  http.Password := 'YOUR_API_TOKEN';
  baseUrl := 'https://your-domain.atlassian.net';
  http.Accept := 'application/json';
  url := TStringBuilder.Create;
  resp := THttpResponse.Create;
  reply := TJsonObject.Create;
  http.SetUrlVar('projectKey','PROJECT');
  issueTypeName := 'Task';
  issueTypeId := '';
  matches := 0;
  typesStart := 0;
  typesMore := True;
  typesOffset := TStringBuilder.Create;
  while (typesMore = True) do
    begin
      typesOffset.Clear();
      typesOffset.AppendInt(typesStart);
      http.SetUrlVar('offset',typesOffset.GetAsString());
      url.SetString(baseUrl);
      url.Append('/rest/api/3/issue/createmeta/{$projectKey}/issuetypes?startAt={$offset}&maxResults=50');
      success := http.HttpNoBody('GET',url.GetAsString(),resp);
      if (resp.StatusCode = 0) then
        begin
          WriteLn('No HTTP response was received. Check connectivity and TLS settings.');
          Exit;
        end;
      if ((success <> True) or (resp.StatusCode < 200) or (resp.StatusCode >= 300)) then
        begin
          WriteLn('Request failed. HTTP ' + resp.StatusCode);
          if (resp.StatusCode = 429) then
            begin
              WriteLn('Rate limited. Retry-After: ' + resp.GetHeaderField('Retry-After'));
            end;
          //  Inspect this response locally; it can contain private Jira data.
          WriteLn(resp.BodyStr);
          Exit;
        end;
      success := reply.Load(resp.BodyStr);
      if (success <> True) then
        begin
          WriteLn('Expected a JSON object in the response.');
          Exit;
        end;
      if (reply.JsonTypeOf('issueTypes') <> 4) then
        begin
          WriteLn('Expected an array: issueTypes');
          Exit;
        end;
      typesCount := reply.SizeOfArray('issueTypes');
      typesIndex := 0;
      while (typesIndex < typesCount) do
        begin
          reply.I := typesIndex;
          WriteLn(reply.StringOf('issueTypes[i].name') + '  ID: ' + reply.StringOf('issueTypes[i].id'));
          if (reply.StringOfEquals('issueTypes[i].name',issueTypeName,True) = True) then
            begin
              issueTypeId := reply.StringOf('issueTypes[i].id');
              matches := matches + 1;
            end;
          typesIndex := typesIndex + 1;
        end;

      typesStart := typesStart + typesCount;
      typesMore := (typesStart < reply.IntOf('total'));
      if ((typesMore = True) and (typesCount = 0)) then
        begin
          WriteLn('Pagination made no progress; stopping.');
          Exit;
        end;
    end;

  if (matches <> 1) then
    begin
      WriteLn('Select one unambiguous issue type from the returned list.');
      Exit;
    end;
  http.SetUrlVar('issueTypeId',issueTypeId);
  fieldsStart := 0;
  fieldsMore := True;
  fieldsOffset := TStringBuilder.Create;
  while (fieldsMore = True) do
    begin
      fieldsOffset.Clear();
      fieldsOffset.AppendInt(fieldsStart);
      http.SetUrlVar('offset',fieldsOffset.GetAsString());
      url.SetString(baseUrl);
      url.Append('/rest/api/3/issue/createmeta/{$projectKey}/issuetypes/{$issueTypeId}?startAt={$offset}&maxResults=50');
      success := http.HttpNoBody('GET',url.GetAsString(),resp);
      if (resp.StatusCode = 0) then
        begin
          WriteLn('No HTTP response was received. Check connectivity and TLS settings.');
          Exit;
        end;
      if ((success <> True) or (resp.StatusCode < 200) or (resp.StatusCode >= 300)) then
        begin
          WriteLn('Request failed. HTTP ' + resp.StatusCode);
          if (resp.StatusCode = 429) then
            begin
              WriteLn('Rate limited. Retry-After: ' + resp.GetHeaderField('Retry-After'));
            end;
          //  Inspect this response locally; it can contain private Jira data.
          WriteLn(resp.BodyStr);
          Exit;
        end;
      success := reply.Load(resp.BodyStr);
      if (success <> True) then
        begin
          WriteLn('Expected a JSON object in the response.');
          Exit;
        end;
      if (reply.JsonTypeOf('fields') <> 4) then
        begin
          WriteLn('Expected an array: fields');
          Exit;
        end;
      //  Full metadata includes field schemas and allowed values.
      WriteLn(reply.Emit());
      fieldsCount := reply.SizeOfArray('fields');
      fieldsIndex := 0;
      while (fieldsIndex < fieldsCount) do
        begin
          reply.I := fieldsIndex;
          WriteLn(reply.StringOf('fields[i].fieldId') + '  ' + reply.StringOf('fields[i].name') + '  Required: ' + reply.BoolOf('fields[i].required'));
          fieldsIndex := fieldsIndex + 1;
        end;

      fieldsStart := fieldsStart + fieldsCount;
      fieldsMore := (fieldsStart < reply.IntOf('total'));
      if ((fieldsMore = True) and (fieldsCount = 0)) then
        begin
          WriteLn('Pagination made no progress; stopping.');
          Exit;
        end;
    end;



  http.Free;
  url.Free;
  resp.Free;
  reply.Free;
  typesOffset.Free;
  fieldsOffset.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.