Connect to JIRA from Delphi

David KLIMAS July 7, 2023

Hello Community,

I would like to connect to JIRA platform to extract all tickets for audit and control purposes: tickets open, tickets pending review, tickets closed, etc.

I try to connect to JIRA with Rest API

var

   client: TRESTClient;
   request: TRESTRequest;
   signature: string;
   Base64: TBase64Encoding;
   Str1: String;
begin
   client := TRESTClient.Create(nil);
   try
      client.BaseURL := 'https://****.atlassian.net:****';
      request := TRESTRequest.Create(nil);
      request.Client := client;
      try
         request.Method := rmGet;
         request.Resource := '/rest/servicedeskapi/request/*****/comment';
         signature := 'username:password';
         Base64 := TBase64Encoding.Create(0);
         signature := 'Basic ' + Base64.Encode(signature);
         request.Params.AddItem('Authorization', signature, TRESTRequestParameterKind.pkHTTPHEADER, [poDoNotEncode]);
request.Execute;

 

Unfortunatly, i get an error in return :

ERROR - {"message":"Client must be authenticated to access this resource.","status-code":401}

Any idea how to solve this ?

4 answers

2 accepted

0 votes
Answer accepted
David KLIMAS July 13, 2023

Hi @abhishek_sharma03 I was able to establish a connection with API Token. Thank you.

abhishek_sharma03
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 13, 2023

Awesome @David KLIMAS Could you please accept the other answer as well on this post !!

BR

Abhishek

0 votes
Answer accepted
David KLIMAS July 7, 2023

I also tried to use ApiToken to connect but the result is the same

signature := 'email:' + ApiToken;
request.Params.AddItem('user', signature, TRESTRequestParameterKind.pkHTTPHEADER, [poDoNotEncode]);

abhishek_sharma03
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 8, 2023

Hi @David KLIMAS - Through which tool are you trying to connect Jira via API ? If you need to download all the tickets why don't you download them in excel through filter

David KLIMAS July 8, 2023

With Delphi. There is some processing to be done, Excel would require manuel actions and add additional steps which I prefer to avoid

abhishek_sharma03
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 10, 2023

Hi @David KLIMAS - How are you authenticating ?

BR

Abhishek

abhishek_sharma03
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 10, 2023
David KLIMAS July 10, 2023

Hi @abhishek_sharma03 

I have tried this :

         signature := 'username:password';
         signature := 'Basic ' + Base64.Encode(signature);

and this 

         signature := 'username:api_token';

I did not Base64 encode the second option. I have to try. I did understand that the "username:password" is not used any more ? 

abhishek_sharma03
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 10, 2023

No the basic authentication using username and password is not used anymore. Please refer the article shared.

David KLIMAS July 10, 2023

I will test with Api token and provide feedback. Thanks

0 votes
Wohlmuth Andreas
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 2, 2024

HI,

need to change to user:PAT.

 

this is working for me:

 


client := TRESTClient.Create(nil);

client.Accept := 'application/json';

client.BaseURL := JHost;


request := TRESTRequest.Create(nil);

request.Client := client;

request.Method := rmGet;
request.Resource := '/rest/api/2/search?jql=assignee%20in%20(currentUser())%20AND%20status%20not%20in%20(Done)&fields=key,description,summary,parent,issuetype';
signature := 'myuser:'+ PAT;
Base64 := TBase64Encoding.Create(0);
signature := 'Basic ' + Base64.Encode(signature);
request.Params.AddItem('Authorization', signature, TRESTRequestParameterKind.pkHTTPHEADER, [poDoNotEncode]);

 

try
request.Execute;

finally

end;

str1:= request.Response.Headers.Text;

 

 

0 votes
Andreas Wohlmuth November 17, 2023

Hi all,

I will use this topic also to discuss issue with html 404 error.

I want to export/update my Jira Task

 

Within the GUI i am using this URL:   

request.Resource := '/jira/secure/RapidBoard.jspa?rapidView=5207&projectKey=TEST';

signature := 'sometestuser:PAT_test_token';

request.Params.AddItem('user', signature, TRESTRequestParameterKind.pkHTTPHEADER, [poDoNotEncode]);

 

Also I am wondering about no error with not existing username at first.

 

Can I use GUI URL for request.Resource parameter?

Is the signature syntax correct for PAT authenification?

 

thanks for help in advance

Andreas

Andreas Wohlmuth December 21, 2023

Hi all,

for me it's working now with:

client.BaseURL := 'https://myjiraserver.com';

request.Resource := '/jira/rest/api/2/issue/ISSUENAME-7571';
signature := 'Bearer <PAT>';

request.Params.AddItem('Authorization', signature, TRESTRequestParameterKind.pkHTTPHEADER, [poDoNotEncode]);

 

Regards

Andreas

David KLIMAS December 21, 2023

Thanks Andreas

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events