Giter Club home page Giter Club logo

Comments (9)

facetoe avatar facetoe commented on June 8, 2024

Hi @rishi-freshbooks, It's a bit funny how Zendesk organized this. Each User is tied to one organization when you query the user API (https://developer.zendesk.com/rest_api/docs/core/users) and can be retrieved via the organization property in Zenpy:

for user in zenpy.users():
    print(user.organization)

There is also an organizations endpoint (https://developer.zendesk.com/rest_api/docs/core/organizations) which takes a User id and returns all organizations associated with that user:

for organization in zenpy.users.organizations(user_id=5386846818):
    print(organization)

If you are looking for all organizations associated with a User then the second one is what you want. Hope this helps!

from zenpy.

rishi-freshbooks avatar rishi-freshbooks commented on June 8, 2024

Thanks @facetoe! Is there a way to link a user to more than 1 organization?

from zenpy.

facetoe avatar facetoe commented on June 8, 2024

Zenpy doesn't support this directly however it would be easy to do in your own code with the users.organizations endpoint.

from zenpy.

rishi-freshbooks avatar rishi-freshbooks commented on June 8, 2024

Factoe would you be able to implement this endpoint? https://developer.zendesk.com/rest_api/docs/core/organization_memberships

from zenpy.

facetoe avatar facetoe commented on June 8, 2024

Ahh most definitely, that looks really handy. I'll create an issue for it and try to implement it in the next week or so. Good spot!

from zenpy.

facetoe avatar facetoe commented on June 8, 2024

Hi @rishi-freshbooks, I've implemented part of the functionality for organization memberships in a9c4ba2. You can query organization memberships:

# To see all organization memberships
for org_memb in zenpy.organization_memberships():
    print(org_memb)

# Or for each user (also works for each organization)
for user in zenpy.users():
    for org_memb in zenpy.users.organization_memberships(user_id=user.id):
        print(org_memb)

And also create and delete them:

obj = OrganizationMembership(user_id=1111, organization_id=222222)
created_orgmemb = zenpy.organization_memberships.create(obj)

zenpy.organization_memberships.delete(created_orgmemb)

There is some functionality I didn't implement as I figured it was unlikely to be used. If you want to use any of the un-implemented functionality let me know and I will have a look at adding it as well.

Let me know if you find any bugs!

from zenpy.

rishi-freshbooks avatar rishi-freshbooks commented on June 8, 2024

Thanks @facetoe! This is great. Do you mind bumping the version and creating a tag, so we can install this new endpoint 😄 ?

from zenpy.

facetoe avatar facetoe commented on June 8, 2024

No worries, it's done!

from zenpy.

tvallois avatar tvallois commented on June 8, 2024

Hey @facetoe,

Thanks for this. Is it possible to create OrganizationMembership with user and organization objects instead of ids?

Thanks

from zenpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.