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 issue #2

Closed s00188372 closed 2 years ago

s00188372 commented 2 years ago

Function used import Cryptoapis from 'cryptoapis'; let defaultClient = Cryptoapis.ApiClient.instance; // Configure API key authorization: ApiKey let ApiKey = defaultClient.authentications['ApiKey']; ApiKey.apiKey = 'YOUR API KEY'; // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) //ApiKey.apiKeyPrefix = 'Token';

let apiInstance = new Cryptoapis.GeneratingApi(); let blockchain = bitcoin; // String | Represents the specific blockchain protocol name, e.g. Ethereum, Bitcoin, etc. let network = testnet; // String | Represents the name of the blockchain network used; blockchain networks are usually identical as technology and software, but they differ in data, e.g. - \"mainnet\" is the live network with actual data while networks like \"testnet\", \"ropsten\" are test networks. let walletId = 60c9d9921c38030006675ff6; // String | Represents the unique ID of the specific Wallet. let opts = { 'context': "context_example", // String | In batch situations the user can use the context to correlate responses with requests. This property is present regardless of whether the response was successful or returned as an error. context is specified by the user. 'generateDepositAddressRB': new Cryptoapis.GenerateDepositAddressRB() // GenerateDepositAddressRB | }; apiInstance.generateDepositAddress(blockchain, network, walletId, opts).then((data) => { console.log('API called successfully. Returned data: ' + data); }, (error) => { console.error(error); });

Error Return {"code":"invalid_request_body_structure","message":"Your request body for POST requests must have a structure of { data: { item: [...properties] } }"}}'

Crypto-APIs commented 2 years ago

Hello,

It seems that you are sending an empty generateDepositAddressRB object in your request body.

Instead of: 'generateDepositAddressRB': new Cryptoapis.GenerateDepositAddressRB()

It should be like this:

'generateDepositAddressRB': new Cryptoapis.GenerateDepositAddressRB(
    new Cryptoapis.GenerateDepositAddressRBData(
        new Cryptoapis.GenerateDepositAddressRBDataItem('custom label')
    )
)

Here is a full example of the request:

import Cryptoapis from 'cryptoapis';
let defaultClient = Cryptoapis.ApiClient.instance;
let ApiKey = defaultClient.authentications['ApiKey'];
ApiKey.apiKey = 'YOUR API KEY';

let apiInstance = new Cryptoapis.GeneratingApi();
let blockchain = 'bitcoin';
let network = 'testnet';
let walletId = '60c9d9921c38030006675ff6';
let opts = {
    'context': "context_example",
    'generateDepositAddressRB': new Cryptoapis.GenerateDepositAddressRB(
        new Cryptoapis.GenerateDepositAddressRBData(
            new Cryptoapis.GenerateDepositAddressRBDataItem('custom label')
        )
    )
};

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

Kind regards, Crypto APIs Team