// Before running the sample:
// - Enable the API at:
// https://console.developers.google.com/apis/api/gmail.googleapis.com
// - Login into gcloud by running:
// `$ gcloud auth application-default login`
// - Install the npm module by running:
// `$ npm install googleapis`
const {google} = require('googleapis');
const gmail = google.gmail('v1');
async function main() {
const auth = new google.auth.GoogleAuth({
// Scopes can be specified either as an array or as a single, space-delimited string.
scopes: [
'https://mail.google.com/',
'https://www.googleapis.com/auth/gmail.addons.current.message.action',
'https://www.googleapis.com/auth/gmail.addons.current.message.metadata',
'https://www.googleapis.com/auth/gmail.addons.current.message.readonly',
'https://www.googleapis.com/auth/gmail.metadata',
'https://www.googleapis.com/auth/gmail.modify',
'https://www.googleapis.com/auth/gmail.readonly',
],
});
// Acquire an auth client, and bind it to all future calls
const authClient = await auth.getClient();
google.options({auth: authClient});
// Do the magic
const res = await gmail.users.messages.get({
// The format to return the message in.
format: 'placeholder-value',
// The ID of the message to retrieve. This ID is usually retrieved using `messages.list`. The ID is also contained in the result when a message is inserted (`messages.insert`) or imported (`messages.import`).
id: 'placeholder-value',
// When given and format is `METADATA`, only include headers specified.
metadataHeaders: 'placeholder-value',
// The user's email address. The special value `me` can be used to indicate the authenticated user.
userId: 'placeholder-value',
});
console.log(res.data);
// Example response
// {
// "historyId": "my_historyId",
// "id": "my_id",
// "internalDate": "my_internalDate",
// "labelIds": [],
// "payload": {},
// "raw": "my_raw",
// "sizeEstimate": 0,
// "snippet": "my_snippet",
// "threadId": "my_threadId"
// }
}
main().catch(e => {
console.error(e);
throw e;
});
// Before running the sample:
// - Enable the API at:
// https://console.developers.google.com/apis/api/gmail.googleapis.com
// - Login into gcloud by running:
// `$ gcloud auth application-default login`
// - Install the npm module by running:
// `$ npm install googleapis`
const {google} = require('googleapis');
const gmail = google.gmail('v1');
async function main() {
const auth = new google.auth.GoogleAuth({
// Scopes can be specified either as an array or as a single, space-delimited string.
scopes: [
'https://mail.google.com/',
'https://www.googleapis.com/auth/gmail.metadata',
'https://www.googleapis.com/auth/gmail.modify',
'https://www.googleapis.com/auth/gmail.readonly',
],
});
// Acquire an auth client, and bind it to all future calls
const authClient = await auth.getClient();
google.options({auth: authClient});
// Do the magic
const res = await gmail.users.messages.list({
// Include messages from `SPAM` and `TRASH` in the results.
includeSpamTrash: 'placeholder-value',
// Only return messages with labels that match all of the specified label IDs.
labelIds: 'placeholder-value',
// Maximum number of messages to return. This field defaults to 100. The maximum allowed value for this field is 500.
maxResults: 'placeholder-value',
// Page token to retrieve a specific page of results in the list.
pageToken: 'placeholder-value',
// Only return messages matching the specified query. Supports the same query format as the Gmail search box. For example, `"from:someuser@example.com rfc822msgid: is:unread"`. Parameter cannot be used when accessing the api using the gmail.metadata scope.
q: 'placeholder-value',
// The user's email address. The special value `me` can be used to indicate the authenticated user.
userId: 'placeholder-value',
});
console.log(res.data);
// Example response
// {
// "messages": [],
// "nextPageToken": "my_nextPageToken",
// "resultSizeEstimate": 0
// }
}
main().catch(e => {
console.error(e);
throw e;
});
// Before running the sample:
// - Enable the API at:
// https://console.developers.google.com/apis/api/gmail.googleapis.com
// - Login into gcloud by running:
// `$ gcloud auth application-default login`
// - Install the npm module by running:
// `$ npm install googleapis`
const {google} = require('googleapis');
const gmail = google.gmail('v1');
async function main() {
const auth = new google.auth.GoogleAuth({
// Scopes can be specified either as an array or as a single, space-delimited string.
scopes: [
'https://mail.google.com/',
'https://www.googleapis.com/auth/gmail.labels',
'https://www.googleapis.com/auth/gmail.modify',
],
});
// Acquire an auth client, and bind it to all future calls
const authClient = await auth.getClient();
google.options({auth: authClient});
// Do the magic
const res = await gmail.users.labels.create({
// The user's email address. The special value `me` can be used to indicate the authenticated user.
userId: 'placeholder-value',
// Request body metadata
requestBody: {
// request body parameters
// {
// "color": {},
// "id": "my_id",
// "labelListVisibility": "my_labelListVisibility",
// "messageListVisibility": "my_messageListVisibility",
// "messagesTotal": 0,
// "messagesUnread": 0,
// "name": "my_name",
// "threadsTotal": 0,
// "threadsUnread": 0,
// "type": "my_type"
// }
},
});
console.log(res.data);
// Example response
// {
// "color": {},
// "id": "my_id",
// "labelListVisibility": "my_labelListVisibility",
// "messageListVisibility": "my_messageListVisibility",
// "messagesTotal": 0,
// "messagesUnread": 0,
// "name": "my_name",
// "threadsTotal": 0,
// "threadsUnread": 0,
// "type": "my_type"
// }
}
main().catch(e => {
console.error(e);
throw e;
});