Skip to content
POST{BASE_URL}/wx-api/api/contact/updateLabel
写操作联系人JSON · Bearer App Token · body appid

更新用户标签

给某个用户打 / 去 / 改标签(操作的是「用户 ↔ 标签」的关联)。

请求参数

参数必填类型说明
appidstring实例 appid,标识操作哪个已登录账号。示例:we_xxxxxxxxxxxxxxx
userIdint64被打标签的用户 id。示例:1688857990821417
operItemsarray<object>标签操作项列表。示例:[{"op":3,"label":{"id":14073750445976458,"name":"测试","dat…
operItems[] 字段
字段类型说明
operItems[].opint64操作:1 新增 / 2 删除 / 3 修改
operItems[].labelobject完整标签对象(须原样取自本接口响应)
operItems[].label.idint64标签 id
operItems[].label.namestring标签名
operItems[].label.dataTypeint64数据类型:1 标签、2 标签组
operItems[].label.bDeletedint64是否已删除(0/1)
operItems[].label.labelGroupIdint64所属标签组 id
operItems[].label.createTimeint64建立 / 更新时间戳(秒)
operItems[].label.labelTypeint64标签类型:1 企业标签、2 个人标签
operItems[].label.businessTypeint64业务类型 / 排序 / 服务组 id(原样回传)
operItems[].label.orderint64业务类型 / 排序 / 服务组 id(原样回传)
operItems[].label.serviceGroupIdint64业务类型 / 排序 / 服务组 id(原样回传)

请求示例

http
POST {BASE_URL}/wx-api/api/contact/updateLabel
Authorization: Bearer <你的 App Token>
Content-Type: application/json

{
  "appid": "we_xxxxxxxxxxxxxxx",
  "userId": 1688857990821417,
  "operItems": [
    {
      "op": 3,
      "label": {
        "id": 14073750445976458,
        "name": "测试",
        "dataType": 1,
        "bDeleted": 0,
        "labelGroupId": 14073751857989781,
        "createTime": 1787872137,
        "labelType": 2,
        "businessType": 0,
        "order": 0,
        "serviceGroupId": 0
      }
    }
  ]
}
bash
curl -X POST '{BASE_URL}/wx-api/api/contact/updateLabel' \
  -H 'Authorization: Bearer <你的 App Token>' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "appid": "we_xxxxxxxxxxxxxxx",
  "userId": 1688857990821417,
  "operItems": [
    {
      "op": 3,
      "label": {
        "id": 14073750445976458,
        "name": "测试",
        "dataType": 1,
        "bDeleted": 0,
        "labelGroupId": 14073751857989781,
        "createTime": 1787872137,
        "labelType": 2,
        "businessType": 0,
        "order": 0,
        "serviceGroupId": 0
      }
    }
  ]
}'
python
import requests

url = "{BASE_URL}/wx-api/api/contact/updateLabel"
headers = {"Authorization": "Bearer <你的 App Token>", "Content-Type": "application/json"}
body = """{
  "appid": "we_xxxxxxxxxxxxxxx",
  "userId": 1688857990821417,
  "operItems": [
    {
      "op": 3,
      "label": {
        "id": 14073750445976458,
        "name": "测试",
        "dataType": 1,
        "bDeleted": 0,
        "labelGroupId": 14073751857989781,
        "createTime": 1787872137,
        "labelType": 2,
        "businessType": 0,
        "order": 0,
        "serviceGroupId": 0
      }
    }
  ]
}"""

resp = requests.post(url, headers=headers, data=body.encode("utf-8"))
print(resp.text)
java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

String url = "{BASE_URL}/wx-api/api/contact/updateLabel";
String body = "{\n" +
    "  \"appid\": \"we_xxxxxxxxxxxxxxx\",\n" +
    "  \"userId\": 1688857990821417,\n" +
    "  \"operItems\": [\n" +
    "    {\n" +
    "      \"op\": 3,\n" +
    "      \"label\": {\n" +
    "        \"id\": 14073750445976458,\n" +
    "        \"name\": \"测试\",\n" +
    "        \"dataType\": 1,\n" +
    "        \"bDeleted\": 0,\n" +
    "        \"labelGroupId\": 14073751857989781,\n" +
    "        \"createTime\": 1787872137,\n" +
    "        \"labelType\": 2,\n" +
    "        \"businessType\": 0,\n" +
    "        \"order\": 0,\n" +
    "        \"serviceGroupId\": 0\n" +
    "      }\n" +
    "    }\n" +
    "  ]\n" +
    "}";

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
    .header("Authorization", "Bearer <你的 App Token>")
    .header("Content-Type", "application/json")
    .POST(HttpRequest.BodyPublishers.ofString(body))
    .build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
php
<?php

$url = '{BASE_URL}/wx-api/api/contact/updateLabel';
$body = <<<'JSON'
{
  "appid": "we_xxxxxxxxxxxxxxx",
  "userId": 1688857990821417,
  "operItems": [
    {
      "op": 3,
      "label": {
        "id": 14073750445976458,
        "name": "测试",
        "dataType": 1,
        "bDeleted": 0,
        "labelGroupId": 14073751857989781,
        "createTime": 1787872137,
        "labelType": 2,
        "businessType": 0,
        "order": 0,
        "serviceGroupId": 0
      }
    }
  ]
}
JSON;

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer <你的 App Token>',
    'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;

响应示例

解析响应前确认字段

返回字段见联系人模块总览。完整响应格式及未列出的字段,请通过开通与支持联系对接人确认后再解析。

响应字段

字段类型说明
codeint64统一封套状态码:0=成功,负数=失败
detailstring附加明细,通常为空
messagestring文案:成功为 ok;失败形如 -码|描述
timestring服务端处理时间 YYYY-MM-DD HH:MM:SS

下一步