WeChat API documentation: quick start, endpoints, webhooks and errors
This WeChat API documentation covers personal WeChat and WeCom endpoints in one REST + JSON API. Once your account is set up, the console always has the latest version.
This page is a public summary
It covers 18 common endpoints. The full API documentation includes every endpoint with detailed parameters, response fields and webhook payloads. Leave your details and we'll send it over.
Auth & conventions
- Base URL:
https://api.wechatapilabs.com - Auth header:
Authorization: Bearer YOUR_API_KEY - UTF-8 JSON in and out; every response is
{"code", "message", "request_id", "data"}andcode = 0means success - Timestamps are Unix seconds
- Default rate limit: 5 requests per second per account; over the limit returns
45009
Quick start
- Contact us for a test account and copy your API key from the console.
- Call Get login QR code, scan it with the phone and wait for the
account.onlinewebhook. - Call Send text to send your first message.
import requests
resp = requests.post(
"https://api.wechatapilabs.com/v1/message/send_text",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"account_id": "acc_123", "to": "wxid_friend", "content": "Hello, this is a test message"},
timeout=10,
)
print(resp.json()) # {"code": 0, "data": {"msg_id": "..."}}HttpClient client = HttpClient.newHttpClient();
String body = """
{"account_id":"acc_123","to":"wxid_friend","content":"Hello, this is a test message"}
""";
HttpRequest req = HttpRequest.newBuilder(URI.create("https://api.wechatapilabs.com/v1/message/send_text"))
.header("Authorization", "Bearer YOUR_API_KEY")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
System.out.println(client.send(req, HttpResponse.BodyHandlers.ofString()).body());const res = await fetch("https://api.wechatapilabs.com/v1/message/send_text", {
method: "POST",
headers: { Authorization: "Bearer YOUR_API_KEY", "Content-Type": "application/json" },
body: JSON.stringify({ account_id: "acc_123", to: "wxid_friend", content: "Hello, this is a test message" }),
});
console.log(await res.json());body := strings.NewReader(`{"account_id":"acc_123","to":"wxid_friend","content":"Hello, this is a test message"}`)
req, _ := http.NewRequest("POST", "https://api.wechatapilabs.com/v1/message/send_text", body)
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil { log.Fatal(err) }
defer resp.Body.Close()
out, _ := io.ReadAll(resp.Body)
fmt.Println(string(out))curl -X POST https://api.wechatapilabs.com/v1/message/send_text \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"account_id":"acc_123","to":"wxid_friend","content":"Hello, this is a test message"}' Account & login endpoints
Get login QR code
Generate a login QR code for a new hosted account. Scan it with the phone to bring the account online; the result arrives via the account.online webhook.
| Parameter | Type | Required | Description |
|---|---|---|---|
type | string | Yes | personal or wecom |
callback_url | string | No | Webhook URL for this account; defaults to the console setting |
Response example
{
"code": 0,
"message": "ok",
"request_id": "req_5c1e",
"data": {
"account_id": "acc_123",
"qrcode_url": "https://.../qr.png",
"expire_in": 120
}
}Get account status
Check whether a hosted account is online, its device and last heartbeat.
| Parameter | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Hosted account ID, from the console or the login response |
Response example
{
"code": 0,
"message": "ok",
"request_id": "req_5c1e",
"data": {
"account_id": "acc_123",
"online": true,
"nickname": "Support Bot",
"last_heartbeat": 1764172800
}
}Messages endpoints
Send text
Send a text message to a friend or group. In groups, use at to @mention members.
| Parameter | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Hosted account ID, from the console or the login response |
to | string | Yes | Friend wxid or group ID (ends with @chatroom) |
content | string | Yes | Message content, up to 2,000 characters |
at | string[] | No | Member wxids to @mention in a group; ["all"] mentions everyone (owner or admin only) |
Response example
{
"code": 0,
"message": "ok",
"request_id": "req_5c1e",
"data": {
"msg_id": "m_9f2c1a"
}
}Send image
Send an image by URL or Base64.
| Parameter | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Hosted account ID, from the console or the login response |
to | string | Yes | Friend wxid or group ID |
image_url | string | One of | Publicly reachable image URL |
image_base64 | string | One of | Base64 image data, up to 10 MB |
Response example
{
"code": 0,
"message": "ok",
"request_id": "req_5c1e",
"data": {
"msg_id": "m_9f2c1b"
}
}Send file
Send a file shown with file_name.
| Parameter | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Hosted account ID, from the console or the login response |
to | string | Yes | Friend wxid or group ID |
file_url | string | Yes | File URL |
file_name | string | Yes | Displayed file name |
Response example
{
"code": 0,
"message": "ok",
"request_id": "req_5c1e",
"data": {
"msg_id": "m_9f2c1c"
}
}Send link card
Send a link card with title, description and thumbnail.
| Parameter | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Hosted account ID, from the console or the login response |
to | string | Yes | Friend wxid or group ID |
title | string | Yes | Title |
desc | string | No | Description |
url | string | Yes | Target URL |
thumb_url | string | No | Thumbnail URL |
Response example
{
"code": 0,
"message": "ok",
"request_id": "req_5c1e",
"data": {
"msg_id": "m_9f2c1d"
}
}Recall message
Recall a message sent by this account within 2 minutes.
| Parameter | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Hosted account ID, from the console or the login response |
msg_id | string | Yes | msg_id returned by a send call |
Response example
{
"code": 0,
"message": "ok",
"request_id": "req_5c1e",
"data": {
"revoked": true
}
}Contacts endpoints
List friends
List friends with remarks and tags, paginated.
| Parameter | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Hosted account ID, from the console or the login response |
cursor | string | No | Pagination cursor; omit on first call |
limit | int | No | Page size, default 100, max 500 |
Response example
{
"code": 0,
"message": "ok",
"request_id": "req_5c1e",
"data": {
"items": [
{
"wxid": "wxid_abc",
"nickname": "Alice",
"remark": "Customer - Alice",
"tags": [
"VIP"
]
}
],
"next_cursor": "c_2"
}
}Accept friend request
Accept a request received via the friend.request webhook.
| Parameter | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Hosted account ID, from the console or the login response |
ticket | string | Yes | Ticket from the webhook |
remark | string | No | Remark to set after accepting |
Response example
{
"code": 0,
"message": "ok",
"request_id": "req_5c1e",
"data": {
"wxid": "wxid_new"
}
}Set remark & tags
Update a friend's remark and tags.
| Parameter | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Hosted account ID, from the console or the login response |
wxid | string | Yes | Friend wxid |
remark | string | No | New remark |
tags | string[] | No | Tags; replaces existing tags |
Response example
{
"code": 0,
"message": "ok",
"request_id": "req_5c1e",
"data": {
"ok": true
}
}Groups endpoints
Create group
Create a group chat with at least 2 friends.
| Parameter | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Hosted account ID, from the console or the login response |
members | string[] | Yes | Friend wxids |
name | string | No | Group name |
Response example
{
"code": 0,
"message": "ok",
"request_id": "req_5c1e",
"data": {
"group_id": "123456@chatroom"
}
}Invite members
Invite friends to a group; groups over 40 members receive an invitation link.
| Parameter | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Hosted account ID, from the console or the login response |
group_id | string | Yes | Group ID |
members | string[] | Yes | Friend wxids |
Response example
{
"code": 0,
"message": "ok",
"request_id": "req_5c1e",
"data": {
"invited": 3
}
}Remove members
Requires the account to be group owner or admin.
| Parameter | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Hosted account ID, from the console or the login response |
group_id | string | Yes | Group ID |
members | string[] | Yes | Member wxids to remove |
Response example
{
"code": 0,
"message": "ok",
"request_id": "req_5c1e",
"data": {
"removed": 1
}
}Post announcement
Requires the account to be group owner or admin.
| Parameter | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Hosted account ID, from the console or the login response |
group_id | string | Yes | Group ID |
content | string | Yes | Announcement text |
Response example
{
"code": 0,
"message": "ok",
"request_id": "req_5c1e",
"data": {
"ok": true
}
}List group members
List members and their group nicknames.
| Parameter | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Hosted account ID, from the console or the login response |
group_id | string | Yes | Group ID |
Response example
{
"code": 0,
"message": "ok",
"request_id": "req_5c1e",
"data": {
"items": [
{
"wxid": "wxid_abc",
"display_name": "Alice"
}
],
"total": 128
}
}Moments endpoints
Post a Moment
Post a text or image Moment with up to 9 images.
| Parameter | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Hosted account ID, from the console or the login response |
content | string | No | Text |
images | string[] | No | Image URLs |
visible_tags | string[] | No | Visible only to friends with these tags |
Response example
{
"code": 0,
"message": "ok",
"request_id": "req_5c1e",
"data": {
"moment_id": "mo_7d1"
}
}WeCom endpoints
Send to external group
Send to an external group with customers. Types: text, image, file, link, miniprogram.
| Parameter | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Hosted account ID, from the console or the login response |
group_id | string | Yes | External group ID |
type | string | Yes | Message type |
payload | object | Yes | Message content for the type; same fields as personal send endpoints |
at | string[] | No | Member IDs to @mention |
Response example
{
"code": 0,
"message": "ok",
"request_id": "req_5c1e",
"data": {
"msg_id": "wm_31a"
}
}List customers
List this member's customers with remarks and corporate tags.
| Parameter | Type | Required | Description |
|---|---|---|---|
account_id | string | Yes | Hosted account ID, from the console or the login response |
cursor | string | No | Pagination cursor |
limit | int | No | Page size, default 100 |
Response example
{
"code": 0,
"message": "ok",
"request_id": "req_5c1e",
"data": {
"items": [
{
"external_id": "wo_abc",
"name": "Bob",
"corp_name": "Acme Ltd",
"tags": [
"Lead"
]
}
],
"next_cursor": null
}
}Webhook events
Once a webhook URL is set in the console or login call, events are POSTed as JSON. Each request carries X-Signature, the hex HMAC-SHA256(webhook secret, body); verify it before processing. Return HTTP 200 within 5 seconds, otherwise we retry 3 times after 10 seconds, 60 seconds and 5 minutes.
message.received
New message (one-to-one or group)
{
"event": "message.received",
"account_id": "acc_123",
"data": {
"msg_id": "m_1",
"from": "wxid_abc",
"room_id": "123456@chatroom",
"type": "text",
"content": "@Support Bot hi",
"at_me": true,
"time": 1764172800
}
}friend.request
Friend request received
{
"event": "friend.request",
"account_id": "acc_123",
"data": {
"from": "wxid_new",
"nickname": "Carol",
"hello": "Hi, I'm Carol",
"ticket": "t_8a2"
}
}group.member_join
New member joined a group
{
"event": "group.member_join",
"account_id": "acc_123",
"data": {
"room_id": "123456@chatroom",
"members": [
"wxid_x"
],
"inviter": "wxid_abc"
}
}account.online / account.offline
Account came online or logged out
{
"event": "account.offline",
"account_id": "acc_123",
"data": {
"reason": "logout_on_phone",
"time": 1764172800
}
}Error codes
| code | Meaning | What to do |
|---|---|---|
0 | Success | |
40001 | Invalid or expired API key | Generate a new key in the console |
40003 | account_id not found or not owned by this key | Check the account ID and key match |
40010 | Missing or malformed parameter | Check required fields and types against the docs |
42001 | Account offline | Call the login endpoint again or subscribe to account.offline |
42002 | Target friend or group not found | Confirm the ID via the friends or groups endpoint |
43001 | No group admin permission | Requires group owner or admin |
45009 | Rate limit exceeded | Slow down and retry after retry_after seconds |
46001 | Platform risk control triggered | Pause proactive actions on this account for 24 hours and contact support |
50000 | Internal error | Retry later; if it persists, contact support with the request_id |
Want every endpoint and the full parameter reference? Leave your details and we'll send you the complete API docs.
Need an endpoint that isn't listed? Most requests can be built.