This sample repo shows you how to make multiple requests to Nylas in order to retrieve the inbox messages across multiple accounts and sort them by received date (most recent at the top) to create a "joint" inbox data source.
- Node.js v16.x
You'll need the following values:
ACCESS_TOKEN_ARRAY = "Token_1,Token_2,..."
CLIENT_ID = ""
CLIENT_SECRET = ""
Add the above values to a .env
file:
$ npm i
Run the script using following commands:
$ node multi_token_messages.js
When you run the script, you'll get an array of messages from all tokens output in your terminal:
[{
acccountId: '<ACCOUNT_ID>',
id: '<MESSAGE_ID>',
bcc: ['<EMAIL_PARTICIPANT>'],
body: '<MESSAGE_BODY>'
cc: ['<EMAIL_PARTICIPANT>'],
date: '<EPOCH_TIMESTAMP>',
events: ['<EVENT_IDS>'],
files: ['<FILE_IDS>'],
from: ['<EMAIL_PARTICIPANT>'],
labels: ['<LABEL_OBJECT>'], OR, folders: ['<FOLDER_OBJECT>']
replyTo: ['<EMAIL_PARTICIPANT>'],
snippet: '<SNIPPET>',
starred: '<BOOLEAN>',
unread: '<BOOLEAN>',
subject: '<SUBJECT>',
thread_id: '<THREAD_ID>',
to: ['<EMAIL_PARTICIPANT>']
}],
Visit our Nylas Node.js SDK documentation to learn more.