billdeitrick / pypco

A Python client for the Planning Center Online API.
MIT License
39 stars 13 forks source link

Household Memberships not accessible #28

Closed mphuff closed 4 years ago

mphuff commented 4 years ago

It appears that because of https://github.com/billdeitrick/pypco/blob/master/pypco/models/people.py#L76 that household_memberships is not available as an entity.

I've obtained a list of household_ids and attempting to obtain them as follows:

print(pco.people.households.get('397489').rel.househould_memberships.list())
# Yields the following exception:
# 
#   File "/home/mhuff/planning-center/pco/lib/python3.6/site-packages/pypco/models/base_model.py", line 371, in list
#    raise PCORelationDoesNotExistError("The relation or link \"{}\" does not exist on this object.".format(self._rel_name))
#pypco.models.base_model.PCORelationDoesNotExistError: The relation or link "househould_memberships" does not exist on this object.
pastorhudson commented 4 years ago

I think what you want is rel.people.list()

import pypco
import os

pco = pypco.PCO(os.environ.get('PCO_CLIENT_ID'),
                os.environ.get('PCO_CLIENT_SECRET'))

house = pco.people.households.get('9272955')

for member in house.rel.people.list():
    print(member)
pastorhudson commented 4 years ago

You can also do: house_members = pco.people.households.get('9272955').rel.people.list()

mphuff commented 4 years ago

That did the trick! Thanks @pastorhudson

pastorhudson commented 4 years ago

Glad to help!