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

使用SimpleTexting API添加带自定义字段联系人时遇‘未知自定义字段’错误

关于SimpleTexting API添加联系人时自定义标签字段的问题

问题描述

我尝试使用SimpleTexting API向“Registrants”群组添加联系人,移除custom_tags字段时联系人可正常添加,但加入该字段后会收到错误{ code: -611, message: 'Unknown custom field' }。我已参照官方文档(文档说明:customField需替换为实际自定义字段参数,例如“Street address”对应参数为“street_address”),测试了customField、custom_tags、tags等多种参数,均无法解决问题。请问问题出在哪里?正确的编码方式是什么?

相关代码

app.post('/api/outgoing-from-ac', async (req, res, next) => {
    try {
        const {contact} = req.body;
        const {email, first_name, last_name, phone, tags} = contact;

        let response = await axios({
            method: 'post',
            url: 'https://app2.simpletexting.com/v1/group/contact/add',
            json: true,
            data: querystring.stringify({
                token: config.simple_texting.token,
                group: 'Registrants',
                phone,
                firstName: first_name,
                lastName: last_name,
                email,
                custom_tags: tags, // <--- This does not work!
            }),
            headers: {
                'content-type': 'application/x-www-form-urlencoded',
            },
        });

        console.log(response.data);

        res.json({
            status: 'OK',
        });
    } catch (error) {
        console.log(error);
        res.json({
            success: false,
            message: 'Error!',
        });
    }
});

问题分析与解决方案

问题核心是混淆了标签(Tags)和自定义字段(Custom Fields)的API参数逻辑:

  • custom_tags不是SimpleTexting API认可的参数名,API将其识别为自定义字段,而该字段不存在,因此抛出Unknown custom field错误
  • 标签的正确参数名是tags,且需要满足格式要求

正确代码修改

如果tags是数组格式,先转换为逗号分隔的字符串(API要求的格式):

app.post('/api/outgoing-from-ac', async (req, res, next) => {
    try {
        const {contact} = req.body;
        const {email, first_name, last_name, phone, tags} = contact;

        // 将标签数组转为逗号分隔的字符串
        const formattedTags = Array.isArray(tags) ? tags.join(',') : tags;

        let response = await axios({
            method: 'post',
            url: 'https://app2.simpletexting.com/v1/group/contact/add',
            data: querystring.stringify({
                token: config.simple_texting.token,
                group: 'Registrants',
                phone,
                firstName: first_name,
                lastName: last_name,
                email,
                tags: formattedTags, // 使用正确的tags参数
            }),
            headers: {
                'content-type': 'application/x-www-form-urlencoded',
            },
        });

        console.log(response.data);

        res.json({
            status: 'OK',
        });
    } catch (error) {
        console.log(error);
        res.json({
            success: false,
            message: 'Error!',
        });
    }
});

额外注意点

  1. 若你实际需要添加的是自定义字段(而非标签),需先在SimpleTexting后台创建对应字段,再用字段的参数名传递值。例如创建了“Favorite Color”字段,对应参数为favorite_color,则添加favorite_color: "blue"的键值对
  2. 确保传递的标签是SimpleTexting后台已存在的,部分API版本支持自动创建新标签,若不支持需提前创建

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 00:00:02