How to manage contacts in WeChat Enterprise Account Development

How to manage contacts in WeChat Enterprise Account Development

The enterprise address book has completely open interfaces, and your applications can call these interfaces to manage departments, members, and tags.

Your app can also send messages using departments, members, or tags, or change the visibility of your app.

Please note that the upper limit of the number of direct employees in each department is 1,000 ; for security reasons, some interfaces require explicit authorization on the management side .

1. Management Department

1. Create a department

  • Request Instructions

Https request method: POST

https://qyapi.weixin.qq.com/cgi-bin/department/create?access_token=ACCESS_TOKEN

The request packet structure is:

  1. {
  2. "name" : "Mailbox Product Group" ,
  3. "parentid" : "1"  
  4. }
  • Parameter Description
parameter must illustrate
access_token yes Call interface credentials
name yes Department name. The length is limited to 1 to 64 characters.
parentid yes The parent department id. The root department id is 1
  • Permissions

The administrator must have the interface permission of "Operate Address Book" and the management permission of the parent department.

  • Return results
    1. {
    2. "errcode" : 0 ,
    3. "errmsg" : "created" ,
    4. "id" : 2  
    5. }
parameter illustrate
errcode Return Code
errmsg A text description of the return code
id The id of the department created.

2. Update department

  • Request Instructions

Https request method: POST

https://qyapi.weixin.qq.com/cgi-bin/department/update?access_token=ACCESS_TOKEN

The request packet structure is (if a non-required field is not specified, the previous setting value of the field will not be updated):

  1. {
  2. "id" : 2 ,
  3. "name" : "Mailbox Product Department"  
  4. }
  • Parameter Description
parameter must illustrate
access_token yes Call interface credentials
id yes Department id.
name no The updated department name. The length is limited to 0 to 64 characters. Specify this parameter when modifying the department name.
  • Permissions

The administrator must have the interface permission of "Operate Address Book" and the management permission of the department.

  • Return results
    1. {
    2. "errcode" : 0 ,
    3. "errmsg" : "updated"  
    4. }

3. Delete a department

  • Request Instructions

Https request method: GET

https://qyapi.weixin.qq.com/cgi-bin/department/delete?access_token=ACCESS_TOKEN&id=1&id=2

  • Parameter Description
parameter must illustrate
access_token yes Call interface credentials
id yes Department ID. (Note: You cannot delete the root department; you cannot delete a department that has sub-departments or members)
  • Permissions

The administrator must have the interface permission of "Operate Address Book" and the management permission of the department.

  • Return results
    1. {
    2. "errcode" : 0 ,
    3. "errmsg" : "deleted"  
    4. }

4. Get the department list

  • Request Instructions

Https request method: GET

https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=ACCESS_TOKEN

  • Parameter Description
parameter must illustrate
access_token yes Call interface credentials
  • Permissions

The administrator must have the interface permission to 'get department list' and the permission to view departments.

  • Return results
    1. {
    2. "errcode" : 0 ,
    3. "errmsg" : "ok" ,
    4. "department" : [
    5. {
    6. "id" : 1 ,
    7. "name" : "Guangzhou R&D Center" ,
    8. "parentid" : 0  
    9. },
    10. {
    11. "id" : 2  
    12. "name" : "Mailbox Product Department" ,
    13. "parentid" : 1  
    14. }
    15. ]
    16. }
parameter illustrate
errcode Return Code
errmsg A text description of the return code
department Department List Data
id Department ID
name Department Name
parentid The parent department id. The root department is 1

#p#

2. Management members

1. Create members

  • Request Instructions

Https request method: POST

https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token=ACCESS_TOKEN

The request packet structure is:

  1. {
  2. "userid" : "zhangsan" ,
  3. "name" : "Zhang San" ,
  4. "department" : [ 1 , 2 ],
  5. "position" : "Product Manager" ,
  6. "mobile" : "15913215421" ,
  7. "gender" : 1 ,
  8. "tel" : "62394" ,
  9. "email" : "[email protected]" ,
  10. "weixinid" : "zhangsan4dev"  
  11. }
  • Parameter Description
parameter must illustrate
access_token yes Call interface credentials
userid yes Employee UserID. Corresponding to the management account, must be unique within the company
name yes Member name. Length is 1 to 64 characters.
department no List of department IDs to which the member belongs. Note that the upper limit for direct employees in each department is 1,000.
position no Position information. Length is 0~64 characters
mobile no Mobile phone number. Must be unique within the company. Mobile/weixinid/email cannot be empty at the same time.
gender no Gender. Gender=0 means male, =1 means female. Default gender=0
tel no Office phone number. Length is 0 to 64 characters.
email no Email address. Length is 0 to 64 characters. Must be unique within the company
weixinid no WeChat ID. Must be unique within the company
  • Permissions

The administrator must have the interface permission to "operate the address book" and the management permission for the designated department.

  • Return results
    1. {
    2. "errcode" : 0 ,
    3. "errmsg" : "created"  
    4. }

2. Update members

  • Request Instructions

Https request method: POST

https://qyapi.weixin.qq.com/cgi-bin/user/update?access_token=ACCESS_TOKEN

The request packet example is as follows (if a non-required field is not specified, the previous setting value of the field will not be updated):

  1. {
  2. "userid" : "zhangsan" ,
  3. "name" : "Li Si" ,
  4. "department" : [1],
  5. "position" : "Backend Engineer" ,
  6. "mobile" : "15913215421" ,
  7. "gender" : 1,
  8. "tel" : "62394" ,
  9. "email" : "[email protected]" ,
  10. "weixinid" : "lisifordev" ,
  11. "enable" : 1
  12. }
  • Parameter Description
parameter must illustrate
access_token yes Call interface credentials
userid yes Employee UserID. Corresponding to the management account, must be unique within the company
name no Member name. Length is 0~64 characters
department no List of department IDs to which the member belongs. Note that the upper limit for direct employees in each department is 1,000.
position no Position information. Length is 0~64 characters
mobile no Mobile phone number. Must be unique within the company. The updated member's mobile/weixinid/email cannot be empty at the same time
gender no Gender. Gender=0 means male, =1 means female. Default gender=0
tel no Office phone number. Length is 0 to 64 characters. Must be unique within the company
email no Email address. Length is 0 to 64 characters. Must be unique within the company
weixinid no WeChat ID. Must be unique within the company
enable no Enable/disable member. 1 means enable member, 0 means disable member
  • Permissions

Administrators must have interface permissions for "operating the address book" and management permissions for designated departments and members.

  • Return results
    1. {
    2. "errcode" : 0 ,
    3. "errmsg" : "updated"  
    4. }

3. Delete members

  • Request Instructions

Https request method: GET

https://qyapi.weixin.qq.com/cgi-bin/user/delete?access_token=ACCESS_TOKEN&userid=lisi

  • Parameter Description
parameter must illustrate
access_token yes Call interface credentials
userid yes Employee UserID. Corresponding to the management account
  • Permissions

Administrators must have interface permissions for "operating the address book" and management permissions for designated departments and members.

  • Return results
    1. {
    2. "errcode" : 0 ,
    3. "errmsg" : "deleted"  
    4. }

4. Get members

  • Request Instructions

Https request method: GET

https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&userid=lisi

  • Parameter Description
parameter must illustrate
access_token yes Call interface credentials
userid yes Employee UserID
  • Return results
    1. {
    2. "errcode" : 0 ,
    3. "errmsg" : "ok" ,
    4. "userid" : "zhangsan" ,
    5. "name" : "Li Si" ,
    6. "department" : [ 1 , 2 ],
    7. "position" : "Backend Engineer" ,
    8. "mobile" : "15913215421" ,
    9. "gender" : 1 ,
    10. "tel" : "62394" ,
    11. "email" : "[email protected]" ,
    12. "weixinid" : "lisifordev" ,
    13. "avatar" : "http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0" ,
    14. "status" : 1  
    15. }
parameter illustrate
errcode Return Code
errmsg A text description of the return code
userid Employee UserID
name Member Name
department Member department ID list
position Job Information
mobile phone number
gender Gender. Gender=0 means male, =1 means female
tel Office Phone
email Mail
weixinid WeChat ID
avatar Avatar URL. Note: If you want to get a thumbnail, just change the "/0" in the URL to "/64".
status Follow status: 1 = Followed, 2 = Frozen, 4 = Not followed
  • Permissions

Administrators must have the 'Get Members' interface permission and the member viewing permission.

5. Get department members

  • Request Instructions

Https request method: GET

https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=ACCESS_TOKEN&department_id=1&fetch_child=0&status=0

  • Parameter Description
parameter must illustrate
access_token yes Call interface credentials
department_id yes Get the department ID
fetch_child no 1/0: Whether to recursively obtain members under the sub-department
status no 0 gets all employees, 1 gets the list of followed members, 2 gets the list of disabled members, 4 gets the list of unfollowed members. Status can be superimposed
  • Permissions

Administrators must have the interface permission to 'get department members' and the viewing permission for the specified department.

  • Return results
    1. {
    2. "errcode" : 0 ,
    3. "errmsg" : "ok" ,
    4. "userlist" : [
    5. {
    6. "userid" : "zhangsan" ,
    7. "name" : "Li Si"  
    8. }
    9. ]
    10. }
parameter illustrate
errcode Return Code
errmsg A text description of the return code
userlist Members List
userid Employee UserID
name Member Name

#p#

3. Manage Tags

1. Create tags

  • Request Instructions

Https request method: POST

https://qyapi.weixin.qq.com/cgi-bin/tag/create?access_token=ACCESS_TOKEN

Note: The tag lock is unlocked by default.

The request packet structure is:

  1. {
  2. "tagname" : "UI"  
  3. }
  • Parameter Description
parameter must illustrate
access_token yes Call interface credentials
tagname yes Tag name. The length is 1 to 64 characters. The tag name cannot be the same as other tags in the same group or the global tag name.
  • Permissions

No limitation.

  • Return results
    1. {
    2. "errcode" : 0 ,
    3. "errmsg" : "created"  
    4. "tagid" : "1"  
    5. }

2. Update the label name

  • Request Instructions

Https request method: POST

https://qyapi.weixin.qq.com/cgi-bin/tag/update?access_token=ACCESS_TOKEN

The following is an example of a request packet:

  1. {
  2. "tagid" : "1" ,
  3. "tagname" : "UI design"  
  4. }
  • Parameter Description
parameter must illustrate
access_token yes Call interface credentials
tagid yes Tag ID
tagname yes Tag name. Maximum length is 64 characters.
  • Permissions

The administrator must be the creator of the specified tag.

  • Return results
    1. {
    2. "errcode" : 0 ,
    3. "errmsg" : "updated"  
    4. }

3. Delete tags

  • Request Instructions

Https request method: GET

https://qyapi.weixin.qq.com/cgi-bin/tag/delete?access_token=ACCESS_TOKEN&tagid=1

  • Parameter Description
parameter must illustrate
access_token yes Call interface credentials
tagid yes Tag ID
  • Permissions

The administrator must be the creator of the specified tag, and the member list of the tag must be empty.

  • Return results
    1. {
    2. "errcode" : 0 ,
    3. "errmsg" : "deleted"  
    4. }

4. Get tag members

  • Request Instructions

Https request method: GET

https://qyapi.weixin.qq.com/cgi-bin/tag/get?access_token=ACCESS_TOKEN&tagid=1

  • Parameter Description
parameter must illustrate
access_token yes Call interface credentials
tagid yes Tag ID
  • Permissions

The administrator must have the "Get Tag Members" interface permission, and the tag must be visible to the administrator; the returned list only includes members under the administrator's jurisdiction.

  • Return results
    1. {
    2. "errcode" : 0 ,
    3. "errmsg" : "ok" ,
    4. "userlist" : [
    5. {
    6. "userid" : "zhangsan" ,
    7. "name" : "Li Si"  
    8. }
    9. ]
    10. }
parameter illustrate
errcode Error Code
errmsg Error message
userlist Members List
userid Employee UserID

5. Add tag members

  • Request Instructions

Https request method: POST

https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers?access_token=ACCESS_TOKEN

The following is an example of a request packet:

  1. {
  2. "tagid" : "1" ,
  3. "userlist" :[ "user1" , "user2" ]
  4. }
  • Parameter Description
parameter must illustrate
access_token yes Call interface credentials
tagid yes Tag ID
userlist yes Company employee ID list
  • Permissions

Tags are visible to administrators and are not locked, and members are under the administrator's jurisdiction.

  • Return results

a) Return if correct

  1. {
  2. "errcode" : 0 ,
  3. "errmsg" : "ok"  
  4. }

b) If part of the userid is illegal, return

  1. {
  2. "errcode" : 0 ,
  3. "errmsg" : "invalid userlist failed"  
  4. "invalidlist" : "usr1|usr2|usr"  
  5. }

c) Return when all the userids are invalid

  1. {
  2. "errcode" : 40070 ,
  3. "errmsg" : "all list invalid "  
  4. }
parameter illustrate
errcode Error Code
errmsg Error message
invalidlist A list of employee IDs that are not within the scope of the permission, separated by "|"

6. Delete tag members

  • Request Instructions

Https request method: POST

https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers?access_token=ACCESS_TOKEN

The request packet is as follows

  1. {
  2. "tagid" : "1" ,
  3. "userlist" :[ "user1" , "user2" ]
  4. }
  • Parameter Description
parameter must illustrate
access_token yes Call interface credentials
tagid yes Tag ID
userlist yes Company employee ID list
  • Permissions

Tags are visible to administrators and are not locked, and members are under the administrator's jurisdiction.

  • Return results

a) Return if correct

  1. {
  2. "errcode" : 0 ,
  3. "errmsg" : "deleted"  
  4. }

b) If part of the userid is illegal, return

  1. {
  2. "errcode" : 0 ,
  3. "errmsg" : "invalid userlist failed"  
  4. "invalidlist" : "usr1|usr2|usr"  
  5. }

c) Return when all the contained userids are invalid

  1. {
  2. "errcode" : 40031 ,
  3. "errmsg" : "all list invalid"  
  4. }
parameter illustrate
errcode Error Code
errmsg Error message
invalidlist A list of employee IDs that are not within the authorized scope or are illegal, separated by "|"

<<:  Should Apple open source Swift? Seven reasons for and against

>>:  Google engineers teach: Top 10 things new developers must invest in

Recommend

How to advertise in Douyin?

1. Traffic dividend channels Any place with traff...

Duyun SEO training: What is SEO? Is it mysterious? / Actually anyone can do SEO

What is SEO? New SEO beginners feel that it is fu...

Why did trilobites become the "top stream" among ancient creatures?

If rocks are pages of history books recording the...

Principal Jiaqi's "Exclusive for Douyin Fans - Heart Hunting Plan"

Principal Jiaqi's "Douyin Fans Exclusive...

Finding a needle in a haystack! New discoveries in the universe

A research team composed of American and European...

How to operate “private domain traffic” in circle of friends!

The topic of private domain traffic has become in...

Review of the event operation planning process!

The essence of an event is communication, but the...

Analysis of the operational process of Tik Tok advertising promotion model!

How are advertisements for products searched on J...