How can I add contact by Account ID with Google People API?

I have a bunch of people I would like to add as Google Contact. For each of them, I have the google account ID.

I would like to use Google People API, but so far I've failed. Here's what I've tried :

-provide Google Id as ResourceName (pre-formating people/id). I got a 400 error with message : "Request person should not have a resource name."

-provide Google Id as a metadata, formating it properly in sources[0].id. I also got a 400 error with message : "Request contains an invalid argument."

I'm kinda stuck here, does anyone have an idea ? Thanks a lot !

Upvotes: 0

Views: 497

Answers (1)

Jasper Duizendstra
Jasper Duizendstra

Reputation: 2617

I also wanted to add contacts using the people API, based on the directory profile. I got this working by using the following body:

body = {
    "names": [{"familyName": "Doe"}],
    "emailAddresses": [
        {"metadata": {"primary": True}, "value": "[email protected]"}
    ],
}

The contact was added and when I compared the contact with another contact that I created manually based on the directory, the properties were the same.

My conclusion is that, by adding the G Suite primary address, Google will figure it out on its own.

Upvotes: 0

Related Questions