WeChatAPI Labs

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.

Get the full API docs

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"} and code = 0 means success
  • Timestamps are Unix seconds
  • Default rate limit: 5 requests per second per account; over the limit returns 45009

Quick start

  1. Contact us for a test account and copy your API key from the console.
  2. Call Get login QR code, scan it with the phone and wait for the account.online webhook.
  3. 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": "..."}}

Account & login endpoints

Get login QR code

POST/v1/account/login_qrcode

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.

ParameterTypeRequiredDescription
typestringYespersonal or wecom
callback_urlstringNoWebhook 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

GET/v1/account/status

Check whether a hosted account is online, its device and last heartbeat.

ParameterTypeRequiredDescription
account_idstringYesHosted 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

POST/v1/message/send_text

Send a text message to a friend or group. In groups, use at to @mention members.

ParameterTypeRequiredDescription
account_idstringYesHosted account ID, from the console or the login response
tostringYesFriend wxid or group ID (ends with @chatroom)
contentstringYesMessage content, up to 2,000 characters
atstring[]NoMember 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

POST/v1/message/send_image

Send an image by URL or Base64.

ParameterTypeRequiredDescription
account_idstringYesHosted account ID, from the console or the login response
tostringYesFriend wxid or group ID
image_urlstringOne ofPublicly reachable image URL
image_base64stringOne ofBase64 image data, up to 10 MB

Response example

{
  "code": 0,
  "message": "ok",
  "request_id": "req_5c1e",
  "data": {
    "msg_id": "m_9f2c1b"
  }
}

Send file

POST/v1/message/send_file

Send a file shown with file_name.

ParameterTypeRequiredDescription
account_idstringYesHosted account ID, from the console or the login response
tostringYesFriend wxid or group ID
file_urlstringYesFile URL
file_namestringYesDisplayed file name

Response example

{
  "code": 0,
  "message": "ok",
  "request_id": "req_5c1e",
  "data": {
    "msg_id": "m_9f2c1c"
  }
}

Recall message

POST/v1/message/revoke

Recall a message sent by this account within 2 minutes.

ParameterTypeRequiredDescription
account_idstringYesHosted account ID, from the console or the login response
msg_idstringYesmsg_id returned by a send call

Response example

{
  "code": 0,
  "message": "ok",
  "request_id": "req_5c1e",
  "data": {
    "revoked": true
  }
}

Contacts endpoints

List friends

GET/v1/contact/friends

List friends with remarks and tags, paginated.

ParameterTypeRequiredDescription
account_idstringYesHosted account ID, from the console or the login response
cursorstringNoPagination cursor; omit on first call
limitintNoPage 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

POST/v1/contact/accept

Accept a request received via the friend.request webhook.

ParameterTypeRequiredDescription
account_idstringYesHosted account ID, from the console or the login response
ticketstringYesTicket from the webhook
remarkstringNoRemark to set after accepting

Response example

{
  "code": 0,
  "message": "ok",
  "request_id": "req_5c1e",
  "data": {
    "wxid": "wxid_new"
  }
}

Set remark & tags

POST/v1/contact/remark

Update a friend's remark and tags.

ParameterTypeRequiredDescription
account_idstringYesHosted account ID, from the console or the login response
wxidstringYesFriend wxid
remarkstringNoNew remark
tagsstring[]NoTags; replaces existing tags

Response example

{
  "code": 0,
  "message": "ok",
  "request_id": "req_5c1e",
  "data": {
    "ok": true
  }
}

Groups endpoints

Create group

POST/v1/group/create

Create a group chat with at least 2 friends.

ParameterTypeRequiredDescription
account_idstringYesHosted account ID, from the console or the login response
membersstring[]YesFriend wxids
namestringNoGroup name

Response example

{
  "code": 0,
  "message": "ok",
  "request_id": "req_5c1e",
  "data": {
    "group_id": "123456@chatroom"
  }
}

Invite members

POST/v1/group/invite

Invite friends to a group; groups over 40 members receive an invitation link.

ParameterTypeRequiredDescription
account_idstringYesHosted account ID, from the console or the login response
group_idstringYesGroup ID
membersstring[]YesFriend wxids

Response example

{
  "code": 0,
  "message": "ok",
  "request_id": "req_5c1e",
  "data": {
    "invited": 3
  }
}

Remove members

POST/v1/group/remove

Requires the account to be group owner or admin.

ParameterTypeRequiredDescription
account_idstringYesHosted account ID, from the console or the login response
group_idstringYesGroup ID
membersstring[]YesMember wxids to remove

Response example

{
  "code": 0,
  "message": "ok",
  "request_id": "req_5c1e",
  "data": {
    "removed": 1
  }
}

Post announcement

POST/v1/group/notice

Requires the account to be group owner or admin.

ParameterTypeRequiredDescription
account_idstringYesHosted account ID, from the console or the login response
group_idstringYesGroup ID
contentstringYesAnnouncement text

Response example

{
  "code": 0,
  "message": "ok",
  "request_id": "req_5c1e",
  "data": {
    "ok": true
  }
}

List group members

GET/v1/group/members

List members and their group nicknames.

ParameterTypeRequiredDescription
account_idstringYesHosted account ID, from the console or the login response
group_idstringYesGroup 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/v1/moment/post

Post a text or image Moment with up to 9 images.

ParameterTypeRequiredDescription
account_idstringYesHosted account ID, from the console or the login response
contentstringNoText
imagesstring[]NoImage URLs
visible_tagsstring[]NoVisible 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

POST/v1/wecom/group/send

Send to an external group with customers. Types: text, image, file, link, miniprogram.

ParameterTypeRequiredDescription
account_idstringYesHosted account ID, from the console or the login response
group_idstringYesExternal group ID
typestringYesMessage type
payloadobjectYesMessage content for the type; same fields as personal send endpoints
atstring[]NoMember IDs to @mention

Response example

{
  "code": 0,
  "message": "ok",
  "request_id": "req_5c1e",
  "data": {
    "msg_id": "wm_31a"
  }
}

List customers

GET/v1/wecom/customers

List this member's customers with remarks and corporate tags.

ParameterTypeRequiredDescription
account_idstringYesHosted account ID, from the console or the login response
cursorstringNoPagination cursor
limitintNoPage 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

codeMeaningWhat to do
0Success
40001Invalid or expired API keyGenerate a new key in the console
40003account_id not found or not owned by this keyCheck the account ID and key match
40010Missing or malformed parameterCheck required fields and types against the docs
42001Account offlineCall the login endpoint again or subscribe to account.offline
42002Target friend or group not foundConfirm the ID via the friends or groups endpoint
43001No group admin permissionRequires group owner or admin
45009Rate limit exceededSlow down and retry after retry_after seconds
46001Platform risk control triggeredPause proactive actions on this account for 24 hours and contact support
50000Internal errorRetry 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.