Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return organization's logo in organizations.get_async #81

Open
andrewli1030 opened this issue Jan 6, 2025 · 2 comments
Open

Return organization's logo in organizations.get_async #81

andrewli1030 opened this issue Jan 6, 2025 · 2 comments

Comments

@andrewli1030
Copy link

I see that an image_url is returned when using organizations.upload_logo_async. Is it possible to return the image_url as part of organizations.get_async?

Alternatively, is there another way to obtain the logo's url?

@ShawnCone
Copy link

+1 on this, having the same issue finding where this is

@ShawnCone
Copy link

ShawnCone commented Feb 7, 2025

It seems like the actual backend call to:
https://api.clerk.com/v1/organizations/{org_id} (https://clerk.com/docs/reference/backend-api/tag/Organizations#operation/GetOrganization)

Returns with the actual image_url (Not documented in the BAPI docs either

All that's need to be done is to extend the python SDK Organization object like this, and it works:

from httpx import get
from utils.app_settings import APP_SETTINGS
from clerk_backend_api import Organization

class ExtendedOrganization(Organization):
    image_url: str | None


class OrganizationNotFoundException(Exception):
    pass


def get_organization_info(org_id: str) -> ExtendedOrganization:
    # Try manually request without sdk
    resp = get(
        f"https://api.clerk.com/v1/organizations/{org_id}",
        headers={"Authorization": f"Bearer {APP_SETTINGS.clerk_secret_key}"},
    )

    if resp.status_code == 404:
        raise OrganizationNotFoundException(f"Organization with id {org_id} not found")

    if resp.status_code != 200:
        logger.error(f"Failed to get organization with id {org_id}, error: {resp.text}")
        raise Exception(f"Failed to get organization with id {org_id}")

    organization = ExtendedOrganization.model_validate(resp.json())

    return organization

# Then later just access it via:
get_organization_info(your_org_id).image_url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants