How to make iContact API call from Google scripts

核能气质少年 提交于 2020-01-06 07:58:08

问题


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:


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.



来源:https://stackoverflow.com/questions/14008002/how-to-make-icontact-api-call-from-google-scripts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!