How to make iContact API call from Google scripts

2019-09-08 18:35发布

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);
}

1条回答
太酷不给撩
2楼-- · 2019-09-08 19:33

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.

查看更多
登录 后发表回答