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

Update: I figured it out and got a 200 OK response. I added the following lines. my $auth_token = "code"; $ua->default_header( "Authorization" => "Bearer $auth_token"); Guys, It's my first time I will attempt to use perl to access an API for information. I was looking around and found this code which I kind of modified for my use. The issue is that I am unsure where to include the token key required to make the request. I'm not sure if I need to include it in the http request itself, but if so, how? The response I'm currently getting is 400 Bad Request. I appreciate any help. The credentials have been ommited for security reasons.
#!/usr/bin/perl -w use strict; use warnings; use LWP::UserAgent; require HTTP::Cookies; my $ua = new LWP::UserAgent; my $cookie_jar = HTTP::Cookies->new( file => 'cookies_lwp.txt', autosa +ve => 1, ignore_discard => 1 ); # A cookie file is needed to store th +e security keys. $ua->cookie_jar($cookie_jar); $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0; $ua->default_header( "Accept" =>"application/json" ); $ua->default_header( "Content-Type" => "application/json"); my $netloc="host"; my $realm="realm name"; my $user="username"; my $pass="password"; $ua->credentials( $netloc, $realm, $user, $pass); $ua->ssl_opts( verify_hostname => 0, SSL_verify_mode => 0x00); my $req = new HTTP::Request('GET','https://host/api/v2/devices/00:04:5 +6:22:51:32/performance/?start_time=2022-02-15T10:00:00&stop_time=2022 +-02-16T10:00:00'); my $res = $ua->request($req); print $res->code, "\n"; print $res->message; use Data::Dumper;

Replies are listed 'Best First'.
Re: Perl and API
by talexb (Chancellor) on Feb 21, 2022 at 05:34 UTC

    It looks like you've updated your post -- but we don't know what you updated. It's also unclear whether you've solved your problem or not (you could add SOLVED to the title if that's the case).

    Tell us where you are, and we'll see if we can help you.

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.