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 Drafts in Gmail
Overview
The following operations allow you to work with Drafts. Click an operation name to see details on how to use it.
For a sample proxy service that illustrates how to work with drafts, see Sample configuration.
Operation | Description |
---|---|
Lists all drafts | |
readDraft | Reads a particular draft |
deleteDraft | Deletes an existing draft |
createDraft | Creates a new draft |
Operation details
This section provides further details on the operations related to drafts.
Listing all drafts
The listDrafts
operation lists all drafts.
<gmail.listDrafts> <maxResults>{$ctx:maxResults}</maxResults> <pageToken>{$ctx:pageToken}</pageToken> </gmail.listDrafts>
Properties
maxResults
: Maximum number of messages to return.pageToken
: Page token to retrieve a specific page of results in the list.
Sample request
Following is a sample REST/JSON request that can be handled by the
listDrafts
operation.
{ "maxResults":"10" "pageToken":"09876536614133772469" }
Related Gmail documentation
https://developers.google.com/gmail/api/v1/reference/users/drafts/list
Reading a draft
The readDraft
operation retrieves a particular draft.
<gmail.readDraft> <id>{$ctx:id}</id> <format>{$ctx:format}</format> </gmail.readDraft>
Properties
- id: The ID of the draft to retrieve
format
: The format to return the draft in
Sample request
Following is a sample REST/JSON request that can be handled by the operation.
{ "id": "1492984134337920839", "format":"raw" }
Related Gmail documentation
https://developers.google.com/gmail/api/v1/reference/users/drafts/get
Deleting a draft
The deleteDraft
operation deletes an existing draft.
<gmail.deleteDraft> <id>{$ctx:id}</id> </gmail.deleteDraft>
Properties
- id: The ID of the draft to delete.
Sample request
Following is a sample REST/JSON request that can be handled by the deleteDraft
operation.
{ "id":"1491513685150755887" }
Related Gmail documentation
https://developers.google.com/gmail/api/v1/reference/users/drafts/delete
Creating a new draft
The createDraft
operation creates a new draft.
<gmail.createDraft> <to>{$ctx:to}</to> <subject>{$ctx:subject}</subject> <from>{$ctx:from}</from> <cc>{$ctx:cc}</cc> <bcc>{$ctx:bcc}</bcc> <id>{$ctx:id}</id> <threadId>{$ctx:threadId}</threadId> <messageBody>{$ctx:messageBody}</messageBody> <contentType>{$ctx:contentType}</contentType> </gmail.createDraft>
Properties
to
: The email address of the recipient of this email.subject
: Subject of the email.from
: The email address of the sender of the email.cc
: The email addresses of recipients who will receive a copy of this email.bcc
: The email addresses of recipients who will privately receive a copy of this email (their email addresses will be hidden).threadId
: ID of the thread.id
: ID of the email.messageBody
: Content of the email.- contentType: If the message body is in the format of html or need to send a rich text then we must give the parameter value as "text/html; charset=UTF-8" otherwise it takes the default value as text/plain.
Sample request
Following is a sample REST/JSON request that can be handled by the createDraft
operation.
{ "to":"tharis63@hotmail.com", "from":"tharis63@gmail.com", "subject":"test", "messageBody":"Hi hariprasath", "cc":"tharis63@outlook.com", "bcc":"tharis63@yahoo.com", "id":"154b8c77e551c509", "threadId":"154b8c77e551c509" "contentType":"text/html; charset=UTF-8" }
Related Gmail documentation
https://developers.google.com/gmail/api/v1/reference/users/drafts/create
Sample configuration
Following is a sample proxy service that illustrates how to connect to Gmail with the init
operation and use the listDrafts
operation. The sample request for this proxy can be found in listDrafts sample request. You can use this sample as a template for using other operations in this category.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="gmail_listDrafts" transports="https,http" statistics="disable" trace="disable" startOnLoad="true"> <target> <target> <inSequence> <property name="maxResults" expression="json-eval($.maxResults)"/> <property name="pageToken" expression="json-eval($.pageToken)"/> <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.listDrafts> <maxResults>{$ctx:maxResults}</maxResults> <pageToken>{$ctx:pageToken}</pageToken> </gmail.listDrafts> <respond/> </inSequence> <outSequence> <log/> <send/> </outSequence> </target> <parameter name="serviceType">proxy</parameter> <description/> </proxy>