// 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.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.messages.modify({
// The ID of the message to modify.
id: 'placeholder-value',
// 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
// {
// "addLabelIds": [],
// "removeLabelIds": []
// }
},
});
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.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.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.threads.get({
// The format to return the messages in.
format: 'placeholder-value',
// The ID of the thread to retrieve.
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",
// "messages": [],
// "snippet": "my_snippet"
// }
}
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.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.labels.get({
// The ID of the label to retrieve.
id: '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
// {
// "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;
});
// 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.insert',
'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.messages.import({
// Mark the email as permanently deleted (not TRASH) and only visible in Google Vault to a Vault administrator. Only used for G Suite accounts.
deleted: 'placeholder-value',
// Source for Gmail's internal date of the message.
internalDateSource: 'placeholder-value',
// Ignore the Gmail spam classifier decision and never mark this email as SPAM in the mailbox.
neverMarkSpam: 'placeholder-value',
// Process calendar invites in the email and add any extracted meetings to the Google Calendar for this user.
processForCalendar: 'placeholder-value',
// 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
// {
// "historyId": "my_historyId",
// "id": "my_id",
// "internalDate": "my_internalDate",
// "labelIds": [],
// "payload": {},
// "raw": "my_raw",
// "sizeEstimate": 0,
// "snippet": "my_snippet",
// "threadId": "my_threadId"
// }
},
media: {
mimeType: 'placeholder-value',
body: '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;
});