Saving Registrations Using Azure Logic Apps

by Brad Jolicoeur

I was recently implementing an online event registration form for a passion project I work on and needed a simple place to store the records that a group of authorized users could access. Google Sheets is a perfect candidate for this requirement since granting access to multiple users is easy and each user can subscribe to get notified when new records are added to the sheet. 

Azure Logic Apps are intended to be an inexpensive and easy way to integrate with Azure services and large number of third party services through a library of connectors.  There is Visual Studio support, but for simple integrations or workflows, the visual designer built into the Azure Portal works well. 

Azure Logic Apps have an integration with Google Sheets that made inserting rows easier than accessing the Google API directly and allowed me to add additional steps like adding the contact to our MailChimp list if they selected that option.

Since this use case is a relatively straight forward use of Azure Logic Apps, I thought I would share the steps I went through in this blog. 



Start off by creating a Google Sheet that includes the column labels you need in the first row of the sheet.

Google Sheet with registration column labels

Create a new Logic App in Azure by clicking 'Create a resource' and searching for Logic App.

Create Azure Logic App

Once the Logic App finished deploying select the Logic App and the Designer will load up

Selecting the HTTP request trigger

We want to trigger this workflow from a HTTP request, so select 'When a HTTP Request is received tile'

Setting the JSON Schema for the HTTP trigger

Add a JSON Schema for the document that will be posted to the Logic App. You can use the example schema below to get started.

   "properties": {
              "email": { "type": "string"},
              "firstName": { "type": "string"},
              "lastName": {"type": "string"},
              "phone": {"type": "string"},
               "submitted": {"type": "string"}

Expand the advanced options to set the Method. For this example we are going to select 'POST'

Adding HTTP method to trigger

Click the New Step button and search for Google Sheets and select Insert Row under the Google Sheets option.

Selecting Insert Row Google Sheets Action

You will get a prompt to log into Google. Use the account you created the Sheet under to log in. Once you are logged in you will be able to browse for the sheet you created under your account. The row 1 values will show up as fields and when you put the cursor in each field a list of fields from the JSON schema will show up on the right. Map the fields from the schema into the sheet.

Mapping the HTTP Post to the Google Sheet

Click the 'New Step' button again and add a response step to let the caller know it was successful.

Setting the response

In my real world Logic App I also added the MailChimp list add action after the response.  I'm leaving that out of this example to keep it concise.  I added the MailChimp step after the response so the user does not need to wait for that step to complete.  The Logic App will continue to process even after the response is sent and the user will get an email notification from MailChimp when the user is added to the list.  

Once you save the Logic App in the Designer the HTTP post URL will populate. To test the Logic App, copy that URL into Postman or another testing tool. Add the header Content-Type application/json and a JSON object that matches your JSON Schema to post.

Posting a message to test the logic app

The success response indicates that the request was successful. If there is an issue with the request an error message will be returned.

Now open up your Google Sheet and the row will be inserted

Showing the row is posted to the sheet

Once I had the Azure Logic App created, inserting a row to the Google Sheet was as simple as using HttpClient to post the JSON formatted data to the Logic App.

string myJson = JsonConvert.SerializeObject(model);
using (var client = new HttpClient())
           var response = await client.PostAsync(
                     new StringContent(myJson, Encoding.UTF8, "application/json"));

That's it! Hope you find this example useful.