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 Https request method: POST https://qyapi.weixin.qq.com/cgi-bin/department/create?access_token=ACCESS_TOKEN The request packet structure is: - {
- "name" : "Mailbox Product Group" ,
- "parentid" : "1"
- }
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 |
The administrator must have the interface permission of "Operate Address Book" and the management permission of the parent department. - {
- "errcode" : 0 ,
- "errmsg" : "created" ,
- "id" : 2
- }
parameter | illustrate |
---|
errcode | Return Code | errmsg | A text description of the return code | id | The id of the department created. |
2. Update department 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): - {
- "id" : 2 ,
- "name" : "Mailbox Product Department"
- }
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. |
The administrator must have the interface permission of "Operate Address Book" and the management permission of the department. - {
- "errcode" : 0 ,
- "errmsg" : "updated"
- }
3. Delete a department Https request method: GET https://qyapi.weixin.qq.com/cgi-bin/department/delete?access_token=ACCESS_TOKEN&id=1&id=2 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) |
The administrator must have the interface permission of "Operate Address Book" and the management permission of the department. - {
- "errcode" : 0 ,
- "errmsg" : "deleted"
- }
4. Get the department list Https request method: GET https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=ACCESS_TOKEN parameter | must | illustrate |
---|
access_token | yes | Call interface credentials |
The administrator must have the interface permission to 'get department list' and the permission to view departments. - {
- "errcode" : 0 ,
- "errmsg" : "ok" ,
- "department" : [
- {
- "id" : 1 ,
- "name" : "Guangzhou R&D Center" ,
- "parentid" : 0
- },
- {
- "id" : 2
- "name" : "Mailbox Product Department" ,
- "parentid" : 1
- }
- ]
- }
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 Https request method: POST https://qyapi.weixin.qq.com/cgi-bin/user/create?access_token=ACCESS_TOKEN The request packet structure is: - {
- "userid" : "zhangsan" ,
- "name" : "Zhang San" ,
- "department" : [ 1 , 2 ],
- "position" : "Product Manager" ,
- "mobile" : "15913215421" ,
- "gender" : 1 ,
- "tel" : "62394" ,
- "email" : "[email protected]" ,
- "weixinid" : "zhangsan4dev"
- }
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 |
The administrator must have the interface permission to "operate the address book" and the management permission for the designated department. - {
- "errcode" : 0 ,
- "errmsg" : "created"
- }
2. Update members 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): - {
- "userid" : "zhangsan" ,
- "name" : "Li Si" ,
- "department" : [1],
- "position" : "Backend Engineer" ,
- "mobile" : "15913215421" ,
- "gender" : 1,
- "tel" : "62394" ,
- "email" : "[email protected]" ,
- "weixinid" : "lisifordev" ,
- "enable" : 1
- }
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 |
Administrators must have interface permissions for "operating the address book" and management permissions for designated departments and members. - {
- "errcode" : 0 ,
- "errmsg" : "updated"
- }
3. Delete members Https request method: GET https://qyapi.weixin.qq.com/cgi-bin/user/delete?access_token=ACCESS_TOKEN&userid=lisi parameter | must | illustrate |
---|
access_token | yes | Call interface credentials | userid | yes | Employee UserID. Corresponding to the management account |
Administrators must have interface permissions for "operating the address book" and management permissions for designated departments and members. - {
- "errcode" : 0 ,
- "errmsg" : "deleted"
- }
4. Get members Https request method: GET https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&userid=lisi parameter | must | illustrate |
---|
access_token | yes | Call interface credentials | userid | yes | Employee UserID |
- {
- "errcode" : 0 ,
- "errmsg" : "ok" ,
- "userid" : "zhangsan" ,
- "name" : "Li Si" ,
- "department" : [ 1 , 2 ],
- "position" : "Backend Engineer" ,
- "mobile" : "15913215421" ,
- "gender" : 1 ,
- "tel" : "62394" ,
- "email" : "[email protected]" ,
- "weixinid" : "lisifordev" ,
- "avatar" : "http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0" ,
- "status" : 1
- }
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 |
Administrators must have the 'Get Members' interface permission and the member viewing permission. 5. Get department members 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 | 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 |
Administrators must have the interface permission to 'get department members' and the viewing permission for the specified department. - {
- "errcode" : 0 ,
- "errmsg" : "ok" ,
- "userlist" : [
- {
- "userid" : "zhangsan" ,
- "name" : "Li Si"
- }
- ]
- }
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 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: - {
- "tagname" : "UI"
- }
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. |
No limitation. - {
- "errcode" : 0 ,
- "errmsg" : "created"
- "tagid" : "1"
- }
2. Update the label name 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: - {
- "tagid" : "1" ,
- "tagname" : "UI design"
- }
parameter | must | illustrate |
---|
access_token | yes | Call interface credentials | tagid | yes | Tag ID | tagname | yes | Tag name. Maximum length is 64 characters. |
The administrator must be the creator of the specified tag. - {
- "errcode" : 0 ,
- "errmsg" : "updated"
- }
3. Delete tags Https request method: GET https://qyapi.weixin.qq.com/cgi-bin/tag/delete?access_token=ACCESS_TOKEN&tagid=1 parameter | must | illustrate |
---|
access_token | yes | Call interface credentials | tagid | yes | Tag ID |
The administrator must be the creator of the specified tag, and the member list of the tag must be empty. - {
- "errcode" : 0 ,
- "errmsg" : "deleted"
- }
4. Get tag members Https request method: GET https://qyapi.weixin.qq.com/cgi-bin/tag/get?access_token=ACCESS_TOKEN&tagid=1 parameter | must | illustrate |
---|
access_token | yes | Call interface credentials | tagid | yes | Tag ID |
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. - {
- "errcode" : 0 ,
- "errmsg" : "ok" ,
- "userlist" : [
- {
- "userid" : "zhangsan" ,
- "name" : "Li Si"
- }
- ]
- }
parameter | illustrate |
---|
errcode | Error Code | errmsg | Error message | userlist | Members List | userid | Employee UserID |
5. Add tag members 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: - {
- "tagid" : "1" ,
- "userlist" :[ "user1" , "user2" ]
- }
parameter | must | illustrate |
---|
access_token | yes | Call interface credentials | tagid | yes | Tag ID | userlist | yes | Company employee ID list |
Tags are visible to administrators and are not locked, and members are under the administrator's jurisdiction. a) Return if correct - {
- "errcode" : 0 ,
- "errmsg" : "ok"
- }
b) If part of the userid is illegal, return - {
- "errcode" : 0 ,
- "errmsg" : "invalid userlist failed"
- "invalidlist" : "usr1|usr2|usr"
- }
c) Return when all the userids are invalid - {
- "errcode" : 40070 ,
- "errmsg" : "all list invalid "
- }
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 Https request method: POST https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers?access_token=ACCESS_TOKEN The request packet is as follows - {
- "tagid" : "1" ,
- "userlist" :[ "user1" , "user2" ]
- }
parameter | must | illustrate |
---|
access_token | yes | Call interface credentials | tagid | yes | Tag ID | userlist | yes | Company employee ID list |
Tags are visible to administrators and are not locked, and members are under the administrator's jurisdiction. a) Return if correct - {
- "errcode" : 0 ,
- "errmsg" : "deleted"
- }
b) If part of the userid is illegal, return - {
- "errcode" : 0 ,
- "errmsg" : "invalid userlist failed"
- "invalidlist" : "usr1|usr2|usr"
- }
c) Return when all the contained userids are invalid - {
- "errcode" : 40031 ,
- "errmsg" : "all list invalid"
- }
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 "|" | |