- Print
- DarkLight
- PDF
Create Typed Messages in Logic Apps Using Parse JSON
- Print
- DarkLight
- PDF
Having structured, or typed messages, becomes very important in Azure Logic Apps as it allows you to use data elements/attributes/fields in downstream actions as Dynamic Content. The problem is, how do we generate these typed messages when we don’t have XSD schemas, or OpenAPI (aka Swagger) API definitions? The answer lies in an action called Parse JSON.
Let’s look at an example. Imagine we are running an Apartment building complex. We want to be able to provide our tenants with the ability to log a maintenance ticket by sending an email into a mailbox. However, we don’t want to be manually creating these tickets, we want to automate them. As a result, we will call an API in our Work Order Management system that will take care of it for us.
This API will return a response that can be useful in updating our customer with a context-relevant email. The problem is, our API doesn’t have a typed message body that we can take advantage of if we want to send a personalized email back to our customer.
In order to provide a relevant response back to our customer, we can use the Parse JSON action and use this output from our HTTP call to generate a JSON schema. We can click on + New step within the Logic Apps designer and then search for Parse JSON.
We now want to click on Use sample payload to generate schema and then can paste in the output from our API call and click Done.
We need to populate our Content field by adding the Body - Dynamic content from our API Call. In addition, we will discover our Schema text area has been populated with our JSON schema that was generated from our sample.
Since we used the Parse JSON action, we can now see Dynamic Content that includes our data attributes from our API call. This allows us to provide a personalized email back to our customer.
Conclusion
Using typed messages unlocks opportunities to leverage the data that is being exchanged between Azure Logic Apps and other systems. For some services, they will include an API specification, like Swagger, which helps immensely. But, when an API specification is not available, we can use a sample message and Parse JSON to create typed messages for us.