Back

Google Contacts API Essential Guide

Aug 1, 20246 minute read

What type of API does Google Contacts provide?

Google Contacts uses a REST API.

Key points to consider:

  • The Google People API, which includes Contacts functionality, is a RESTful API.

  • The API uses standard HTTP methods like GET, POST, PATCH etc. for different operations.

  • Requests are made to REST-style endpoints like "/v1/people:batchUpdateContacts".

  • Data is exchanged in JSON format in the request/response bodies.

  • The API follows REST principles like using HTTP status codes, having resource-based URLs, and being stateless.

Code example of making a request to the Google Contacts API:

import requests url = "https://people.googleapis.com/v1/people:batchUpdateContacts" params = { "updateMask": "names", "readMask": "names,emailAddresses" } data = { "contacts": { "resource_name": { "emailAddresses": [ { "value": "[email protected]" } ], "etag": "etag" } } } headers = { "Authorization": "Bearer ACCESS_TOKEN" } response = requests.post(url, params=params, json=data, headers=headers) print(response.status_code) print(response.json())

In summary, Google Contacts uses a standard REST API architecture, not SOAP or GraphQL. This allows for easy integration using common HTTP libraries and follows widely adopted API design practices.

Does the Google Contacts API have webhooks?

Based on the search results provided, it appears that the official Google Contacts API does not have native webhook functionality. Here are the key points to consider:

No Native Webhook Support

The search results do not mention any specific webhook capabilities for the Google Contacts API.

The information provided is mostly about general webhook configurations in Google Cloud and third-party integrations.

Third-Party Integration Options

Zapier offers integrations between Google Contacts and webhooks. This suggests that while native webhook support may not be available, third-party services can provide webhook-like functionality for Google Contacts.

Some of the Zapier integrations mentioned include:

  • Adding new Google Contacts from webhooks
  • Posting updates to webhooks when new or updated contacts are detected in Google Contacts
  • Creating custom requests in webhooks for new or updated Google Contacts

Alternative Approaches

If you need real-time updates for Google Contacts, you may need to consider alternative approaches:

  • Polling the Google Contacts API at regular intervals
  • Using third-party services like Zapier to create webhook-like functionality
  • Exploring other Google Cloud services that might offer event-driven architectures for Google Workspace data

Best Practices

When working with Google APIs, always refer to the official documentation for the most up-to-date information on available features.

If webhook functionality is crucial for your use case, consider reaching out to Google support or checking their developer forums for any upcoming features or workarounds.

When using third-party integrations, ensure they comply with your data security and privacy requirements.

In conclusion, while the official Google Contacts API does not appear to have native webhook support, there are third-party solutions and alternative approaches that can provide similar functionality. Always verify the latest information from official sources when planning your integration strategy.

Rate Limits and other limitations

The Google Contacts API has the following key rate limits and quotas:

Default Quota Limit

The default quota limit for the Google Contacts API is 20,000,000 requests per day for free. This is determined from the Google Cloud Console under the project's API quota settings.

Per-User Rate Limit

There is a per-user rate limit of 10,000 requests per day. This means each individual user of your application can make up to 10,000 requests per day to the Contacts API.

Queries Per Second (QPS) Limit

The default QPS limit is 2,400 queries per minute per user per Google Cloud project. This can be increased from the Admin SDK API Quotas page in the Google Cloud Console.

Key Points to Consider

  • If the rate limits are exceeded, the API will return an HTTP 503 status code.

  • It's recommended to use exponential backoff when retrying failed requests due to rate limiting.

  • Google may not be strictly enforcing or counting all requests against these quotas currently.

  • The actual throughput may be higher than the stated limits due to caching and optimizations on Google's end.

Best Practices

  • Implement proper error handling and retries using exponential backoff for 503 errors.

  • Monitor your usage in the Google Cloud Console.

  • Consider increasing limits if needed for high-volume applications.

  • Optimize API usage by batching requests when possible.

  • Be aware of per-user limits in addition to overall project quotas.

In summary, while the Contacts API has fairly generous default limits, it's important to implement proper error handling and follow best practices to avoid issues with rate limiting. The actual enforced limits may be higher than stated, but building your application to work within the documented limits is recommended.

Latest API Version

The most recent version of the Google Contacts API is v1 of the People API. Here are the key points:

Direct Answer

The Google Contacts API has been deprecated and replaced by the People API. The current version of the People API that provides contacts functionality is v1.

Key Points

  • The original Google Contacts API was deprecated and retired on January 19, 2022.
  • The People API v1 now provides the functionality for managing contacts that was previously in the Contacts API.
  • The People API uses different endpoints, fields, and authorization scopes compared to the old Contacts API.

API Details

  • The base URL for People API requests is https://people.googleapis.com/v1/.
  • Key endpoints include:
    • people:batchCreateContacts for creating contacts
    • people:batchUpdateContacts for updating contacts
    • people:batchDeleteContacts for deleting contacts
    • people:searchContacts for searching contacts

Best Practices

  • Use the new People API scopes instead of the old Contacts API scopes:
    • https://www.googleapis.com/auth/contacts for accessing personal contacts
    • https://www.googleapis.com/auth/directory.readonly for accessing directory information
  • When updating contacts, include the etag field to ensure the contact hasn't changed since last read.
  • Be aware of limitations on "Other Contacts" - only basic information can be read, and administrators have read-only access.

In summary, developers should use the People API v1 for any contact-related functionality previously handled by the Google Contacts API. This requires updating endpoints, fields, and authorization scopes in existing applications.

How to get a Google Contacts developer account and API Keys?

  1. Create a Google Account

  2. Set up a Google Cloud project

    • Go to the Google Cloud Console (https://console.cloud.google.com/)
    • Create a new project or select an existing one
    • Enable the People API for your project:
      • In the Cloud Console, go to the APIs & Services > Library page
      • Search for "People API" and click on it
      • Click "Enable" to activate the API for your project
  3. Set up credentials

    • Go to the Credentials page in the Google Cloud Console
    • Click "Create Credentials" and select "OAuth client ID"
    • Configure the OAuth consent screen if prompted
    • Choose the application type (Web application, Desktop app, etc.)
    • Set up authorized redirect URIs if needed
    • Download the client configuration file (client_secret.json)
  4. Authenticate and authorize

    • Implement OAuth 2.0 authentication in your application:
      1. Redirect the user to Google's OAuth 2.0 server
      2. Google's OAuth 2.0 server authenticates the user and obtains consent
      3. Your application receives an authorization code from Google
      4. Your application exchanges the authorization code for an access token
      5. Your application can use the access token to call the People API
  5. Start using the API

    • Use the obtained credentials to make API calls to the People API

Key Points to Consider:

  • Handle token refresh and storage securely in your application
  • Be aware of API usage limits and implement proper error handling
  • Keep your client secrets and access tokens secure
  • Follow Google's API terms of service and data usage policies

What can you do with the Google Contacts API?

Based on the search results provided, here are the key data models you can interact with using the Google Contacts API, along with what is possible for each:

Contacts

  • Create, read, update, and delete contacts
  • Access fields like:
    • Names
    • Email addresses
    • Phone numbers
    • Addresses
    • Organizations
    • Birthdays
    • Events
    • Relations
    • Websites
    • Photos
    • Biographies
    • and more

Contact Groups

  • Create, read, update, and delete contact groups
  • Access fields like:
    • Name
    • Group type (system or user-created)
    • Metadata (update time, deleted status)

Other Contacts

  • Read-only access
  • Only basic information available:
    • Names
    • Email addresses
    • Phone numbers

Directory Contacts (for Google Workspace users)

  • List and search directory contacts and profiles
  • Requires specific authorization scope

Key Points:

  • Full read/write access for personal contacts and contact groups
  • Limited read-only access for "Other Contacts"
  • Directory contacts require separate authorization
  • The API uses OAuth 2.0 for authentication
  • Various fields are available for each contact, allowing detailed information storage and retrieval
  • The API supports operations like creating, updating, deleting, and listing contacts

Best Practices:

  • Use appropriate scopes for the level of access required
  • Handle "Other Contacts" as read-only data
  • Migrate from the legacy Contacts API to the People API for full functionality
  • Utilize client libraries provided by Google for easier integration

This overview covers the main data models and interactions possible with the Google Contacts API, focusing on contacts, contact groups, and the different levels of access for various contact types.