Search code examples
apigmailgoogle-apps

Is there an API to get a list of gmail filters and update them?


Google Apps has an "Google Apps Email Settings API" which allows to create a new mail filter via an API call.

Is there any (perhaps undocumented) way to get the list of current filters and update them?


Solution

  • A Filter object was added to the API that allows for filter processing, including retrieval, creation and deletion.

    https://developers.google.com/gmail/api/guides/filter_settings

    Specifically:

    Listing Filters

    GET https://www.googleapis.com/gmail/v1/users/userId/settings/filters
    

    Returns a JSON list of Filter objects

    Retrieving a specific Filter

    GET https://www.googleapis.com/gmail/v1/users/userId/settings/filters/id
    

    Returns a single JSON Filter object

    Deleting a specific Filter

    DELETE https://www.googleapis.com/gmail/v1/users/userId/settings/filters/id
    

    Creating a Filter

    POST https://www.googleapis.com/gmail/v1/users/userId/settings/filters
    

    With a JSON encoded Filter in the request body.

    While the REST URLs have v1 in the address, they are linked from the current documentation. Also note, GMail API migration is currently in progress, and the deprecated API will cease to function as of July 2016. Keep this in mind, as the API may change.