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 Labels in Gmail



Overview

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

For a sample proxy service that illustrates how to work with labels, see Sample configuration.

OperationDescription

listLabels

Lists all labels

readLabelGets a label's details
createLabelsCreates a new label
updateLabelsUpdates an existing label
deleteLabelDeletes a label

Operation details

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

Listing all labels

The listLabels operation lists all existing labels.

listLabels
</gmail.listLabels>
Related Gmail documentation

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

Getting a label's details

The readLabel operation gets a label's details.

readLabel
<gmail.readLabel>
	<id>{$ctx:id}</id>
</gmail.readLabel>
Properties
  • id: The ID of the label whose details you want to retrieve.
Sample request

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

Sample Request for readLabel
{
"id":"Label_1"
}
Related Gmail documentation

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

Creating a new label

The createLabels operation creates a new label.

createLabels
<gmail.createLabels>
	<name>{$ctx:name}</name>
    <messageListVisibility>{$ctx:messageListVisibility}</messageListVisibility>
    <labelListVisibility>{$ctx:labelListVisibility}</labelListVisibility>
    <type>{$ctx:type}</type>
    <messagesTotal>{$ctx:messagesTotal}</messagesTotal>
    <messagesUnread>{$ctx:messagesUnread}</messagesUnread>
    <threadsTotal>{$ctx:threadsTotal}</threadsTotal>
    <threadsUnread>{$ctx:threadsUnread}</threadsUnread>
</gmail.createLabels>
Properties
  • name: The display name of the label.
  • messageListVisibility: The visibility of messages with this label in the message list in the Gmail web interface.
  • labelListVisibility: The visibility of the label in the label list in the Gmail web interface.
  • type: The owner type for the label.
  • messagesTotal: The total number of messages with the label.
  • messagesUnread: The number of unread messages with the label.
  • threadsTotal: The total number of threads with the label.
  • threadsUnread: The number of unread threads with the label
Sample request

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

Sample Request for createLabels
{
 "name": "TestESB2",
 "threadsUnread": 100,
 "messageListVisibility": "show",
 "threadsTotal": 100,
 "type": "user",
 "messagesTotal": 100,
 "messagesUnread": 100,
 "labelListVisibility": "labelShow"
}
Related Gmail documentation

https://developers.google.com/gmail/api/v1/reference/users/labels/create

Update labels

The updateLabels operation updates an existing label.

updateLabels
<gmail.updateLabels>
	<name>{$ctx:name}</name>
    <messageListVisibility>{$ctx:messageListVisibility}</messageListVisibility>
    <labelListVisibility>{$ctx:labelListVisibility}</labelListVisibility>
    <type>{$ctx:type}</type>
    <messagesTotal>{$ctx:messagesTotal}</messagesTotal>
    <messagesUnread>{$ctx:messagesUnread}</messagesUnread>
    <threadsTotal>{$ctx:threadsTotal}</threadsTotal>
    <threadsUnread>{$ctx:threadsUnread}</threadsUnread>
    <id>{$ctx:id}</id>
</gmail.updateLabels>
Properties
  • name: The display name of the label.
  • messageListVisibility: The visibility of messages with this label in the message list in the Gmail web interface.
  • labelListVisibility: The visibility of the label in the label list in the Gmail web interface.
  • type: The owner type for the label.
  • messagesTotal: The total number of messages with the label.
  • messagesUnread: The number of unread messages with the label.
  • threadsTotal: The total number of threads with the label.
  • threadsUnread: The number of unread threads with the label.
  • id:The ID of the label to update.

Sample request

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

Sample Request for updateLabels
{
 "id":"426572682792",
 "name": "TestESB2",
 "threadsUnread": 100,
 "messageListVisibility": "show",
 "threadsTotal": 100,
 "type": "user",
 "messagesTotal": 100,
 "messagesUnread": 100,
 "labelListVisibility": "labelShow"
}
Related Gmail documentation

https://developers.google.com/gmail/api/v1/reference/users/labels/update

Deleting a label

The deleteLabel operation deletes a label.

deleteLabel
<gmail.deleteLabel>
	<id>{$ctx:id}</id>
</gmail.deleteLabel>
Properties
  • id: The ID of the label to delete.
Sample request

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

Sample Request for deleteLabel
{
	"id":"57648478394803"
} 
Related Gmail documentation

https://developers.google.com/gmail/api/v1/reference/users/labels/delete

Sample configuration

Following is a sample proxy service that illustrates how to connect to Gmail with the init operation and use the readLabel operation. The sample request for this proxy can be found in readLabel 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_listLabels"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
    	<target>
        <inSequence>
            <property name="id" expression="json-eval($.id)"/>
            <property name="format" expression="json-eval($.format)"/>
            <property name="metadataHeaders" expression="json-eval($.metadataHeaders)"/>
            <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.readLabel>
	          <id>{$ctx:id}</id>
            </gmail.readLabel>
            <respond/>
        </inSequence>
        <outSequence>
            <log/>
            <send/>
        </outSequence>
    </target>
    <parameter name="serviceType">proxy</parameter>
    <description/>
</proxy>