You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用ActiveCampaign API v1 contact_sync添加联系人提示缺邮箱如何解决

问题原因

你触发报错是两个配置错误共同导致的:

  • 请求头的Content-Type值配置错误,多写了冗余的Content-Type: 前缀,导致服务端无法正确识别请求体格式
  • ActiveCampaign V1 接口仅支持application/x-www-form-urlencoded格式的参数,你直接传递JS对象作为请求体,服务端无法正常解析参数,因此识别不到提交的邮箱字段

可运行代码示例

Netlify Lambda 为Node.js运行环境,你可以直接用内置的URLSearchParams做参数序列化,无需引入额外依赖:

const axios = require('axios');

exports.handler = async (event) => {
  // 序列化请求参数
  const requestParams = new URLSearchParams();
  requestParams.append('email', 'email@email.com');
  requestParams.append('first_name', 'John');
  // 如需同步到指定列表,添加下方参数,将12替换为你的目标列表ID即可
  // requestParams.append('p[12]', 12);

  try {
    const response = await axios({
      method: 'post',
      url: 'https://ACCOUNT.api-us1.com/admin/api.php?api_key=你的API密钥&api_action=contact_sync&api_output=json',
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
      data: requestParams
    });
    return {
      statusCode: 200,
      body: JSON.stringify(response.data)
    };
  } catch (err) {
    return {
      statusCode: 500,
      body: JSON.stringify(err.response?.data || err.message)
    };
  }
};

如果更习惯用qs库做序列化,安装qs依赖后可以用下方写法:

const axios = require('axios');
const qs = require('qs');

// 接口请求部分代码
const response = await axios({
  method: 'post',
  url: 'https://ACCOUNT.api-us1.com/admin/api.php?api_key=你的API密钥&api_action=contact_sync&api_output=json',
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  data: qs.stringify({
    email: 'email@email.com',
    first_name: 'John'
  })
});

内容的提问来源于stack exchange,提问作者JohnnyK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 11:15:02