Connecting a WooCommerce Purchase to Microsoft Logic App
Recently, we had a client who was using WooCommerce to run a storefront for their business. However, they wanted to do additional processing after a purchase was made. They told us that they were not expecting high volume from their sales, with no more than 10 purchases coming in a month. Thus, we decided that there was little need to stand up a whole server and have it run constantly for a purchase every 3 days. Instead, we decided to use WooCommerce’s webhooks to invoke a logic app. Since their pricing is particularly attractive at low volumes, our client was on board.
Before we begin, we should get some nomenclature out of the way. If you’re already familiar with what a logic app and webhook is, please feel free to skip the next two sections.
What is a Logic App?
Logic apps are no-code way of building automations visually. They leverage Microsoft Azure’s serverless compute-on-demand framework to keep costs low and throughput high; you only pay when you use, and the costs are low. It also has hundreds of connectors (include Salesforce, Office 365, Twitter, Dropbox, Google services, and more) to connect to other products. If they don’t have what you need, you can create your own. In short, logic apps can add a lot of power to your business.
What is a Webhook?
Webhooks, at their core, are a way that applications allow themselves to be extended; they are a way for applications to report to third parties when events occur. They use HTTP verbs to make requests to the third party applications, allowing the third party apps “hook” into them. In our specific case, we will be using a webhook to have WooCommerce alert the logic app that an order has been created. WooCommerce does not care what the logic app does with this information, or that it is even a logic app that is receiving the information. It will simply send an alert that a order has been created.
Create Logic App
First, we set up the logic app in Azure. The process is really straightforward. Simply click Create a resource to start the process. Type “Logic App” into the search bar and pull up the product.
Click the Create button.
Then fill out the information about the logic app.
Once it is provisioned, you will want to open it. Azure will display a welcome screen where you can specify what kind of trigger that you want to use. The trigger is the event that will cause your logic app to start. In our case, we will be using a webhook to trigger the logic app. This will mean that our logic app will be waiting for the webhook to send it data. For this, select When a HTTP request is received.
Finally, save the logic app. This will generate an HTTP Post URL that we can use in the next section.
Create and Test Webhook
The next step is to create the webhook in WooCommerce. WooCommerce has great documentation on how to do it.
For our purposes, we will be using the HTTP Post URL from the previous step. This is how we direct WooCommerce to our logic app for processing. For the Topic, we’re going to be using “Order created”. You can leave the secret blank, as it will fill that out itself. With that, your webhook is set up!
The last step is to create a schema so that logic apps knows the shape of the data coming in. The easiest way to do that is to generate some test data and then use logic app’s tool for generating a schema from the demo data.
In order to generate demo data, just create a fake purchase within WooCommerce. This will send the request over to Azure. Once that is done, head over to the Azure portal and look at the run history.
Choose one of the successful runs and open it. There, you can see the input and output of the HTTP request. Copy the content of the Body.
Go back to the logic app’s home page and select Edit.
From there, expand When a HTTP request is received and click Use sample payload to generate schema. Paste the data from before and click Done.
With this, you can now build out your automation with all of the data that comes over from WooCommerce. For this particular project, we were creating users in a separate SQL database using their purchase information, then recording their purchases to drive a dashboard for their site. However, the possibilities are endless!
Let us help you out!
Code Vanguard has worked with clients of all sizes, helping them to use the cloud to scale with their business. We’ve helped them to developed tools and processes ranging from automated business flows to distributed cloud processing. If you’d like Code Vanguard to help your organization with Azure development, feel free to reach out to us!
Check out some of our other posts about Azure!