Nylas Mail We Were Unable to Apply the Changes to Your Thread Please Try Again Later
Nylas Node.js SDK
Installation
Install the Nylas SDK:
npm install nylas or yarn add nylas
API Overview
Every resource (i.due east., letters, events, contacts) is accessed via an example of Nylas. Earlier making any requests, be sure to phone call config and initialize the Nylas instance with your clientId and clientSecret. Then, telephone call with and pass it your accessToken. The accessToken allows Nylas to make requests for a given account's resources.
const Nylas = ;
Nylas
;
const nylas = Nylas ;
Every resources method accepts an optional callback every bit the final argument:
nylas threads
;
Additionally, every resource method returns a promise, then you don't have to utilize callbacks if your code is hope-friendly. Hither's an case using promises:
nylas threads
;
And here's an example using async/await:
const getThreadCount = async {
const threads = wait nylas threads ;
return threads length ;
} ;
Authentication
The Nylas Rest API uses server-side (iii-legged) OAuth, and the Node.js bindings provide convenience methods that simplify the OAuth process. For more than information nigh authenticating users with Nylas, visit the API docs.
urlForAuthentication() takes in an options object, which must have a redirectURI property defined. Other supported, but optional, properties are:
-
loginHint- The user'due south email address, if known. -
state- An arbitrary string that will exist returned dorsum every bit a query param in yourredirectURI. -
scopes- An array of which scopes yous'd like to auth with. The Nylas API provides granular hallmark scopes that empower users with control over what level of admission your awarding has to their data. See supported Authentication Scopes for a full list of scopes and details behind the scopes. If omitted, defaults to all scopes.
Step 1: Redirect the user to Nylas
const Nylas = ;
Nylas
;
router
;
Footstep 2: Handle the Authentication Response
router
;
Getting IP Addresses to Whitelist
To obtain a dynamic listing of IP addresses that Nylas might apply to connect.
const nylas = Nylas ;
Nylas accounts
;
Fetching Messages, Events, Contacts, etc.
The Node.js SDK exposes API resources (threads, letters, folders, labels, files, events, contacts, etc.) as attributes of the nylas object. You tin query these resources in several ways. Available filters can be establish in the API docs.
const nylas = Nylas ;
nylas threads
;
nylas threads
;
nylas threads
;
nylas threads
;
nylas threads
;
nylas threads
;
Folders and Labels
The folders and labels API allows y'all to utilize Gmail labels to whole threads or individual messages and, for providers other than Gmail, to motion threads and letters between folders.
Note that folders and labels are identical from the standpoint of the SDK. The only difference is that a message can have many labels only only a single folder.
const nylas = Nylas ;
nylas labels
;
nylas folders
;
const fld = nylas folders ;
fld ;
permit spamLabel = undefined ;
nylas labels
;
File Metadata
const nylas = Nylas ;
const f = nylas files
;
f
;
On success, the file metadata should look like:
{ "content_type": "application/msword", "filename": "Reinstatement of Corporation.medico", "id": "9tm2n206vdj29wrhcxfvmvo4o", "message_ids": [ "93mtrpk4uo3wsvwcpb5yh57kp" ], "account_id": "6aakaxzi4j5gn6f7kbb9e0fxs", "object": "file", "size": 100864 } Uploading Files
Because of a bug in the library we use to issue HTTP requests, we can't pass a stream to the file upload part, which is why we read the file direct.
const fs = ;
const nylas = Nylas ;
fs
;
Downloading Files
const fs = ;
const nylas = Nylas ;
const f = nylas files
;
f
;
Creating and Sending Drafts
You tin create, relieve, and send drafts. To send, showtime create a draft object with the correct fields (To/CC/BCC, subject area, body, etc.), and then call transport. When the draft is sent, the Nylas API will return a Message object.
If you want to send a answer, set replyMessageId to the ID of the message to which yous're replying. When that field is ready, the Nylas API volition set email headers to mark your message every bit a respond.
const nylas = Nylas ;
const draft = nylas drafts
;
const tracking =
" links " : truthful
" opens " : truthful
" thread_replies " : truthful
" payload " : " 12345 "
draft
;
typhoon
;
const savedId = ' 1234 ' ;
nylas drafts
;
Searching Threads and Messages
You lot can run a full-text search on threads and messages using search and passing a string to query. By default, the Nylas API returns forty results, but y'all can pass a limit and offset to perform pagination.
const nylas = Nylas ;
nylas messages ;
Creating and Updating Webhooks
Y'all can programmatically create, read, update and delete webhooks.
const newWebhook = Nylas webhooks
;
newWebhook ;
Nylas webhooks
Nylas webhooks ;
Using the Delta Streaming API
const DELTA_EXCLUDE_TYPES = ' contact ' ' calendar ' ' outcome ' ' file ' ' tag ' ;
const nylas = Nylas ;
nylas deltas
;
Interacting with Events
You lot can send calendar invites to events using the Nylas API. To send invites and updates to the event's participants, prepare notify_participants to true.
const nylas = Nylas ;
const event = nylas events
;
event
;
nylas events
;
Sending and Retrieving Raw MIME
To send raw MIME, you can build a typhoon and, instead of providing the normal fields, pass the MIME in an object as rawMime.
To retrieve the raw MIME for an business relationship'south message, call getRaw on the message object, and the MIME will be returned in a promise.
const nylas = Nylas ;
const typhoon = nylas drafts ;
typhoon ;
nylas messages
;
Accounts
It'south possible to get details almost the business relationship you're accessing by using the account method:
const nylas = Nylas ;
nylas account ;
You can access the billing condition and cancel/reactivate an account for the accounts in your app by using the accounts method:
Nylas accounts
;
Nylas accounts
;
Nylas accounts
;
Nylas accounts
;
Open-Source API
The Nylas Sync Engine is open-source, and you tin also employ the Node.js SDK with the open-source API. Since the open-source API provides no authentication or security, connecting to information technology is simple.
It requires us to "auth" to it by passing the business relationship id as an auth token. Here's an example of fetching the messages of the kickoff business relationship after getting the business relationship ID:
const Nylas = ;
Nylas
;
Nylas accounts
;
Instance Apps
We have a few example Express apps in the case directory that show examples for authentication and webhooks. Yous can run them to see how they're implemented:
npm install or yarn
npm showtime or yarn outset
Note that you'll need to replace the Nylas app ID and app surreptitious in app.js or create a config.js file with your application'south credentials.
Contributing
We'd love your help making the Nylas Node.js SDK better. Come chat in the Nylas customs Slack channel or email support@nylas.com.
Please sign the Contributor License Agreement earlier submitting pull requests. (Information technology'southward similar to other projects, like NodeJS or Shooting star.)
Tests can be run with:
npm test
Our linter can exist run with:
npm run lint
To use the package during local development, symlink the directory:
npm link in the nylas-nodejs directory npm link nylas in the directory with your lawmaking that uses the package
Source: https://www.npmjs.com/package/nylas/v/4.7.0?activeTab=readme
Post a Comment for "Nylas Mail We Were Unable to Apply the Changes to Your Thread Please Try Again Later"