0

I need to write a function in google scripts that addes a contact to icontact via API. I have the following code which works to change a contact but I am unsuccessful in changing the code to add a contact... Does anybody know how to write the call to add a contact?

function sendHttpPost() {
var headers= {
"API-Username":"XXXXX",
"API-AppId":"XXXXXX",
"API-Version":"2.0",
"API-Password":"XXXXX",
"Accept":"application/json"};
var payload = 
  {
    "contactId":1976438,
    "email":"schnick@schnack.com",
    "prefix":"Mr.",
    "firstName":"X",
    "lastName":"XXXXX",

  };

  var options =
    {
      "headers" : headers,
      "method" : "post",
      "payload" : payload
    };

UrlFetchApp.fetch("https://app.icontact.com/icp/a/XXXXX/c/XXXX/contacts/1976438", options);
}
Mogsdad
  • 44,709
  • 21
  • 151
  • 275

1 Answers1

0

The difference between an update and an add, according to the posted documentation, is in the URL you Post to. To update a contact, the URL path ends with the {contactId}, while to add a contact you leave that out.

Add:

https://app.sandbox.icontact.com/icp/a/{accountId}/c/{clientfolderId}/contacts/

Update

https://app.sandbox.icontact.com/icp/a/{accountId}/c/{clientfolderId}/contacts/{contactId}

In your code above, you're including {contactId}, "1976438". Drop that, and you'll be adding a new contact.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275