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 | |
by bigup401 (Pilgrim) on Nov 11, 2020 at 13:31 UTC | |
by bigup401 (Pilgrim) on Nov 11, 2020 at 18:20 UTC | |
by stevieb (Canon) on Nov 12, 2020 at 18:06 UTC |