Jitendra Pathak
Jitendra Pathak

Reputation: 299

How to add custom fields in google contacts API V3 with json

API Request

POST https://www.google.com/m8/feeds/contacts/default/full?alt=json

Body

{
    "entry": {
        "gd$name": {
            "gd$fullName": {
                "$t": "Rohit Roy"
            },
            "gd$givenName": {
                "$t": "Rohit"
            },
            "gd$familyName": {
                "$t": "Roy"
            }
        },
        "gd$email": [
            {
                "address": "[email protected]",
                "primary": "true",
                "rel": "http://schemas.google.com/g/2005#home"
            }
        ],
        "gd$phoneNumber": {
            "$t": "+919999888877",
            "primary": "true",
            "rel": "http://schemas.google.com/g/2005#home"
        },
        "gd$organization": {
            "gd$orgName": {
                "$t": "XYZ Pvt. ltd."
            }
        }
    }
}

This code is working properly i want to add custom fields to google contacts.

For that i tried convert below XML into JSON.

<gContact:userDefinedField key="chess" value="likes playing black"/>

Like This

"gContact$userDefinedField":{
        "key":"food",
        "value":"Chinese"
        }

But this code is not working with above code so i need help to add custom field with my working code above.

Upvotes: 0

Views: 532

Answers (1)

Jitendra Pathak
Jitendra Pathak

Reputation: 299

Fortunately i got solution of custom fields, birthday and all other google contact fields with JSON API.

Google Contact API Docs updated and mentioned about Peoples API which is replacement of old google contact API.

So now i am using Peoples API instead of Contacts API V3 which already deprecated.

Click This Link For Peoples API Create Contact API Docs

HTTP Request

POST https://people.googleapis.com/v1/people:createContact

Body

{
  "emailAddresses": [
        {
            "value": "[email protected]",
            "type": "work"
        }
    ],
  "names": [{
        "givenName": "John",
        "familyName": "Doe"
    }],
        "birthdays": [
        {
            "date": {
                "year": 1996,
                "month": 5,
                "day": 2
            }
        }
    ],
    "userDefined": [
        {
            "key": "customfield",
            "value": "anyvalue-123456"
        }
    ]
}

In the Body userDefined is for custom fields.

Upvotes: 1

Related Questions