iContact API Create contact call in JS google script

132 Views Asked by At

I'm trying to create a new contact through the iContact API.

I got the error message as

You did not provide an email field, which is required. Please provide an email field

by running the following code with Google Apps Script.

I guess the payload structure is not good, i tried other structures without success.

function sendHttpPost() {
var headers= {
"API-Username":"[email protected]",
"API-AppId":"pkec8CCH3Rd5GJoYY52YMjfPZym1sIXI",
"API-Version":"2.0",
"API-Password":"4tpzgto4tpzgto",
"Accept":"application/json"};
var payload = 
    {contact: 
        { "contactId":64363721,
    "email":"[email protected]",
    "prefix":"Mr.",
    "firstName":"Michael",
    "lastName":"Smith",
    "suffix":"Jr.",
    "street":"2365 Meridian Parkway",
    "street2":"",
    "city":"Durham",
    "state":"NC",
    "postalCode":27502,
    "phone":"8668039462",
    "fax":"",
    "business":"ABusiness",
    "createDate":"2009-06-18 22:39:54'",
    "bounceCount":0,
    "status":"normal",
   }
}
    ;

  var options =
    {
      "headers" : headers,
      "method" : "POST",
      "payload" : payload,
      "timeout":5000
    };

var res = UrlFetchApp.fetch("https://app.icontact.com/icp/a/{account_id}/c/{folder_id}/contacts/", options);

Logger.log(res);
}

iContact API documentation link
I get also the email issue when trying with the same code as this old post

0

There are 0 best solutions below