Crypto-APIs / Crypto_APIs_2.0_SDK_Node.js

Crypto APIs 2.0 Node.js library/SDK
14 stars 11 forks source link

invalid_request_body_structure: Your request body for POST requests must have a structure of ... #1

Closed pierreco closed 3 years ago

pierreco commented 3 years ago

Hello,

When I try to use the v2 API, I get this error.

'{"apiVersion":"2.0.0","requestId":"61249fa7d1d3ceb1da12d030","error":{"code":"invalid_request_body_structure","message":"Your request body for POST requests must have a structure of { data: { item: [...properties] } }"}}'

Here is my code below:


async function generateDepositAddress({ walletId, blockchain, network }) {
  const defaultClient = Cryptoapis.ApiClient.instance;
  const ApiKey = defaultClient.authentications['ApiKey'];
  ApiKey.apiKey = process.env.CRYPTO_API_KEY;
  let apiInstance = new Cryptoapis.GeneratingApi();

  apiInstance.generateDepositAddress(blockchain, network, walletId).then((data) => {
    console.log('API called successfully. Returned data: ' + data);
    return data;
  }, (error) => {
    console.error(error);
    return error?.body?.error?.message
  });
}
Crypto-APIs commented 3 years ago

Hello,

Since it is a POST request, you should also send a request body.

Here is an example:

async function generateDepositAddress({ walletId, blockchain, network }) {
    const defaultClient = Cryptoapis.ApiClient.instance;
    const ApiKey = defaultClient.authentications['ApiKey'];
    ApiKey.apiKey = process.env.CRYPTO_API_KEY;
    let apiInstance = new Cryptoapis.GeneratingApi();

    let item = new Cryptoapis.GenerateDepositAddressRBDataItem('yourLabelStringHere');
    let postData = new Cryptoapis.GenerateDepositAddressRBData(item);
    let opts = {
        'generateDepositAddressRB': new Cryptoapis.GenerateDepositAddressRB(postData)
    };

    apiInstance.generateDepositAddress(blockchain, network, walletId, opts).then((data) => {
        console.log('API called successfully. Returned data: ' + data);
        return data;
    }, (error) => {
        console.error(error);
        return error?.body?.error?.message
    });
}

Kind regards, Crypto APIs