Overcoming Challenges: Working with JSON and Webhooks on Make.com
Introduction
Working with JSON data can sometimes be a bit tricky, especially when you're dealing with webhooks and email templates. In this blog post, we'll be discussing a common problem faced by many Make.com users and provide a step-by-step solution to overcome it.
The Problem
Let's say you're working on getting a series of keys on a JSON webhook input into an email template. Some of the keys may be empty, and if you just pass them to the MailGun email template, it will complain that the value is missing. You've managed to get it working with a custom JSON structure for the mail variables that you parse and iterate on, but you're not using all the variables you need in this example. You're then iterating on the array object that is created from the previously mapped JSON keys and aggregating it into a MailGun template variables destination type while filtering out any keys that may not have a value. This is required since some source events do not contain that data, while others do. Mailgun is taking the output aggregate array and is happy. But is this the correct way to do this? Or is there a more efficient / optimized way to handle this that doesn’t require creating and re-parsing a JSON object into a different format than what the webhook receives?
The Solution
With Mailgun, if a value is blank/empty string, then it’s not allowed to be submitted. You might see if it will allow NULL instead and the ifempty() function can help you. This basically just says if value is empty, then use null instead. null is slightly different than empty string. If you need to do transformations, my approach would definitely be to do them before you aggregate the array. You then won’t need to merge the arrays. But you can’t put a router between an iterator and aggregator. If you only have a few of the values that will need transforming, you could add a Set Variable module in between your iterator and aggregator. Using switch() or if() formulas instead of a router, you can replace just certain key/value pairs while leaving the others intact.
Troubleshooting Tips
If you have more complex transformations, I would explore the idea of creating an additional scenario to handle this and then send the key/value to the scenario webhook using an HTTP module in between the iterator and aggregator, and then use the webhook response as the value to aggregate. If security is a concern, you can add security to the second webhook, so that it only returns data if a unique key is passed in the webhook headers—a unique key that only your organisation knows. You can create this key as a global variable and pass it through the HTTP module from the calling function, and check it from a filter straight after the webhook in the secondary scenario.
Conclusion
In conclusion, working with JSON data and webhooks can be a bit tricky, but with the right approach and tools, you can easily overcome these challenges. Remember to always check your data and make sure it's in the correct format before passing it to other services. And don't forget to secure your webhooks to prevent unauthorized access. Happy coding!
You do have further questions?
Ask your question via E-Mail: Richard@make-app.de
Book a paid Support & Consulting Session
New Make.com user? Sign up through this Affiliate Link to receive 10.000 operations for FREE.