Skip to content

Commit

Permalink
Add Show Many Users by External IDs (#92) (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wundark authored Apr 29, 2020
1 parent 2f39530 commit fddb564
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
10 changes: 9 additions & 1 deletion zendesk/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *client) ShowUser(id int64) (*User, error) {
return out.User, err
}

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

// CreateUser creates a user.
//
Expand Down
9 changes: 7 additions & 2 deletions zendesk/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ func TestUserCRUD(t *testing.T) {
require.Equal(t, nilUser, found)

other, err := client.CreateUser(&User{
Name: String(randString(16)),
Email: String(randString(16) + "@example.com"),
Name: String(randString(16)),
Email: String(randString(16) + "@example.com"),
ExternalID: String(randString(16)),
})
require.NoError(t, err)

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

manyExternal, err := client.ShowManyUsersByExternalIDs([]string{*created.ExternalID, *other.ExternalID})
require.NoError(t, err)
require.Len(t, manyExternal, 2)

tags, err := client.AddUserTags(*created.ID, []string{"a", "b"})
require.NoError(t, err)
require.Len(t, tags, 2)
Expand Down
1 change: 1 addition & 0 deletions zendesk/zendesk.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Client interface {
ShowLocaleByCode(string) (*Locale, error)
ShowManyOrganizations([]int64) ([]Organization, error)
ShowManyUsers([]int64) ([]User, error)
ShowManyUsersByExternalIDs([]string) ([]User, error)
ShowOrganization(int64) (*Organization, error)
ShowTicket(int64) (*Ticket, error)
ShowUser(int64) (*User, error)
Expand Down

0 comments on commit fddb564

Please sign in to comment.