in reply to Re^3: 500 Not a SCALAR reference
in thread 500 Not a SCALAR reference

i have updated it with strict and warning also added a clear header structure. you can see the output and the error i get

Replies are listed 'Best First'.
Re^5: 500 Not a SCALAR reference
by poj (Abbot) on Jan 08, 2019 at 07:57 UTC

    See post

    #!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use Digest::SHA qw(hmac_sha256_hex); use Time::HiRes qw(gettimeofday); use URI; use Encode; my $nonce = int (gettimeofday * 1000); my $url = "https://localbitcoins.com"; my $api_endpoint = "/api/merchant/new_invoice/"; my $hmac_key = "sdfsdfdsfdsfy"; my $hmac_secret = "sdfdsfdsf"; my %params = ( currency => 'USD', amount => '500', description => 'HEY', internal => '0', ); my $uri = URI->new(); $uri->query_form( \%params ); my $post_params_urlencoded = $uri->as_string; $post_params_urlencoded =~ s/^[?]//; my $message = encode('utf8',$nonce.$hmac_key.$api_endpoint.$post_param +s_urlencoded); my $signature = uc hmac_sha256_hex($message, $hmac_secret); my %headers = ( 'Apiauth-Key' => $hmac_key, 'Apiauth-Nonce' => $nonce, 'Apiauth-Signature' => $signature, ); my $ua = LWP::UserAgent->new; $ua->agent("MyApp/0.1 "); # remove exit to send request $ua->add_handler( request_prepare => sub { print "Request:\n".$_[0]->as_string; exit }); my $res = $ua->post( $url.$api_endpoint, %headers, Content => $post_pa +rams_urlencoded ); print "Content-type: text/plain\n\n"; if ($res->is_success) { print $res->content; } else { print $res->status_line; }
    poj

      poj when i run it still i get 400 BAD REQUEST

        print the content $res->content on failure also

        if ($res->is_success) { print $res->content; } else { print $res->status_line; print $res->content; }

        You should get an error code like this

        {"error": {"message": "HMAC authentication key and signature was given +, but they are invalid.", "error_code": 41}}
        poj