sendinblue / APIv3-nodejs-library

SendinBlue's API v3 Node.js Library
ISC License
101 stars 47 forks source link

data.map is not a function. #26

Closed Dallas62 closed 6 years ago

Dallas62 commented 6 years ago

While retrieving ContactInfo with:

    apiInstance.getContactInfo(email)

I fall into a bug:

TypeError: data.map is not a function
    at Function.exports.convertToType ([project]/node_modules/sib-api-v3-sdk/src/ApiClient.js:503:23)
    at Function.exports.constructFromObject ([project]/node_modules/sib-api-v3-sdk/src/model/GetExtendedContactDetailsStatistics.js:77:40)
    at Function.exports.constructFromObject ([project]/node_modules/sib-api-v3-sdk/src/model/GetExtendedContactDetails.js:76:65)
    at Function.exports.convertToType ([project]/node_modules/sib-api-v3-sdk/src/ApiClient.js:498:23)
    at exports.deserialize ([project]/node_modules/sib-api-v3-sdk/src/ApiClient.js:347:20)
    at [project]/node_modules/sib-api-v3-sdk/src/ApiClient.js:444:30
    at Request.callback ([project]/node_modules/superagent/lib/node/index.js:668:14)
    at [project]/node_modules/superagent/lib/node/index.js:883:18
    at IncomingMessage.<anonymous> ([project]/node_modules/superagent/lib/node/parsers/json.js:16:7)
    at IncomingMessage.emit (events.js:165:20)
    at endReadableNT (_stream_readable.js:1101:12)
    at process._tickCallback (internal/process/next_tick.js:152:19) 'data.map is not a function'

I added some debug log in [project]/node_modules/sib-api-v3-sdk/src/ApiClient.js:503:

          // for array type like: ['String']
          var itemType = type[0];
          console.log(type, data);   /// <=====
          return data.map(function(item) {
            return exports.convertToType(item, itemType);
          });

3 elements are printed:

[ 'Number' ] [ 4 ]
[ { [Function: exports] constructFromObject: [Function] } ] [ { campaignId: 16, eventTime: '2017-04-28T17:13:52.000+02:00' } ]
[ { [Function: exports] constructFromObject: [Function] } ] { campaignId: 16, eventTime: '2017-04-28T17:14:32.099+02:00' }

Cordialy.

ekta-slit commented 6 years ago

Hi @Dallas62

Can you please share your complete code input, so that we can try to replicate?

Thanks

Dallas62 commented 6 years ago

Just need to call

apiInstance.getContactInfo(email)

over a list of emails, the inputs that create the bug come from sendinblue API.

ekta-slit commented 6 years ago

Issue not replicated at our end. Please try below code, it works nicely

var SibApiV3Sdk = require('sib-api-v3-sdk');

var defaultClient = SibApiV3Sdk.ApiClient.instance;

var apiKey = defaultClient.authentications['api-key'];
apiKey.apiKey = "yourApiKey"

var apiInstance = new SibApiV3Sdk.ContactsApi();

var email = "test@sendinblue.com"; // String | Email (urlencoded) of the contact

apiInstance.getContactInfo(email).then(function(data) {
  console.log('API called successfully. Returned data: ' + data);
}, function(error) {
  console.error(error);
});

Hope that helps! If you still face any issue please raise a support ticket here https://account.sendinblue.com/support with detailed information.

Thanks

Dallas62 commented 6 years ago

The following code is the same or close as mine.

The problem doesn't appear on test@sendinblue.com, well.

Take randomly 10k emails from production and run the same code in a loop to find an email with the bug.

If you have a private contact point, I can find a e-mail from our database/sendinblue campaigns.