Skip to content

v5.7.0

Compare
Choose a tag to compare
@mrashed-dev mrashed-dev released this 31 Mar 21:12
· 95 commits to main since this release

This new release of the Nylas Python SDK a couple of new features and enhancements.

Release Notes

Added

  • Add Outbox support
  • Add support for new (beta) Integrations authentication (Integrations API, Grants API, Hosted Authentication for Integrations)
  • Add support for limit and offset for message/thread search
  • Add authentication_type field to Account

Changed

  • Bump supported API version to v2.5

Fixed

  • Fix Draft not sending metadata (#205)

Using New Features

Outbox

To send a new message through the outbox:

from nylas import APIClient
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

# Create a draft
draft = api_client.drafts.create()
draft.subject = "With Love, from Nylas"
draft.to = [{"email": "[email protected]", "name": "Me"}]
draft.body = "This email was sent using the Nylas email API. Visit https://nylas.com for details."

# Set the outbox-specific parameters
tomorrow = datetime.datetime.today() + datetime.timedelta(days=1)
day_after = tomorrow + datetime.timedelta(days=1)

# Send the outbox message
job_status = nylas.outbox.send(draft, tomorrow, retry_limit_datetime=day_after)

To update an outbox message after sending it

from nylas import APIClient
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

# Modify the message
draft = nylas.drafts.get('{id}')
draft.subject = "With Love, from Nylas"

# Set the outbox-specific parameters
tomorrow = datetime.datetime.today() + datetime.timedelta(days=1)
day_after = tomorrow + datetime.timedelta(days=1)

# Update the outbox message
job_status = nylas.outbox.update("job-status-id", draft=draft, send_at=tomorrow, retry_limit_datetime=day_after)

To delete an outbox job

from nylas import APIClient
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

nylas.outbox.delete("job-status-id")

We also support SendGrid operations. To get the authentication and verification status

from nylas import APIClient
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

verification = nylas.outbox.send_grid_verification_status()
verification.domain_verified
verification.sender_verified

To delete a SendGrid user:

from nylas import APIClient
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

nylas.outbox.delete_send_grid_sub_user("[email protected]")

Integration Authentication (Beta)

Integrations API

To list all integrations:

from nylas import APIClient
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

all_integrations = nylas.authentication.integrations.list()

To get an integration for a specific OAuth Provider:

from nylas import APIClient
from nylas.client.authentication_models import Authentication
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

integration = nylas.authentication.integrations.get(Authentication.Provider.ZOOM)

To create a new integration (we will use Zoom for example):

from nylas import APIClient
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

integration = nylas.authentication.integrations.create()
integration.name("My Zoom Intrgration")
integration.set_client_id("zoom.client.id")
integration.set_client_secret("zoom.client.secret")
integration.redirect_uris = ["https://www.nylas.com"]
integration.expires_in(1209600)
integration.save()

To update an existing integration:

from nylas import APIClient
from nylas.client.authentication_models import Authentication
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

zoom_integration = nylas.authentication.integrations.get(Authentication.Provider.ZOOM)
zoom_integration.name = "Updated name"
zoom_integration.save()

To delete an existing integration for a specific OAuth provider:

from nylas import APIClient
from nylas.client.authentication_models import Authentication
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

nylas.authentication.integrations.delete(Authentication.Provider.ZOOM);

Grants

To list all grants:

from nylas import APIClient
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

all_grants = nylas.authentication.grants.list()

To get a specific grant:

from nylas import APIClient
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

grant = nylas.authentication.grants.get("grant-id")

To create a new grant (we will use Zoom for example):

from nylas import APIClient
from nylas.client.authentication_models import Authentication
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

grant = nylas.authentication.grants.create()
grant.provider = Authentication.Provider.ZOOM
grant.settings = {"refresh_token": "zoom_refresh_token"}
grant.state = "test_state"
grant.scope = ["meeting:write"]
grant.metadata = {"sdk": "python sdk"}
grant.save()

To update an existing grant:

from nylas import APIClient
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

grant = nylas.authentication.grants.get("grant-id")
grant.metadata = {"sdk": "python sdk"}
grant.save()

To delete an existing grant:

from nylas import APIClient
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

nylas.authentication.grants.delete("grant_id");

To trigger a re-sync on a grant:

from nylas import APIClient
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

resyced_grant = nylas.authentication.grants.on-demand-sync("grant_id",  sync_from=60);

Hosted Authentication for Authentication

To begin the hosted authentication process and get a login url:

from nylas import APIClient
from nylas.client.authentication_models import Authentication
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

login_info = nylas.authentication.hosted_authentication(
  provider=Authentication.Provider.ZOOM,
  redirect_uri="https://www.nylas.com",
  settings={"refresh_token": "zoom_refresh_token"},
  scope=["meeting:write"],
  metadata={"sdk": "python sdk"},
  login_hint="[email protected]",
  state="my-state",
  expires_in=43200
)