Quantcast
Channel: Topliners : All Content - All Communities
Viewing all articles
Browse latest Browse all 3423

Issues Pulling Contact Fields from Bulk API

$
0
0

I am putting together some code to bulk export data using Node.js and I am running into issues where the /contact/fields call is returning invalid JSON.  It seems to only happen when the pageSize gets too high.  It returns extra spaces or newlines in the JSON which breaks the JSON.parse() function.

 

The only way I have found to get around the problem is to make the page size 10 or less.  It seems anything larger and I get a JSON parse error.  Here is the code i am using

 

function getAllEloquaFields(callback) {  var https = require('https');  var config = require('./config'); // This just sets the https options and builds the auth header  config.options.host = 'secure.eloqua.com';  config.options.path = '/API/Bulk/1.0/contact/fields?page=100&pageSize=20';  config.options.port = '443';  config.options.method = 'GET';  function final() { callback(results); }  var page_size = 10;  var results = [];  function repeat(page,page_size) {    config.options.path = url_obj.pathname + 'contact/fields?page='+page+'&pageSize='+page_size;    var reqGet = https.request(config.options, function(res) {      res.on('data', function(d) {        var json;        try {          json = JSON.parse(d);          if(json.elements.length > 0) {            results = results.concat(json.elements);            repeat(page+1,page_size);          } else {            final();          }        } catch(e) {          console.log('There was an error: ' + e);        }      });    });    reqGet.end();    reqGet.on('error', function(e) {      console.error(e);    });  }  repeat(1,page_size);
};

getAllEloquaFields(url_obj,function(elements) {
  console.log(elements);
});

 

And here is the section of json that seems to have the issue:

 

{      " createdAt": "/Date(-2208970800000)/", //<---- the extra space is messing things up      "dataType": "string",      "hasNotNullConstraint": false,      "hasReadOnlyConstraint": false,      "hasUniquenessConstraint": false,      "internalName": "C_SFDCLeadID",      "name": "SFDC LeadID",      "statement": "{{Contact.Field(C_SFDCLeadID)}}",      "updatedAt": "/Date(1270576350780)/",      "updatedBy": "Some.One",      "uri": "/contact/field/100024"
},

 

Has anyone else seen this issue?

 

Thanks,

Russ


Viewing all articles
Browse latest Browse all 3423

Trending Articles