Nylas Mail- We Were Unable to Apply the Changes to Your Thread
Nylas Node.js SDK
Installation
Install the Nylas SDK:
npm install nylas
or yarn add nylas
API Overview
Every resource (i.eastward., messages, events, contacts) is accessed via an case of Nylas
. Before making whatever requests, exist sure to call config
and initialize the Nylas
case with your clientId
and clientSecret
. And then, call with
and laissez passer it your accessToken
. The accessToken
allows Nylas
to make requests for a given account'due south resource.
const Nylas = ;
Nylas
;
const nylas = Nylas ;
Every resource method accepts an optional callback as the final argument:
nylas threads
;
Additionally, every resource method returns a promise, so yous don't have to apply callbacks if your code is promise-friendly. Hither's an example using promises:
nylas threads
;
And here'southward an example using async/expect:
const getThreadCount = async {
const threads = await nylas threads ;
return threads length ;
} ;
Authentication
The Nylas Residual API uses server-side (three-legged) OAuth, and the Node.js bindings provide convenience methods that simplify the OAuth process. For more information almost authenticating users with Nylas, visit the API docs.
urlForAuthentication()
takes in an options
object, which must take a redirectURI
property defined. Other supported, but optional, properties are:
-
loginHint
- The user'south email address, if known. -
land
- An capricious cord that volition be returned back equally a query param in yourredirectURI
. -
scopes
- An array of which scopes y'all'd similar to auth with. The Nylas API provides granular authentication scopes that empower users with control over what level of access your awarding has to their data. Run across supported Hallmark Scopes for a full list of scopes and details behind the scopes. If omitted, defaults to all scopes.
Step i: Redirect the user to Nylas
const Nylas = ;
Nylas
;
router
;
Step 2: Handle the Authentication Response
router
;
Getting IP Addresses to Whitelist
To obtain a dynamic listing of IP addresses that Nylas might use to connect.
const nylas = Nylas ;
Nylas accounts
;
Fetching Messages, Events, Contacts, etc.
The Node.js SDK exposes API resource (threads, messages, folders, labels, files, events, contacts, etc.) as attributes of the nylas
object. You can query these resources in several means. Available filters can exist found 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 you to apply Gmail labels to whole threads or individual letters and, for providers other than Gmail, to motion threads and messages between folders.
Note that folders and labels are identical from the standpoint of the SDK. The only difference is that a bulletin can have many labels but simply a unmarried folder.
const nylas = Nylas ;
nylas labels
;
nylas folders
;
const fld = nylas folders ;
fld ;
let 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.doc", "id": "9tm2n206vdj29wrhcxfvmvo4o", "message_ids": [ "93mtrpk4uo3wsvwcpb5yh57kp" ], "account_id": "6aakaxzi4j5gn6f7kbb9e0fxs", "object": "file", "size": 100864 }
Uploading Files
Considering of a bug in the library we apply to issue HTTP requests, nosotros can't laissez passer a stream to the file upload function, which is why we read the file straight.
const fs = ;
const nylas = Nylas ;
fs
;
Downloading Files
const fs = ;
const nylas = Nylas ;
const f = nylas files
;
f
;
Creating and Sending Drafts
Yous can create, save, and send drafts. To send, beginning create a draft object with the correct fields (To/CC/BCC, subject area, trunk, etc.), and then call send
. When the draft is sent, the Nylas API will return a Message
object.
If y'all want to ship a reply, set replyMessageId
to the ID of the message to which you're replying. When that field is set, the Nylas API will set up electronic mail headers to mark your message as a respond.
const nylas = Nylas ;
const draft = nylas drafts
;
const tracking =
" links " : true
" opens " : truthful
" thread_replies " : true
" payload " : " 12345 "
draft
;
draft
;
const savedId = ' 1234 ' ;
nylas drafts
;
Searching Threads and Messages
You can run a full-text search on threads and messages using search
and passing a string to query. By default, the Nylas API returns 40 results, but you can laissez passer a limit
and offset
to perform pagination.
const nylas = Nylas ;
nylas letters ;
Creating and Updating Webhooks
You 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 ' ' event ' ' file ' ' tag ' ;
const nylas = Nylas ;
nylas deltas
;
Interacting with Events
You can send calendar invites to events using the Nylas API. To ship invites and updates to the event's participants, ready notify_participants
to true
.
const nylas = Nylas ;
const result = nylas events
;
event
;
nylas events
;
Sending and Retrieving Raw MIME
To send raw MIME, you lot 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's message, call getRaw
on the message object, and the MIME will be returned in a promise.
const nylas = Nylas ;
const draft = nylas drafts ;
draft ;
nylas messages
;
Accounts
It'southward possible to get details about the account y'all're accessing past using the account
method:
const nylas = Nylas ;
nylas account ;
You can access the billing status and cancel/reactivate an business relationship 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 up-source, and yous tin also apply the Node.js SDK with the open-source API. Since the open up-source API provides no hallmark or security, connecting to information technology is simple.
It requires usa to "auth" to it by passing the account id as an auth token. Here'due south an example of fetching the messages of the first account after getting the account ID:
const Nylas = ;
Nylas
;
Nylas accounts
;
Example Apps
We take a few example Limited apps in the case
directory that show examples for authentication and webhooks. You tin run them to meet how they're implemented:
npm install
or yarn
npm offset
or yarn get-go
Note that you'll need to replace the Nylas app ID and app secret in app.js
or create a config.js
file with your application'southward credentials.
Contributing
We'd love your assist making the Nylas Node.js SDK ameliorate. Come up chat in the Nylas community Slack channel or email back up@nylas.com.
Delight sign the Contributor License Understanding before submitting pull requests. (It'south similar to other projects, similar NodeJS or Meteor.)
Tests tin can be run with:
npm examination
Our linter can be 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 code that uses the package
Source: https://www.npmjs.com/package/nylas/v/4.7.0?activeTab=readme
0 Response to "Nylas Mail- We Were Unable to Apply the Changes to Your Thread"
ارسال یک نظر