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.
Expand the advanced options to set the Method. For this example we are going to select 'POST'
Click the New Step button and search for Google Sheets and select Insert Row under the Google Sheets option.
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.
Click the 'New Step' button again and add a response step to let the caller know it was successful.
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.
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
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"));