diff --git a/tests/test_organizations.py b/tests/test_organizations.py index b7cf5322..ddd08060 100644 --- a/tests/test_organizations.py +++ b/tests/test_organizations.py @@ -109,7 +109,7 @@ def test_get_organization( assert request_kwargs["method"] == "get" assert request_kwargs["url"].endswith("/organizations/organization_id") - def test_get_organization_by_lookup_key( + def test_get_organization_by_external_id( self, mock_organization, capture_and_mock_http_client_request ): request_kwargs = capture_and_mock_http_client_request( @@ -117,12 +117,12 @@ def test_get_organization_by_lookup_key( ) organization = syncify( - self.organizations.get_organization_by_lookup_key(lookup_key="test") + self.organizations.get_organization_by_external_id(external_id="test") ) assert organization.dict() == mock_organization assert request_kwargs["method"] == "get" - assert request_kwargs["url"].endswith("/organizations/by_lookup_key/test") + assert request_kwargs["url"].endswith("/organizations/external_id/test") def test_create_organization_with_domain_data( self, mock_organization, capture_and_mock_http_client_request diff --git a/tests/test_user_management.py b/tests/test_user_management.py index f0aed6e9..c6819ae6 100644 --- a/tests/test_user_management.py +++ b/tests/test_user_management.py @@ -392,6 +392,26 @@ def test_get_user(self, mock_user, capture_and_mock_http_client_request): assert user.profile_picture_url == "https://example.com/profile-picture.jpg" assert user.last_sign_in_at == "2021-06-25T19:07:33.155Z" + def test_get_user_by_external_id( + self, mock_user, capture_and_mock_http_client_request + ): + request_kwargs = capture_and_mock_http_client_request( + self.http_client, mock_user, 200 + ) + + external_id = "external-id" + user = syncify( + self.user_management.get_user_by_external_id(external_id=external_id) + ) + + assert request_kwargs["url"].endswith( + f"user_management/users/external_id/{external_id}" + ) + assert request_kwargs["method"] == "get" + assert user.id == "user_01H7ZGXFP5C6BBQY6Z7277ZCT0" + assert user.profile_picture_url == "https://example.com/profile-picture.jpg" + assert user.last_sign_in_at == "2021-06-25T19:07:33.155Z" + def test_list_users_auto_pagination( self, mock_users_multiple_pages, diff --git a/workos/organizations.py b/workos/organizations.py index 4ff234f5..42b781e4 100644 --- a/workos/organizations.py +++ b/workos/organizations.py @@ -60,13 +60,13 @@ def get_organization(self, organization_id: str) -> SyncOrAsync[Organization]: """ ... - def get_organization_by_lookup_key( - self, lookup_key: str + def get_organization_by_external_id( + self, external_id: str ) -> SyncOrAsync[Organization]: - """Gets details for a single Organization by lookup key + """Gets details for a single Organization by external id Args: - lookup_key (str): Organization's lookup key + external_id (str): Organization's external id Returns: Organization: Organization response from WorkOS @@ -125,7 +125,6 @@ def delete_organization(self, organization_id: str) -> SyncOrAsync[None]: class Organizations(OrganizationsModule): - _http_client: SyncHTTPClient def __init__(self, http_client: SyncHTTPClient): @@ -167,9 +166,9 @@ def get_organization(self, organization_id: str) -> Organization: return Organization.model_validate(response) - def get_organization_by_lookup_key(self, lookup_key: str) -> Organization: + def get_organization_by_external_id(self, external_id: str) -> Organization: response = self._http_client.request( - "organizations/by_lookup_key/{lookup_key}".format(lookup_key=lookup_key), + "organizations/external_id/{external_id}".format(external_id=external_id), method=REQUEST_METHOD_GET, ) @@ -237,7 +236,6 @@ def list_organization_roles(self, organization_id: str) -> RoleList: class AsyncOrganizations(OrganizationsModule): - _http_client: AsyncHTTPClient def __init__(self, http_client: AsyncHTTPClient): @@ -279,9 +277,9 @@ async def get_organization(self, organization_id: str) -> Organization: return Organization.model_validate(response) - async def get_organization_by_lookup_key(self, lookup_key: str) -> Organization: + async def get_organization_by_external_id(self, external_id: str) -> Organization: response = await self._http_client.request( - "organizations/by_lookup_key/{lookup_key}".format(lookup_key=lookup_key), + "organizations/external_id/{external_id}".format(external_id=external_id), method=REQUEST_METHOD_GET, ) diff --git a/workos/types/organizations/organization.py b/workos/types/organizations/organization.py index 23186498..03ee74d0 100644 --- a/workos/types/organizations/organization.py +++ b/workos/types/organizations/organization.py @@ -6,5 +6,5 @@ class Organization(OrganizationCommon): allow_profiles_outside_organization: bool domains: Sequence[OrganizationDomain] - lookup_key: Optional[str] = None stripe_customer_id: Optional[str] = None + external_id: Optional[str] = None diff --git a/workos/types/user_management/user.py b/workos/types/user_management/user.py index ca1e4c1b..5b2a3595 100644 --- a/workos/types/user_management/user.py +++ b/workos/types/user_management/user.py @@ -15,3 +15,4 @@ class User(WorkOSModel): last_sign_in_at: Optional[str] = None created_at: str updated_at: str + external_id: Optional[str] = None diff --git a/workos/user_management.py b/workos/user_management.py index c684eb4e..a7131bc1 100644 --- a/workos/user_management.py +++ b/workos/user_management.py @@ -66,6 +66,7 @@ USER_PATH = "user_management/users" USER_DETAIL_PATH = "user_management/users/{0}" +USER_DETAIL_BY_EXTERNAL_ID_PATH = "user_management/users/external_id/{0}" ORGANIZATION_MEMBERSHIP_PATH = "user_management/organization_memberships" ORGANIZATION_MEMBERSHIP_DETAIL_PATH = "user_management/organization_memberships/{0}" ORGANIZATION_MEMBERSHIP_DEACTIVATE_PATH = ( @@ -137,6 +138,16 @@ def get_user(self, user_id: str) -> SyncOrAsync[User]: """ ... + def get_user_by_external_id(self, external_id: str) -> SyncOrAsync[User]: + """Get the details of an existing user. + + Args: + external_id (str): The user's external id + Returns: + User: User response from WorkOS. + """ + ... + def list_users( self, *, @@ -389,7 +400,6 @@ def get_authorization_url( ) if connection_id is not None: - params["connection_id"] = connection_id if organization_id is not None: params["organization_id"] = organization_id @@ -860,6 +870,14 @@ def get_user(self, user_id: str) -> User: return User.model_validate(response) + def get_user_by_external_id(self, external_id: str) -> User: + response = self._http_client.request( + USER_DETAIL_BY_EXTERNAL_ID_PATH.format(external_id), + method=REQUEST_METHOD_GET, + ) + + return User.model_validate(response) + def list_users( self, *, @@ -1464,6 +1482,14 @@ async def get_user(self, user_id: str) -> User: return User.model_validate(response) + async def get_user_by_external_id(self, external_id: str) -> User: + response = await self._http_client.request( + USER_DETAIL_BY_EXTERNAL_ID_PATH.format(external_id), + method=REQUEST_METHOD_GET, + ) + + return User.model_validate(response) + async def list_users( self, *,