Dear Monks, Happy 4th of July!

Coinbase has a REST-ful API and offers code snippets in NodeJS, Python, Ruby, and PHP to connect to this API. I think a snippet showing how to connect to the latest Coinbase API in Perl would be useful to many. So I created an account on pro.coinbase.com and got an API key. I wrote the following code, based on the examples in other languages. It looks correct, but does not authenticate. I would appreciate any help. You don't have to create an account, as I've included my API key and secret key.

Please help me get this code talking to Coinbase. The API Documentation is here.

use Modern::Perl; use LWP::UserAgent; use JSON; use Digest::SHA qw(hmac_sha256_base64 hmac_sha256_hex hmac_sha256); use MIME::Base64; my $uri = 'https://api-public.sandbox.pro.coinbase.com'; my $api_key = '6dc071df2d42724c019f79a53464d006'; my $secret = 'vjYZFn39LEFfbJ5z9QzdWt+HsahYTPvXInoYMD9Gq754FJL0evlG +nHcTiaaITGF+6GfbyYnxoyCXji9OR1iEMw=='; my $passphrase = "There is no passphrase.", my $timestamp = time(); my $request_method = "GET"; my $request_path = '/products'; my $body = ''; my $message = $timestamp . $request_method . $request_path . $b +ody; my $decoded_secret = decode_base64($secret); my $signature_b64 = encode_base64( hmac_sha256($message, $decoded_secr +et) ); chomp($signature_b64); my $ua = LWP::UserAgent->new; my $res = $ua->get( $uri, 'CB-ACCESS-SIGN' => $signature_b64, 'CB-ACCESS-TIMESTAMP' => $timestamp, 'CB-ACCESS-KEY' => $api_key, 'CB-ACCESS-PASSPHRASE' => $passphrase, 'Content-Type' => 'application/json' ); if ($res->is_success) { say $res->decoded_content; } else { say "request failed."; say "status:", $res->status_line; }

In reply to Coinbase API by ownlifeful

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.