You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Next »

Introduction 

In this tutorial, we will show the process of sending emails using Microsoft Graph API with Joget JSON Tool. The guideline will help you automate the process of sending emails, making it a more efficient and streamlined process. This article will provide a step-by-step guide to help set up and send emails using Microsoft Graph API and Joget JSON Tool.

Set Up Azure Application

Before going to Joget to use the Microsoft Graph API, we first must create the Azure application that has the permission to use this API, follow the steps below and you will have everything you need to send emails using the Microsoft Graph API.

Create Developer Account

To start creating your Azure application, you must first sign up on Azure here, but simply signing up using your personal Microsoft account wouldn't work as it won't give you full access to Azure. To get this access, you will need to join the Microsoft Developer program.

To join the Microsoft Developer program, simply sign up on their website with your personal Microsoft account, and get yourself a Microsoft 365 Developer subscription, you can either purchase it, or get a 90 day free trial.

Use the email in the "Administrator" section to sign up for your Azure account and this time you will have full access to it.

Register Application

So now with the Azure account set up, we can begin registering an application. 

To register an application go to:

  1. Azure Active Directory
  2. App Registrations
  3. New Registration
  4. Choose a name for the app
  5. Select your support type, for this guide, we will be using the third one

  6. And for this guide, ignore the redirect URI
  7. Register


After this you should see in the app's overview you have an "Application (client) ID" and a "Directory (tenant) ID", these two are important so that your API call will actually be using your app and your account.

Get Client Secret

Next up is to get your client secret.

To do this, from the app's overview page, go to:

  1. Certificates and Secrets
  2. New Client Secret
  3. Enter description and expire duration
  4. Add client secret

After doing so, you now should have a "value" and "ID", copy paste this "value" somewhere like a Notepad.

Client Secret Value

Make sure you secure this value before leaving or refreshing the page as the value will become hidden afterwards.

Add API Permissions

Last thing to do is to give the Azure app the permission to send emails via the Microsoft Graph API.

To do this, from the app's overview page, go to:

  1. API Permissions
  2. Add a Permission
  3. Microsoft Graph
  4. Application Permissions (for this guide we are using application permissions)
  5. Add "Mail.Send"
  6. Optionally, also add "User.Read.All" (this is for if you want to see the list of users who can use this Azure app, by default, Microsoft should give you a dozen dummy accounts when creating an Azure account)
  7. Add Permissions
  8. Press "Grant Admin Consent for MSFT"

And now your Azure app has the permission to send emails!

Using Joget JSON Tool to Call API

The Joget JSON Tool is a plugin for app processes that lets you issue JSON web service calls. In order to properly send an email with the MS Graph API, you will need in total 2 of these JSON tools. One to request for an access token and the other to actually send the email.

Requesting Access Token

Courtesy to Microsoft's documentation, to acquire the access token, you will need a POST request to the url:

https://login.microsoftonline.com/[TENANT ID HERE]/oauth2/v2.0/token

So, enter the appropriate information into your first JSON Tool and keep the Body Type as "Request Parameters".

Make sure to insert your own tenant ID

Next up is to give the request the appropriate parameters, this request will need 4 things:

  • A client ID
  • The client secret
  • A grant type
  • And a scope

Following the steps above, you should have the client ID and client secret with you, simply enter those two values with the name "client_id" and "client_secret".

For the grant type, in this guide we are using the client credentials authentication flow, we are using this for this guide so that we don't need to worry about logging the user in when getting an access token. Enter the value "client_credentials" with the name "grant_type".

And finally for the scope enter the link:

  https://graph.microsoft.com/.default

Other authentications flow would let you be more specific with your scope, like entering "Mail.send" but for client credentials it must have a value with the "/.default" suffixed to the application ID URI, which by default is "https://graph.microsoft.com/". Enter the link to the value with the name "scope".

The result of this request takes form of a JSON object, if your request was successful, the JSON object should look something like this:

{
    "token_type": "Bearer",
    "expires_in": 3599,
    "ext_expires_in": 3599,
    "access_token": "412076657279206c6f6e67206a756d626c6564207069656365206f662074657874"
}

The "access_token" property of this JSON object is what we need for our second JSON tool, and for this guide, we will store this value in a workflow variable. You can create a workflow variable by going to the "Process Property", which in Joget DX8, is accessible via the pencil icon beside your process' name.

Add as many variables as you need and name them appropriately.

Back at your JSON tool, scroll down to the "Store to Workflow Variable" setting and enter the variable of your choice and give the JSON object name "access_token".

And with that, we have successfully requested and stored our access token for the second JSON tool.

Sending the Email

Dancing cow

Demo App

Here is the demo app that showcases this guide, please do keep in mind all of the information related to the Azure app has been left empty since those should be filled with your own Azure app. Most of these empty information can be find in the process of the application.





  • No labels