如何使用SuiteCRM V8 API创建联系人?(已获取有效访问令牌)
使用SuiteCRM V8 API创建联系人(客户端凭证模式)
核心请求信息
- 请求方法:
POST - API端点:
/api/v8/module/Contacts - 必要请求头:
Authorization: Bearer YOUR_ACCESS_TOKEN(替换为你获取的有效令牌)Content-Type: application/vnd.api+json(SuiteCRM V8遵循JSON:API规范)
请求体格式示例
请求体必须符合JSON:API结构,attributes内的字段对应SuiteCRM联系人模块的字段别名(而非显示名称),其中last_name为必填项:
{ "data": { "type": "Contacts", "attributes": { "first_name": "John", "last_name": "Doe", "email1": "john.doe@example.com", "phone_work": "123-456-7890", "title": "Software Engineer" } } }
完整curl请求示例
curl -X POST "https://your-suitecrm-instance.com/api/v8/module/Contacts" \ -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9..." \ -H "Content-Type: application/vnd.api+json" \ -d '{ "data": { "type": "Contacts", "attributes": { "first_name": "John", "last_name": "Doe", "email1": "john.doe@example.com" } } }'
关键注意事项
- 权限验证:确保你的客户端凭证拥有Contacts模块的创建权限,否则会返回
403 Forbidden错误 - 字段别名:字段名需与SuiteCRM内部定义的别名一致(例如邮箱字段是
email1而非email,办公电话是phone_work),可通过后台「模块管理→联系人→字段」查看别名 - 关联其他模块:如果需要将联系人关联到账户、机会等模块,可添加
relationships字段,示例:{ "data": { "type": "Contacts", "attributes": { "first_name": "John", "last_name": "Doe" }, "relationships": { "accounts": { "data": [ { "type": "Accounts", "id": "550e8400-e29b-41d4-a716-446655440000" } ] } } } } - 响应状态:成功创建会返回
201 Created,并返回联系人的完整数据;字段验证失败(如缺少必填项)会返回422 Unprocessable Entity,附带具体错误提示
内容的提问来源于stack exchange,提问作者Bhavesh Nariya
相关产品推荐
相关产品推荐

