How can I receive a a custon field in google sheets

I’m trying to collect contact information into a google sheets, and I can get only the normal fields, but I have 2 custom fields, that is not listed here, how can I get this fields ?

Here my source code.
any ideas?
I’m using Scripts for google sheets.

function doGetContacts(e) {

return getContacts(e);

}

function getContacts(e){

    try {

        var responseC = UrlFetchApp.fetch(URL+'/contacts?listid=28', options);

        var dataC = responseC.getContentText();

        var jsonC = JSON.parse(dataC);

        var contacts = jsonC['contacts'];

        var contactsData = [];

      

       for (var i = 0; i < contacts.length; i++) {

        contactsData.push([

          contacts[i]["email"],

          contacts[i]["firstName"],

          contacts[i]["phone"],

          contacts[i]["id"],

            ]);

          }

        var numRows = contactsData.length;

        var numCols = contactsData[0].length;

        var ss = SpreadsheetApp.getActiveSpreadsheet();

        var sheet = ss.getSheetByName('Sheet1');

        sheet.getRange('A2:M').clearContent();

        SpreadsheetApp.flush();

        Utilities.sleep(500);

        sheet.getRange(2,1,numRows,numCols).setValues(contactsData);

    }

    catch (error) {

        Logger.log(error);

    }

}

Hello,

You can include the custom field values via sideloading. To do this, add the additional include parameter to your query string with a value of fieldValues. Your updated URL should look like this: /contacts?listid=28&include=fieldValues.

This will tell the API to return the custom field values as part of the response. It will be a separate array on the API response (in your code this would be accessed on jsonC) called fieldValues. In your code you can access this data by doing something like var fieldValues = jsonC['fieldValues'];

Then you will need to iterate over this array to compare the contact field, which is the contact’s ID, to the id field in each item in your existing contacts array to assign the custom field values to the correct contact.

-Matt

1 Like