programmatic redirect nylas email api

Introducing Programmatic Redirect of URIs

The Nylas API now makes it easy to manage customer subdomains with programmatic redirect of URIs.

Jieun Kim | November 25, 2019

When new customers sign-up for your platform and you generate a unique URI for them, it can help improve the customer onboarding experience if you can programmatically create redirect URIs for those customers.

Take Slack for example. All Slack users have unique slack URLs to access the app on the web, following a structure like nylas.slack.com. With programmatic redirect URIs on Nylas, all Nylas customers can automatically generate redirect URIs each time they’d like to provision a new customer.

How? Let’s take a look.

First, if you’d like to simply see your current redirect URIs (and other application info), you can do this by making a GET call to the `a/{client_id}/` endpoint.

curl -X GET "https://api.nylas.com/a/2ajt9foi41hf90hr50rj6flvr" \

-H "Content-Type: application/json" \

-H "Authorization: Basic mysUp3RS3crEtCl1EntS3crET="

 

The client_id is the ID of your Nylas developer application and the authorization is the client secret, passed in as an HTTP Basic Auth username.

curl -X PUT "https://api.nylas.com/a/2ajt0hf90hrrfoi41j6fl95vr" \

-H "Content-Type: application/json" \

-d '{

    "application_name": "My New App Name",

    "redirect_uris": [

    "http://localhost:5555/login_callback",

    "localhost",

      "https://customerA.myapplication.com/login_callback"

]

}'

 

Next, in order to update the URIs, make a PUT call to the a/{client_id}endpoint.

The authorization for this endpoint follows the same pattern as other account management endpoints, so the authorization is the client secret, passed in as an HTTP Basic Auth username.

The application_name  parameter is optional and will update the app’s name. If this field is omitted, no changes will be made to the application name. 

The redirect_uris parameter takes an array of strings; each string is a single redirect_uri for the application. Keep in mind that this is a PUT call, so you will need to include every redirect URI each time you update, rather than just adding a single redirect URI at a time. For example, in the code snippet above, if you had one redirect URI to start: http://localhost:5555/login_callback and wanted to add both localhost and https://customerA.myapplication.com/login_callback, you will need to pass all three strings to the array as shown. 

Sign up today to get a free API key and try it out, or if you’re already a customer, test out the new features and let us know what you think!

About the Author

jieun kim is a technical writer based in nyc. in her spare time, she enjoys contemplating unusual shapes and accumulating large stacks of books.

Ready to Start Building?

Connect up to 10 accounts for free today. No credit card required.