简体   繁体   中英

Active Campaign API: How to 'create or update contact' along with their custom field values?

I'm using Node js, and I can create/update a contact's email, name, or phone number. But the custom fields I have never get updated. Here's what I got so far.

 var data = JSON.stringify({
   "contact": {
        "email": "t@brady.com",
         "firstName": "Tom",
        "lastName": "Brady",
        "phone": "111122233",
        "myCustomField": "myValue"
    }
 });

 var options = {
   hostname: hostname,
   path: '/api/3/contact/sync',
   method: 'POST',
   headers: {
     'Api-Token': apiToken,
     'Content-Type': 'application/x-www-form-urlencoded',
     'Content-Length': data.length
   }
 }

 var req = this.https.request(options, function(res){
 });
 req.on('error', function(err){
   console.log('error: ' + err.message);
 });
 req.write(data);
 req.end();

So this will update the contact's built-in fields (email, name, phone) but not myCustomField. Any idea why? How to solve it? I would really appreciate any help.

PS myCustomField exists in Active Campaign. The contact just doesn't have a value for it.

First, you need to get the filed id of the custom fields. You can do this with postman with GET request https://youraccountname.api-us1.com/api/3/fields docs and when you have the ids that you want to update you can easily do it like this. Hope it help. I was struggling a lot before I figured this out.

fetch(proxyurl + active_campaign_url, {
  mode: "cors",
  method: "POST",
  body: JSON.stringify({
    contact: {
      firstName,
      lastName,
      email,
      fieldValues: [
        {
          field: 1,
          value: jobTitle,
        },
        {
          field: 30,
          value: companyName
        }
      ],
    },
  }),
  headers: headers,
})
  .then((response) => response.json())**strong text**

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM