in reply to Re^10: Invalid nonce
in thread Invalid nonce

i have been able to make this API to work, and am successfully interacting with it now

Am trying to make a post with this data

my $url_query = "currency=usdt"."&amount=20"."&address=0x55Dc816924e33 +CA50830A"."&destination_tag=None";

but am getting this error

{"status": "error", "reason": {"amount": ["This field is required."]}}
 API Documentation Section : https://www.bitstamp.net/api/#tag/Withdrawals/operation/RequestCryptoWithdrawal

Full code

#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use Digest::SHA qw(hmac_sha256_hex); use UUID::Tiny ':std'; use URI::Escape; use JSON; use Time::HiRes qw(time); use JSON::XS; sub write_call_back { my ($data, $userp) = @_; ${$userp} .= $data; return length($data); } sub url_encode { my ($data) = @_; return uri_escape($data); } my $api_key = "api_key"; my $api_secret = "api_secret"; my $timestamp = int(time() * 1000); my $nonce = create_uuid_as_string(UUID_V4); my $x_auth = "BITSTAMP $api_key"; my $x_auth_nonce = $nonce; my $x_auth_timestamp = $timestamp; my $x_auth_version = "v2"; my $content_type = "application/x-www-form-urlencoded"; my $payload = url_encode('{"offset":1}'); my $http_method = "POST"; my $url_host = "www.bitstamp.net"; my $url_path = "/api/v2/usdt_withdrawal/?"; my $url_query = "currency=usdt"."&amount=20"."&address=0x55Dc816924e33 +CA50830A"."&destination_tag=None"; my $data_to_sign = join('', $x_auth, $http_method, $url_host, $url_path, $url_query, $content_type, $x_auth_nonce, $x_auth_timestamp, $x_auth_version, +$payload ); my $x_auth_signature = hmac_sha256_hex($data_to_sign, $api_secret); my $ua = LWP::UserAgent->new; my $url = "https://$url_host$url_path$url_query"; my $req = HTTP::Request->new(POST => $url); $req->header('X-Auth' => $x_auth); $req->header('X-Auth-Signature' => $x_auth_signature); $req->header('X-Auth-Nonce' => $x_auth_nonce); $req->header('X-Auth-Timestamp' => $x_auth_timestamp); $req->header('X-Auth-Version' => $x_auth_version); $req->header('Content-Type' => $content_type); $req->content($payload); my $resp = $ua->request($req); if ($resp->is_success) { print $resp->content; } else { print "HTTP POST error code: ", $resp->code, "\n"; print "HTTP POST error message: ", $resp->message, "\n"; }

Replies are listed 'Best First'.
Re^12: Invalid nonce
by hippo (Archbishop) on Aug 21, 2024 at 10:28 UTC

    Use the techniques outlined in Basic debugging checklist to determine precisely what you are sending to the API endpoint. Then look in the API documentation for that endpoint to see precisely what it expects to be sent.

    If what you are sending does not match the spec then alter your code until it does.

    If what you are sending does match the spec but still gives an error then contact the API provider to enquire about the problem.


    🦛

Re^12: Invalid nonce
by Corion (Patriarch) on Aug 21, 2024 at 16:12 UTC

    hippo's advice is correct. Compare what you are sending against what you think you are sending.

    See (for example) LWP::Debug for a good approach to see all the data you send:

    use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->add_handler("request_send", sub { shift->dump; return }); $ua->add_handler("response_done", sub { shift->dump; return }); ...
Re^12: Invalid nonce
by cavac (Prior) on Aug 21, 2024 at 06:19 UTC

      this method, also failed earlier, i think i will contact there support because am seeing alot API fixes. seems there have alot bugs in there API. because even there perl module nolonger works : https://metacpan.org/pod/Finance::BitStamp::API