Skip to content

Commit fddb564

Browse files
authored
Add Show Many Users by External IDs (#92) (#93)
1 parent 2f39530 commit fddb564

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

zendesk/user.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (c *client) ShowUser(id int64) (*User, error) {
6767
return out.User, err
6868
}
6969

70-
// ShowManyUsers accepts a comma-separated list of user ids or external ids.
70+
// ShowManyUsers accepts a comma-separated list of user ids.
7171
//
7272
// Zendesk Core API docs: https://developer.zendesk.com/rest_api/docs/support/users#show-many-users
7373
func (c *client) ShowManyUsers(ids []int64) ([]User, error) {
@@ -80,6 +80,14 @@ func (c *client) ShowManyUsers(ids []int64) ([]User, error) {
8080
err := c.get(fmt.Sprintf("/api/v2/users/show_many.json?ids=%s", strings.Join(sids, ",")), out)
8181
return out.Users, err
8282
}
83+
// ShowManyUsersByExternalIDs accepts a comma-separated list of external ids.
84+
//
85+
// Zendesk Core API docs: https://developer.zendesk.com/rest_api/docs/support/users#show-many-users
86+
func (c *client) ShowManyUsersByExternalIDs(externalIds []string) ([]User, error) {
87+
out := new(APIPayload)
88+
err := c.get(fmt.Sprintf("/api/v2/users/show_many.json?external_ids=%s", strings.Join(externalIds, ",")), out)
89+
return out.Users, err
90+
}
8391

8492
// CreateUser creates a user.
8593
//

zendesk/user_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ func TestUserCRUD(t *testing.T) {
5858
require.Equal(t, nilUser, found)
5959

6060
other, err := client.CreateUser(&User{
61-
Name: String(randString(16)),
62-
Email: String(randString(16) + "@example.com"),
61+
Name: String(randString(16)),
62+
Email: String(randString(16) + "@example.com"),
63+
ExternalID: String(randString(16)),
6364
})
6465
require.NoError(t, err)
6566

@@ -77,6 +78,10 @@ func TestUserCRUD(t *testing.T) {
7778
require.NoError(t, err)
7879
require.Len(t, many, 2)
7980

81+
manyExternal, err := client.ShowManyUsersByExternalIDs([]string{*created.ExternalID, *other.ExternalID})
82+
require.NoError(t, err)
83+
require.Len(t, manyExternal, 2)
84+
8085
tags, err := client.AddUserTags(*created.ID, []string{"a", "b"})
8186
require.NoError(t, err)
8287
require.Len(t, tags, 2)

zendesk/zendesk.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type Client interface {
7171
ShowLocaleByCode(string) (*Locale, error)
7272
ShowManyOrganizations([]int64) ([]Organization, error)
7373
ShowManyUsers([]int64) ([]User, error)
74+
ShowManyUsersByExternalIDs([]string) ([]User, error)
7475
ShowOrganization(int64) (*Organization, error)
7576
ShowTicket(int64) (*Ticket, error)
7677
ShowUser(int64) (*User, error)

0 commit comments

Comments
 (0)