PaddyP has asked for the wisdom of the Perl Monks concerning the following question:

Hello brothers and sisters of PerlMonks,

I have a problem with a Perl script to access Atlassian JIRA via a REST-API. The error message reads:
"Unable to POST /jira/rest/api/latest/search/: 500 Can't connect to my +site.com:443 (Bad file descriptor) Can't connect to mysite.com:443 (B +ad file descriptor) Bad file descriptor at C:/MyPrograms/Strawberry/p +erl/vendor/lib/LWP/Protocol/http.pm line 50, <STDIN> line 2. (for request: {"startAt":0,"maxResults":500,"fields":["*navigable"],"j +ql":"project = xxxx AND Status = Open"}) at jira_test_rest-api.pl lin +e 48."
Do you have any idea what I have to do to correct this fault? I think it might be a certificate problem but I have no idea since I'm a complete newbie with Perl...

If I use CURL to place this request, it works without problems...

Thanks and best regards,
PaddyP

Replies are listed 'Best First'.
Re: Problem with a call to REST API
by Corion (Patriarch) on Aug 10, 2023 at 07:43 UTC

    If you have a working Curl command, you can convert it to the appropriate LWP::UserAgent or HTTP::Tiny code using my Curl to Perl translator.

    My suspicion is that the difference between Perl and Curl is that Curl picks up a HTTP proxy setting from the environment but Perl does not, or the other way around. Inspect your environment for the environment variables HTTP_PROXY and HTTPS_PROXY. Alternatively, talk to your system administrator what settings are necessary to connect to the outside world.

Re: Problem with a call to REST API
by karlgoethebier (Abbot) on Aug 09, 2023 at 19:20 UTC

    JIRA::REST looks quite good:

    use JIRA::REST; my $jira = JIRA::REST->new({ url => 'https://jira.example.net', username => 'myuser', password => 'mypass', }); # File a bug my $issue = $jira->POST('/issue', undef, { fields => { project => { key => 'PRJ' }, issuetype => { name => 'Bug' }, summary => 'Cannot login', description => 'Bla bla bla', }, }); # Get issue $issue = $jira->GET("/issue/TST-101"); # Iterate on issues my $search = $jira->POST('/search', undef, { jql => 'project = "TST" and status = "open"', startAt => 0, maxResults => 16, fields => [ qw/summary status assignee/ ], });

    Maybe there is no need to torture yourself with LWP or Curl.

    «The Crux of the Biscuit is the Apostrophe»

Re: Problem with a call to REST API
by choroba (Cardinal) on Aug 09, 2023 at 18:18 UTC
    Just guessing: Have you installed LWP::Protocol::https?

    Also, are you aware there are several JIRA related modules on CPAN?

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: Problem with a call to REST API
by Anonymous Monk on Aug 10, 2023 at 23:21 UTC

    You need to share your code. What happens when you run this:

    use strict; use warnings; use LWP::UserAgent; use HTTP::Request; my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new( GET => 'https://mysite.com:443/'); my $response = $ua->request($req); print $response->code."\n";

      Hi,

      I get a "500" as result...

      Cheers,
      PaddyP