Skip to content

Commit 6b82725

Browse files
authored
Add getUserByExternalId (#1229)
## Description Convenience method for accessing the associated api endpoint ## Documentation Does this require changes to the WorkOS Docs? E.g. the [API Reference](https://workos.com/docs/reference) or code snippets need updates. ``` [x] Yes ``` If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required. ^ docs are coming but looking to get this out in a preview release ahead of time.
1 parent 495af31 commit 6b82725

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/user-management/user-management.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,29 @@ describe('UserManagement', () => {
5959
});
6060
});
6161

62+
describe('getUserByExternalId', () => {
63+
it('sends a Get User request', async () => {
64+
const externalId = 'user_external_id';
65+
fetchOnce({ ...userFixture, external_id: externalId });
66+
67+
const user = await workos.userManagement.getUserByExternalId(externalId);
68+
expect(fetchURL()).toContain(
69+
`/user_management/users/external_id/${externalId}`,
70+
);
71+
expect(user).toMatchObject({
72+
object: 'user',
73+
id: 'user_01H5JQDV7R7ATEYZDEG0W5PRYS',
74+
75+
profilePictureUrl: 'https://example.com/profile_picture.jpg',
76+
firstName: 'Test 01',
77+
lastName: 'User',
78+
emailVerified: true,
79+
lastSignInAt: '2023-07-18T02:07:19.911Z',
80+
externalId,
81+
});
82+
});
83+
});
84+
6285
describe('listUsers', () => {
6386
it('lists users', async () => {
6487
fetchOnce(listUsersFixture);

src/user-management/user-management.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ export class UserManagement {
199199
return deserializeUser(data);
200200
}
201201

202+
async getUserByExternalId(externalId: string): Promise<User> {
203+
const { data } = await this.workos.get<UserResponse>(
204+
`/user_management/users/external_id/${externalId}`,
205+
);
206+
207+
return deserializeUser(data);
208+
}
209+
202210
async listUsers(options?: ListUsersOptions): Promise<AutoPaginatable<User>> {
203211
return new AutoPaginatable(
204212
await fetchAndDeserialize<UserResponse, User>(

0 commit comments

Comments
 (0)