Operations (sample payloads)

Main operations

Create send-as alias

Creates a custom 'from' send-as alias. REQUIRES a service account. Sample Input

\{
    "user_id": "me",
    "display_name": "John Doe",
    "send_as_address": "john.doe@example.com",
    "is_default": false,
    "reply_to_address": "support@example.com",
    "signature": "<p>Best regards,<br>John Doe<br>Customer Support</p>",
    "treat_as_alias": true
\}

Sample Output

\{
    "sendAsEmail": "john.doe@example.com",
    "displayName": "John Doe",
    "replyToAddress": "support@example.com",
    "signature": "<p>Best regards,<br>John Doe<br>Customer Support</p>",
    "isDefault": false,
    "treatAsAlias": true,
    "verificationStatus": "pending"
\}

Delete message

Deletes a message in your Inbox. Sample Input

\{
    "user_id": "me",
    "message_id": "17a2d34b8c9e5f3d"
\}

Sample Output

{
    "deleted": true
}

Delete send-as alias

Deletes a specified send-as alias. REQUIRES a service account. Sample Input

\{
    "user_id": "me",
    "send_as_address": "marketing@example.com"
\}

Sample Output

{
    "deleted": true
}

Download message attachments

Get the attachments from a message. Sample Input

\{
    "user_id": "me",
    "message_id": "17e3d45b8a9c2f3d"
\}

Sample Output

{
    "files": [
        \{
            "name": "report.pdf",
            "url": "https://www.googleapis.com/gmail/v1/users/me/messages/17e3d45b8a9c2f3d/attachments/ANGjdJ8z9X_kL2fj...",
            "mime_type": "application/pdf",
            "expires": 1623456789
        \},
        \{
            "name": "image.jpg",
            "url": "https://www.googleapis.com/gmail/v1/users/me/messages/17e3d45b8a9c2f3d/attachments/BGHjdJ8z9X_kL2fj...",
            "mime_type": "image/jpeg",
            "expires": 1623456789
        \}
    ]
}

Get message

Get full details of a message in your Inbox. Sample Input

\{
    "user_id": "me",
    "message_id": "17e3d45b8a9c2f3d"
\}

Sample Output

Get send-as alias

Returns data for a specified send-as alias. REQUIRES a service account. Sample Input

\{
    "user_id": "me",
    "send_as_address": "marketing@example.com"
\}

Sample Output

\{
    "sendAsEmail": "marketing@example.com",
    "displayName": "Marketing Team",
    "replyToAddress": "replies@example.com",
    "signature": "<div>Best regards,<br>The Marketing Team<br><img src='https://example.com/logo.png' alt='Company Logo'></div>",
    "isDefault": false,
    "treatAsAlias": true,
    "verificationStatus": "verified"
\}

Get thread

Returns full details of a thread in your Inbox. Sample Input

\{
    "user_id": "me",
    "thread_id": "17a2d34b8c9e5f3d"
\}

Sample Output

{
    "id": "17a2d34b8c9e5f3d",
    "historyId": "1234567",
    "messages": [
        {
            "id": "17a2d34b8c9e5f3d",
            "threadId": "17a2d34b8c9e5f3d",
            "labelIds": [
                "INBOX",
                "CATEGORY_PERSONAL"
            ],
            "snippet": "Hi John, I hope this email finds you well. I wanted to follow up on our...",
            "historyId": "1234567",
            "internalDate": "1623456789000",
            "payload": {
                "partId": "",
                "mimeType": "multipart/alternative",
                "filename": "",
                "headers": [
                    \{
                        "name": "From",
                        "value": "Jane Doe &lt;jane.doe@example.com&gt;"
                    \},
                    \{
                        "name": "To",
                        "value": "John Smith &lt;john.smith@example.com&gt;"
                    \},
                    \{
                        "name": "Subject",
                        "value": "Follow-up on project discussion"
                    \}
                ],
                "body": {
                    "size": 0
                },
                "parts": [
                    {
                        "partId": "0",
                        "mimeType": "text/plain",
                        "filename": "",
                        "headers": [
                            \{
                                "name": "Content-Type",
                                "value": "text/plain; charset=UTF-8"
                            \}
                        ],
                        "body": \{
                            "size": 240,
                            "data": "SGkgSm9obiwKCkkgaG9wZSB0aGlzIGVtYWlsIGZpbmRzIHlvdSB3ZWxsLiBJIHdhbnRlZCB0byBmb2xsb3cgdXAgb24gb3VyIHByb2plY3QgZGlzY3Vzc2lvbiBmcm9tIGxhc3Qgd2Vlay4gSGF2ZSB5b3UgaGFkIGEgY2hhbmNlIHRvIHJldmlldyB0aGUgcHJvcG9zYWw/CgpMZXQgbWUga25vdyBpZiB5b3UgaGF2ZSBhbnkgcXVlc3Rpb25zIG9yIGNvbmNlcm5zLgoKQmVzdCByZWdhcmRzLApKYW5l"
                        \}
                    }
                ]
            },
            "sizeEstimate": 5678
        }
    ]
}

Get user profile

Returns information about the user authenticated to Tray. Sample Input

{
    "user_id": "me"
}

Sample Output

\{
    "emailAddress": "john.doe@example.com",
    "messagesTotal": 15234,
    "threadsTotal": 3789,
    "historyId": "8374629"
\}

List labels

Lists all labels in the user's inbox. Sample Input

{
    "user_id": "me"
}

Sample Output

{
    "labels": [
        \{
            "id": "INBOX",
            "name": "INBOX",
            "messageListVisibility": "show",
            "labelListVisibility": "labelShow",
            "type": "system"
        \},
        \{
            "id": "SENT",
            "name": "SENT",
            "messageListVisibility": "show",
            "labelListVisibility": "labelShow",
            "type": "system"
        \},
        \{
            "id": "TRASH",
            "name": "TRASH",
            "messageListVisibility": "show",
            "labelListVisibility": "labelShow",
            "type": "system"
        \},
        \{
            "id": "Label_1",
            "name": "Work",
            "messageListVisibility": "show",
            "labelListVisibility": "labelShow",
            "type": "user"
        \},
        \{
            "id": "Label_2",
            "name": "Personal",
            "messageListVisibility": "show",
            "labelListVisibility": "labelShow",
            "type": "user"
        \}
    ]
}

List messages

Returns a list of all the messages in the Gmail inbox. Sample Input

\{
    "user_id": "me",
    "query": "is:unread",
    "include_spam_trash": false,
    "label_ids": [
        "INBOX",
        "IMPORTANT"
    ],
    "limit": 50,
    "page_token": "next_page_token_123"
\}

Sample Output

{
    "messages": [
        \{
            "id": "17a1b2c3d4e5f6g7",
            "threadId": "17a1b2c3d4e5f6g7"
        \},
        \{
            "id": "18b3c4d5e6f7g8h9",
            "threadId": "18b3c4d5e6f7g8h9"
        \},
        \{
            "id": "19c5d6e7f8g9h0i1",
            "threadId": "19c5d6e7f8g9h0i1"
        \}
    ],
    "nextPageToken": "next_page_token_456",
    "resultSizeEstimate": 127
}

List send-as aliases

Lists a user's custom 'from' send-as alias. REQUIRES a service account. Sample Input

{
    "user_id": "john.doe@example.com"
}

Sample Output

{
    "sendAs": [
        \{
            "sendAsEmail": "john.doe@example.com",
            "displayName": "John Doe",
            "replyToAddress": "john.doe@example.com",
            "signature": "Best regards,\nJohn Doe\nSales Manager",
            "isPrimary": true,
            "isDefault": true
        \},
        \{
            "sendAsEmail": "support@example.com",
            "displayName": "Example Support",
            "replyToAddress": "support@example.com",
            "signature": "Thank you for contacting Example Support,\n\nBest regards,\nJohn Doe",
            "isPrimary": false,
            "isDefault": false
        \},
        \{
            "sendAsEmail": "marketing@example.com",
            "displayName": "Example Marketing",
            "replyToAddress": "marketing@example.com",
            "signature": "Stay updated with our latest offers!\n\nJohn Doe\nMarketing Team",
            "isPrimary": false,
            "isDefault": false
        \}
    ]
}

List threads

Returns a list of all the conversation threads in the Gmail inbox. Sample Input

\{
    "user_id": "me",
    "query": "is:unread",
    "include_spam_trash": false,
    "label_ids": [
        "INBOX",
        "IMPORTANT"
    ],
    "limit": 50,
    "page_token": "next_page_token_123"
\}

Sample Output

{
    "threads": [
        \{
            "id": "thread_id_1",
            "snippet": "Hello, I wanted to discuss the project...",
            "historyId": "12345"
        \},
        \{
            "id": "thread_id_2",
            "snippet": "Meeting reminder: Team sync at 2 PM...",
            "historyId": "12346"
        \},
        \{
            "id": "thread_id_3",
            "snippet": "Your flight reservation has been confirmed...",
            "historyId": "12347"
        \}
    ],
    "nextPageToken": "next_page_token_456",
    "resultSizeEstimate": 150
}

List user history

Lists the history of all changes to the given mailbox. Sample Input

\{
    "user_id": "me",
    "start_history_id": "12345",
    "history_types": "messageAdded",
    "limit": 10,
    "label_id": "INBOX",
    "page_token": "nextPageToken123"
\}

Sample Output

{
    "history": [
        {
            "id": "67890",
            "messages": [
                \{
                    "id": "msg123",
                    "threadId": "thread456"
                \}
            ],
            "messagesAdded": [
                {
                    "message": \{
                        "id": "msg123",
                        "threadId": "thread456",
                        "labelIds": [
                            "INBOX",
                            "UNREAD"
                        ]
                    \}
                }
            ]
        }
    ],
    "nextPageToken": "nextPageToken789",
    "historyId": "67890"
}

Reply to message

Sends a reply email message via your Gmail account. Messages will appear to the recipient as if you had sent the message yourself in the Gmail interface. Sample Input

{
    "user_id": "me",
    "message_id": "17e3d45b8a9c2f3d",
    "body": "Thank you for your email. I've reviewed the proposal and have a few questions. Can we schedule a call to discuss further?",
    "from": \{
        "email": "john.doe@example.com",
        "name": "John Doe"
    \},
    "to": [
        \{
            "email": "jane.smith@company.com",
            "name": "Jane Smith"
        \}
    ],
    "cc": [
        \{
            "email": "team@company.com",
            "name": "Project Team"
        \}
    ],
    "bcc": [
        \{
            "email": "manager@company.com",
            "name": "Manager"
        \}
    ],
    "reply_to": \{
        "email": "john.doe@company.com",
        "name": "John Doe"
    \},
    "attachments": [
        \{
            "filename": "questions.pdf",
            "content": "base64encodedcontent..."
        \}
    ]
}

Sample Output

\{
    "id": "17e3d45b8a9c2f3e",
    "threadId": "17e3d45b8a9c2f3d",
    "labelIds": [
        "SENT",
        "INBOX"
    ]
\}

Send message

Sends an email message via your Gmail account. Messages will appear to the recipient as if you had sent the message yourself in the Gmail interface. Sample Input

{
    "user_id": "me",
    "to": [
        \{
            "email": "recipient@example.com",
            "name": "John Doe"
        \}
    ],
    "subject": "Meeting Agenda for Tomorrow",
    "body": "<p>Hello John,</p><p>I hope this email finds you well. I wanted to share the agenda for our meeting tomorrow:</p><ol><li>Project updates</li><li>Budget review</li><li>Q&A session</li></ol><p>Please let me know if you have any questions or if you'd like to add any items to the agenda.</p><p>Best regards,<br>Jane Smith</p>",
    "from": \{
        "email": "jane.smith@example.com",
        "name": "Jane Smith"
    \},
    "cc": [
        \{
            "email": "manager@example.com",
            "name": "Team Manager"
        \}
    ],
    "bcc": [
        {
            "email": "archive@example.com"
        }
    ],
    "reply_to": \{
        "email": "jane.smith@company.com",
        "name": "Jane Smith"
    \},
    "attachments": [
        \{
            "filename": "meeting_agenda.pdf",
            "content": "base64encodedcontent..."
        \}
    ]
}

Sample Output

\{
    "id": "17a9f3b2c4d5e6f7",
    "threadId": "17a9f3b2c4d5e6f7",
    "labelIds": [
        "SENT",
        "INBOX"
    ]
\}

Update message labels

Modifies the labels on the specified message. Sample Input

\{
    "user_id": "me",
    "message_id": "17a2d34b8c9def0",
    "add_label_ids": [
        "IMPORTANT",
        "CATEGORY_PERSONAL"
    ],
    "remove_label_ids": [
        "INBOX"
    ]
\}

Sample Output

\{
    "id": "17a2d34b8c9def0",
    "threadId": "17a2d34b8c9def0",
    "labelIds": [
        "IMPORTANT",
        "CATEGORY_PERSONAL",
        "SENT"
    ]
\}

Update send-as alias

Updates a custom 'from' send-as alias. REQUIRES a service account. Sample Input

\{
    "user_id": "me",
    "display_name": "John Doe",
    "send_as_address": "john.doe@example.com",
    "is_default": true,
    "reply_to_address": "support@example.com",
    "signature": "<p>Best regards,<br>John Doe<br>Customer Support</p>",
    "treat_as_alias": false
\}

Sample Output

\{
    "sendAsEmail": "john.doe@example.com",
    "displayName": "John Doe",
    "replyToAddress": "support@example.com",
    "signature": "<p>Best regards,<br>John Doe<br>Customer Support</p>",
    "isDefault": true,
    "treatAsAlias": false,
    "verificationStatus": "accepted"
\}

Update vacation

Updates vacation responder settings. Sample Input

\{
    "user_id": "me",
    "enable_auto_reply": true,
    "response_subject": "Out of Office: Vacation",
    "response_body_plain_text": "I am currently on vacation and will return on July 15th. For urgent matters, please contact my colleague at colleague@example.com.",
    "response_body_html": "<p>I am currently on vacation and will return on July 15th. For urgent matters, please contact my colleague at <a href='mailto:colleague@example.com'>colleague@example.com</a>.</p>",
    "restrict_to_contact": false,
    "restrict_to_domain": true,
    "start_time": 1688169600000,
    "end_time": 1689379200000
\}

Sample Output

\{
    "enableAutoReply": true,
    "responseSubject": "Out of Office: Vacation",
    "responseBodyPlainText": "I am currently on vacation and will return on July 15th. For urgent matters, please contact my colleague at colleague@example.com.",
    "restrictToContacts": false,
    "restrictToDomain": true,
    "startTime": "2023-07-01T00:00:00.000Z",
    "endTime": "2023-07-15T00:00:00.000Z"
\}

DDL operations

List labels (DDL)

Note that DDL operations can only be called directly by Connectors API, or when using CustomJS in the Embedded solution editor for e.g. DDL-dependent data mapping


Sample Input

{}

Sample Output

{
    "labels": [
        \{
            "id": "INBOX",
            "name": "INBOX",
            "type": "system"
        \},
        \{
            "id": "SENT",
            "name": "SENT",
            "type": "system"
        \},
        \{
            "id": "TRASH",
            "name": "TRASH",
            "type": "system"
        \},
        \{
            "id": "SPAM",
            "name": "SPAM",
            "type": "system"
        \},
        \{
            "id": "Label_1",
            "name": "Work",
            "type": "user"
        \},
        \{
            "id": "Label_2",
            "name": "Personal",
            "type": "user"
        \},
        \{
            "id": "Label_3",
            "name": "Urgent",
            "type": "user"
        \}
    ]
}

Was this page helpful?