{{announcement.body}}
{{announcement.title}}

Low Code Serverless Integration With SendGrid Using Kumologica

DZone 's Guide to

Low Code Serverless Integration With SendGrid Using Kumologica

In this article, we see how to build a simple order management service that will furnish and send a purchase receipt email using SendGrid.

· Integration Zone ·
Free Resource

When making an online purchase, customers expect to receive purchase receipt emails from the vendor they do business with. Any delays in receipt of email, or emails being delivered to the spam folder can lead to a poor customer experience and may impact your brand and potentially may impact revenue.

Few aspects for having a good purchase receipts are :

  1. Proper branding and design of your purchase receipt.
  2. Proper furnishing of purchase content.- Price, Shipping, order date etc.
  3. Responsive nature of purchase receipt email.

SendGrid is a communication platform for transactional and marketing email delivery. It provides features for configuring email templates that can be used for the email delivery for different scenarios such as transaction emails, account creation emails, password reset emails, purchase receipt emails, account notification emails and more. In this article, we see how to build a simple order management service that will furnish and send a purchase receipt email using SendGrid. The service will integrate with SendGrid using Kumologica SendGrid node.

Kumologica is a free low-code development tool to build serverless integrations. You can learn more about Kumologica in this medium article or subscribe to our YouTube channel for the latest videos.


Use Case

We are going to implement a simple order management service for an online shopping portal. This service will accept the request from the shopping portal (UI) when the customer makes a purchase. The request will be first stored in an order management System database and then the price calculation is carried out by the service before sending the purchase receipt email to the customer.

Flow logic



Prerequisites

  1. Kumologica designer installed in your machine. https://kumologica.com/download.html
  2. Create a AWS DynamoDB table with the primary key as “orderid”.

Note: This is to simulate a order management system data store.

     3.Create an account in SendGrid and configure a Dynamic Template.

     4. Go to Email API and select Dynamic templates.

     5. Click on “Create a Dynamic Template” and provide a template name.

     6. Go to the “Code Editor” and provide your template. For this use case you may also pick up the template we have used.

Code editor in SendGrid UI



Implementation

Steps:

  1. Open Kumologica Designer, click on Add more nodes option on the bottom left corner of the designer to install the SendGrid node. Once installation is completed restart the designer.

Add more nodes panel


  1. Click the Home button and choose Create New Kumologica Project.
  2. Enter name (for example OrderManagementFlow), select directory for project and switch Source into From Existing Flow …
  3. Copy and Paste the following flow
  4. press Create Button.

You should be seeing flow as given below on the designer canvas.

Understanding the flow

  1. POST /order is the EventListener node with event source as Amazon API gateway , verb as POST , path as /order. The flow expected the following payload structure as the request.
JSON
 




x


 
1
{
2
    "orderid": "30077AB",
3
    "orderdate": "January 09 2020",
4
    "item": "Laptop",
5
    "itemmodel": "black",
6
    "qty": 2,
7
    "address": "8 , River road, Penrith,NSW,2186",
8
    "email" : "abc@gmail.com"
9
}



     2. Log_Entry logs the incoming payload in AWS CloudWatch.

     3. StoreToVariable is to store the entire payload in a variable to use during receipt preparation.

    4. OrderManagementSystem is the Amazon DynamoDB node to store the incoming order request.

    5. ReceiptPreperation is the datamapper node which is used for implementing the price calculation          logic as well as mapping the content for SendGrid node.

Plain Text
 




xxxxxxxxxx
1
20


1
(
2
$orderdata := $flowContext("payload","vars");
3
$itemprice := 12;
4
$shipping := 4.25;
5
$tax := 0.25;
6
$subtotal := $orderdata.qty * 12;
7
$total := $subtotal + $shipping + $tax ;
8
{
9
  "orderid" : $orderdata.orderid,
10
  "item" : $orderdata.item,
11
  "itemmodel": $orderdata.itemmodel,
12
  "address" : $orderdata.address,
13
  "orderdate" : $orderdata.orderdate,
14
  "subtotal": $subtotal,
15
  "itemprice": 12,
16
  "shipping": 4.25,
17
  "tax": 0.25,
18
  "qty": $orderdata.qty,
19
  "total": $total
20
};)


In the above logic in data mapper itemprice , shipping fee, tax etc are hardcoded for demonstration purpose only. These values are fetched from different system in real world.

6. SendGrid node sends the prepared receipt content along with the recipient details to SendGrid platform.

Note: Ensure to have the API key for accessing the SendGrid platform

7. Success is the EventListener End node responding with 202 http response code and payload as {"status" : "confirmed"}


Deployment

  1. Select CLOUD tab on the right panel of Kumologica designer, select your AWS Profile.
  2. Go to “Trigger” section under cloud tab and select the AmazonAPI Gateway.

     3. Press Deploy button.

Try It

Invoke your API with the following url and payload.

Plain Text
 




xxxxxxxxxx
1
11


 
1
Url: https://<<apigatewayid>>.execute-api.ap-southeast-2.amazonaws.com/test/order
2
Payload :
3
{
4
    "orderid": "30077AB",
5
    "orderdate": "January 09 2020",
6
    "item": "Laptop",
7
    "itemmodel": "black",
8
    "qty": 2,
9
    "address": "8 , River road, Penrith,NSW,2186",
10
    "email" : "abc@gmail.com"
11
}


You will be receiving the following purchase receipt content.


Conclusion

This article presented how easy Kumologica Designer flow integrates with SendGrid platform as part order management service to furnish and send a purchase receipt to the customer.

Remember Kumologica is totally free to download and use. Go ahead and give it a try, we would love to hear your feedback.

Topics:
aws, aws lambda, integration, kumologica, low code, microservice, sendgrid, serverless

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}