Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

invalid timestamp

by bigup401 (Pilgrim)
on Nov 11, 2020 at 13:18 UTC ( [id://11123587]=perlquestion: print w/replies, xml ) Need Help??

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

am getting this error when i try to run the code

"message":"invalid timestamp"

and this is the api timestamp guidelines

TIMESTAMPS All timestamp are returned in ISO8601 format in UTC with fields ending in postfix _at. Example: "created_at": "2015-07-01T00:55:47Z" Your timestamp must be within 30 seconds of the api service time or your request will be considered expired and rejected. We recommend using the time endpoint to query for the API server time if you believe there many be time skew between your server and the API servers. The CB-ACCESS-TIMESTAMP header MUST be number of seconds since Unix Epoch.

#!/usr/bin/perl use LWP::UserAgent; use JSON::Create 'create_json'; use JSON; use Digest::SHA qw(hmac_sha256_base64 hmac_sha256_hex hmac_sha256); use MIME::Base64; use POSIX qw(strftime); my $Endpoint = 'https://api.coinbase.com'; my $api_key = 'KEY'; my $secret = 'SCRETE'; my %json = ( type => 'send', to => 'ADDY', amount => '1.00', amount => 'USD' ); my $body = create_json (\%json); my $timestamp = strftime '%Y-%m-%dT%H:%M:%SZ', gmtime(); my $request_method = "POST"; my $request_path = '/v2/accounts/account:id/transactions'; 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) ); my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 }, ); $ua->agent("MyApp/0.1"); my $res = $ua->post( "$Endpoint$request_path", 'CB-ACCESS-SIGN' => $signature_b64, 'CB-ACCESS-TIMESTAMP' => $timestamp, 'CB-ACCESS-KEY' => $api_key, 'CB-ACCESS-VERSION' => '2019-11-15', 'Content-Type' => 'application/json' ); if ($res->is_success) { print $res->decoded_content; } else { print "request failed."; print "status:", $res->decoded_content; }

Replies are listed 'Best First'.
Re: invalid timestamp
by Corion (Patriarch) on Nov 11, 2020 at 13:20 UTC

    Have you looked at the actual value you are sending and whether it matches the API expectations?

    Have you used a manual value with the API?

    Have you noticed the distinction in the API between "epoch" and "timestamp"?

      Have you used a manual value with the API?

      yes

      Have you looked at the actual value you are sending and whether it matches the API expectations?

      yes

      Have you noticed the distinction in the API between "epoch" and "timestamp"?

      NO

        i have solved this after looking into this ( Have you noticed the distinction in the API between "epoch" and "timestamp"?)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11123587]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-19 20:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found