This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Working with Threads in Gmail



Overview

The following operations allow you to work with threads. Click an operation name to see details on how to use it.

For a sample proxy service that illustrates how to work with threads.

OperationDescription

listAllThreads

Lists all threads

readThreadGets an email thread
trashThreadsSends a thread to the trash
unTrashThreadsRemoves a thread from the trash
modifyExistingThreadsModifies an existing thread

Operation details

This section provides further details on the operations related to threads.

Listing all threads

The listAllThreads operation lists all the existing email threads.

listAllThreads
<gmail.listAllThreads>
	<includeSpamTrash>{$ctx:includeSpamTrash}</includeSpamTrash>
    <labelIds>{$ctx:labelIds}</labelIds>
    <maxResults>{$ctx:maxResults}</maxResults>
    <pageToken>{$ctx:pageToken}</pageToken>
    <q>{$ctx:q}</q>
</gmail.listAllThreads>
Properties
  • includeSpamTrash: Include messages from SPAM and TRASH in the results. (Default: false).
  • labelIds: Only returns threads with labels that match all of the specified label IDs.
  • maxResults: Maximum number of messages to return.
  • pageToken: Page token to retrieve a specific page of results in the list.
  • q: Only returns messages matching the specified query. Supports the same query format as the Gmail search box.
Sample request

Following is a sample REST/JSON request that can be handled by the listAllThreads operation.

Sample Request for listAllThreads
{
  "maxResults":"10",
  "includeSpamTrash":"true",
  "pageToken":"00965906535058580458",
  "labelIds":"UNREAD",
  "q":"Jira"
}
Related Gmail documentation

https://developers.google.com/gmail/api/v1/reference/users/threads/list

Getting an email thread

The readThread operation retrieves an existing thread.

readThread
<gmail.readThread>
	<id>{$ctx:id}</id>
    <format>{$ctx:format}</format>
    <metadataHeaders>{$ctx:metadataHeaders}</metadataHeaders>
</gmail.readThread>
Properties
  • id: The ID of the thread to retrieve.
  • format: The format in which to return the messages in the thread.
  • metadataHeaders: When the format is METADATA, only include the headers specified with this property.
Sample request

Following is a sample REST/JSON request that can be handled by the readThread operation.

Sample Request for readThread
{ 
  "id":"14bbb686ba287e1d",
  "format":"minimal"
}
Related Gmail documentation

https://developers.google.com/gmail/api/v1/reference/users/threads/get

Sending a thread to the trash

The trashThreads operation sends a thread to the trash.

getDiscussion
<gmail.trashThreads>
	<id>{$ctx:id}</id>
</gmail.trashThreads>
Properties
  • id: Required - The ID of the thread to trash.
Sample request

Following is a sample REST/JSON request that can be handled by the trashThreads operation.

Sample Request for trashThreads
{ 
  "id":"14bbb686ba287e1d"
}
Related Gmail documentation

https://developers.google.com/gmail/api/v1/reference/users/threads/trash

Removing a thread from the trash

The unTrashThreads operation removes a thread from the trash.

unTrashThreads
<gmail.unTrashThreads>
	<id>{$ctx:id}</id>
</gmail.unTrashThreads>
Properties
  • id: Required - The ID of the thread to untrash.
Sample request

Following is a sample REST/JSON request that can be handled by the unTrashThreads operation.

Sample Request for unTrashThreads
{ 
  "id":"14bbb686ba287e1d"
}
Related Gmail documentation

https://developers.google.com/gmail/api/v1/reference/users/threads/untrash

Modifying an existing thread

The modifyExistingThreads operation modifies an existing thread.

modifyExistingThreads
<gmail.modifyExistingThreads>
	<id>{$ctx:id}</id>
    <addLabelIds>{$ctx:addLabelIds}</addLabelIds>
    <removeLabelIds>{$ctx:removeLabelIds}</removeLabelIds>
</gmail.modifyExistingThreads> 
Properties
  • id: Required - The ID of the thread to modify.
  • addLabelIds: A list of IDs of labels to add to this thread.
  • removeLabelIds: A list of IDs of labels to remove from this thread.
Sample request

Following is a sample REST/JSON request that can be handled by the modifyExistingThreads operation.

Sample Request for modifyExistingThreads
{
  "id":"14b31c7af7b778f4",
  "addLabelIds": [
    "Label_33",
    "Label_24"
  ],
  "removeLabelIds": [
    "Label_28",
    "Label_31"]
}
Related Gmail documentation

https://developers.google.com/gmail/api/v1/reference/users/threads/modify

Sample configuration

Following is a sample proxy service that illustrates how to connect to Gmail with the init operation and use the listAllThreads operation. The sample request for this proxy can be found in listAllThreads sample request. You can use this sample as a template for using other operations in this category.

Sample Proxy
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="gmail_listAllThreads"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
    <target>
        <inSequence>
            <property name="includeSpamTrash" expression="json-eval($.includeSpamTrash)"/>
            <property name="labelIds" expression="json-eval($.labelIds)"/>
            <property name="maxResults" expression="json-eval($.maxResults)"/>
            <property name="pageToken" expression="json-eval($.pageToken)"/>
            <property name="q" expression="json-eval($.q)"/>
            <property name="userId" expression="json-eval($.userId)"/>
            <property name="refreshToken" expression="json-eval($.refreshToken)"/>
            <property name="clientId" expression="json-eval($.clientId)"/>
            <property name="clientSecret" expression="json-eval($.clientSecret)"/>
            <property name="accessToken" expression="json-eval($.accessToken)"/>
            <property name="registryPath" expression="json-eval($.registryPath)"/>
            <property name="apiUrl" expression="json-eval($.apiUrl)"/>
            <gmail.init>
                <userId>{$ctx:userId}</userId>
                <refreshToken>{$ctx:refreshToken}</refreshToken>
                <clientSecret>{$ctx:clientSecret}</clientSecret>
                <clientId>{$ctx:clientId}</clientId>
                <registryPath>{$ctx:registryPath}</registryPath>
                <accessToken>{$ctx:accessToken}</accessToken>
                <apiUrl>{$ctx:apiUrl}</apiUrl>
            </gmail.init>
            <gmail.listAllThreads>
                <includeSpamTrash>{$ctx:includeSpamTrash}</includeSpamTrash>
                <labelIds>{$ctx:labelIds}</labelIds>
                <maxResults>{$ctx:maxResults}</maxResults>
                <pageToken>{$ctx:pageToken}</pageToken>
                <q>{$ctx:q}</q>
            </gmail.listAllThreads>
            <respond/>
        </inSequence>
        <outSequence>
            <log/>
            <send/>
        </outSequence>
    </target>
    <parameter name="serviceType">proxy</parameter>
    <description/>
</proxy>