Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to use REST API in PERL while passing JQL

saravanan subramanian
Contributor
November 26, 2024

Code:



use REST::Client; use JSON qw//; use MIME::Base64; use Data::Dumper; use LWP::UserAgent; use JIRA::Client; `export PERL_LWP_SSL_VERIFY_HOSTNAME=0`; my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 }, protocols_allowed => ['https'], ); my $username = 'saravanan.subramanian@cmegroup.com'; my $password = 'AXXX'; my $base_url = 'https://cmegroup-sandbox-461.atlassian.net'; #my $jira_rest = JIRA::Client::Automated->new('https://cmegroup-sandbox-461.atlassian.net', $user, $passwd); my $jira_rest = REST::Client->new(); $jira_rest->addHeader('Content-Type','application/json'); $jira_rest->addHeader('Authorization','Basic'.encode_base64("$username:$password")); $jira_rest->GET('https://cmegroup-sandbox-461.atlassian.net/rest/api/3/search?jql=project=vmt'); print Dumper($jira_rest); print $jira_rest->responseCode();

 

'

 

 

 

 

I get 400 error when i am rying to run the code below. How ever the I have access to project


when i removed the single quotes in the link below I am able to see the results returned in the UI.  Please let me know how to fix it




Error:


 

_rc' => '400', '_content' => '{"errorMessages":["The value \'vmt\' does not exist for the field \'project\'."],"warningMessages":[]}', '_msg' => 'Bad Request', '_protocol' => 'HTTP/1.1', '_request' => bless( { '_uri' => bless( do{\(my $o = 'https://cmegroup-sandbox-461.atlassian.net/rest/api/3/search?jql=project=vmt')}, 'URI::https' ), '_headers' => bless( {

 

 

URL

https://cmegroup-sandbox-461.atlassian.net/rest/api/3/search?jql=project=vmt'

1 answer

1 accepted

1 vote
Answer accepted
Tuncay Senturk
Community Champion
November 27, 2024

Hi @saravanan subramanian 

Your Authorization header is missing a space after 'Basic', and the encode_base64 function adds a newline character by default, which can corrupt the header. Have you tried adding a space as below?

$jira_rest->addHeader('Authorization', 'Basic '.encode_base64("$username:$password", ''));

 

saravanan subramanian
Contributor
November 27, 2024

sure will try and let you know

saravanan subramanian
Contributor
November 27, 2024

silly me - it worked .  Thank you very much

Tuncay Senturk
Community Champion
November 27, 2024

:) glad it worked

Like saravanan subramanian likes this

Suggest an answer

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

Atlassian Community Events