Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

add new contact to group using google people API with python

I am trying to create a code that saves new contacts and puts them in a certain group.

Creating a contact works great-

service = build('people', 'v1', credentials=creds)
service.people().createContact(body={"names": [{"givenName": name}], "phoneNumbers": [{'value': phone}],}).execute()

There is no problem in creating a group either-

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

service = build('people', 'v1', credentials=creds)
a = service.contactGroups().create(body={"contactGroup": {"name": "try1123", }}).execute()

But when I try to create a contact within the group I encounter an unknown error-

    service.people().createContact(body={"names": [{"givenName": name}], "phoneNumbers": [{'value': phone_number}],
                                     "memberships": [{"contactGroupMembership": {
                                         "contactGroupResourceName": "contactGroups/'try1123'", }, }]}).execute()

error:

googleapiclient.errors.HttpError: <HttpError 400 when requesting https://people.googleapis.com/v1/people:createContact?alt=json returned "Request contains an invalid argument.". Details: "Request contains an invalid argument.">

createContact python code

createContact Method

>Solution :

I think the problem here is where the {contactGroupId} you are specifying in contactGroupResourceName, you are putting the name of the contact group you created, the id should be an int value for what can I see in the examples, something like "contactGroupResourceName": "contactGroups/123123123"

Most likely the call when you created the contactGroup should have returned you this id.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading