In this episode Jonathan and Jamie discuss using webhooks with Moltin.
Jamie: Hi, folks. I'm Jamie, Developer Advocate at Moltin.
Jonathan: And I'm Jonathan, Front End Engineer.
Jamie: This week, we're going to be discussing how you can get started using integrations or webhooks as we like to call them internally. Webhooks are a great way for anyone looking to integrate Moltin into their already existing platform. Or if you’re just kind of looking to offer some extended functionality for your store or your project, whatever you are looking to build. You can use webhooks.
Jamie: So webhooks are so cool because you see other services like, Netify, for example, who use webhooks as a build, part of the build process. You can just trigger a webhook and it'll start building your site. With Moltin, when there's a new order, that's something we can throw out to another service. It could create receipts, it could do a lot more. So, like, I think it's interesting that we discuss some of the ideas around webhooks and what we can do with them, really. And maybe, you know ... we got a lot of examples we can show as well. So, love to share with you some of the examples that we've got. Yeah, we'll talk about that. So, like, what's your thoughts on webhooks and where it ... how it stands at Moltin, right now? Before we dive into any examples.
Jonathan: So, I'd say, like, integrations is probably one of the lesser known APIs on our platform. It's probably, under utilized by a lot of our customers. And really, what you can do with integrations is actually kind of tie in other services, that cover functionality that Moltin doesn't offer.
Jonathan: So, for example, when an order is paid, you might want to fire off a receipt. Moltin doesn't offer that functionality out of the box. But, with our integrations API, you can tie in with a service like Postmark or with a service, like SendGrid, and send our email when your order's paid, send that email receipt.
Jonathan: Same for SMS, you can Twilio, to do exactly the same. So, those are very simple answers that offer powerful functionality and that tie ins with other APIs you may already be using.
Jamie: Exactly, yeah. That's cool. I think that's really powerful because Moltin is just once piece of a larger puzzle. And if you're using Moltin just for orders and carts or you venture to use our catalog system, you can just extend Moltin, you know, massively, with an array of webhooks. And the different types of webhooks that we've got, looking here. All of the observable events, we've got brands, we've got carts, categories, collections. Pretty much all of our API, any of the special things that happen, such as being created, updated, deleted. Orders, like, the most common that we see used, like the receipts that you mentioned. So, when an order is being fulfilled, paid, refunded ... like, the refunded thing, you can integrate that with a payment provider, so you can maybe send a hook back to go and refund a payment.
Jamie: And if a payment is through a manual gateway, something that's not built on Moltin, you can handle all of that through webhooks. You haven't got to build any custom server logic, yourself, to handle payments. We can, kind of just, give you a webhook and you can do one piece of a larger puzzle. And it just feels really isolated and following the microservice of which we advocate.
Jonathan: Yeah, there really are endless possibilities. The, kind of, the only limit, I would say, is your imagination. You know, we see a lot of customers doing things with Algolia, so they want to index their product catalog with Algolia, we got an example that shows you how to do that using a service function.
Jamie: Yeah, so we got service function, here, showing you how to sync data to Algolia. So, I use Algolia myself on some projects and I've used it with a lot of Moltin projects as well and it's really powerful when you want to, kind of, have instant search on a website. You know, we're not the search experts, we're the eCommerce experts in APIs. So, I'm able to offload some of that capability to another service and utilize that and I can have super, super fast search results coming back with all my products that I wanted. And filter in all of the attributes of all of those products, as well.
Jonathan: Yeah, yeah.
Jamie: All the facets search you get for free with Algolia. And that's done with, you know, orders and products, So the next example, here, is simply, when an order is being created but this can be extended when a product is being created or a catalog is created. We dive into the code, we'll have a look at the service function here. This is just a tiny service function that runs on ... I think this is working on, Zeit Now, but it can work on AWS Lambda and Netify functions and any Azure and any of those services.
Jamie: This specific example I got here, it just, pretty much, initializes Algolia. And from there, we're able to access the index within Algolia. And this kind of stuff here, we're able to parse the data that's coming from Moltin. And we get a bunch of data. So, inside of the documentation, you can have a look at the event payload. Inside of the event payload, you actually get the resources that were affected by the event. So, if someone creates a new product then you will get that data inside-
Jonathan: Get that full product payload.
Jamie: Exactly, yeah. So, it's pretty cool. Don't you think?
Jonathan: Yeah. Yeah, last week, we talked about JAMstack and Netify and that ties in nicely to this.
Jonathan: And obviously with static sites, those API request are made on build time to build your product pages, etc. So, with Moltin's events and webhooks, we can fire a build webhook to Netify when you've updated a product or you've created a new one, even deleted one or added a new category product or ... as we've said before, the possibilities are endless. I think the ethos, really, behind all of this is ... as you said, we're not the search experts, Algolia are.
Jonathan: So, we, kind of, offload that functionality to them but we make it easy to integrate. So-
Jonathan: How do we go about, actually, creating one of these webhooks in Moltin, how would I do that?
Jamie: Yeah, so We make it really easy for people to add these webhooks. So, we have the ability to do it directly with the API. So, if you just want to run a cURL command or even if you wanted to, programmatically create an integration through our SDK to, you know, or through a library or just plain old HTTP, you could that. You can do it directly through the API and pass all this data here.
Jamie: We, also, have a dashboard, which you're one of the core engineers of that and so we now have inside the dashboard-
Jonathan: Look at that.
Jamie: the ability to list all of your current integrations that what we've got now is just a list of all our existing integrations. Then, we can, kind of, see the status as well. So, we can see that this order confirmation is enabled and we can see what it observes as well. This one, specifically, is just a, you know, it's kind of ... it'll only acknowledge itself and run that hook when an order is paid.
Jamie: And I can, kind of, dive into this one and I can see all the information such as the URL. And this is a secret key and the secret key is something that you can configure in the dashboard. So, you don't just want anybody to be able to access your serverless function, if you've got it somewhere. So, what we allow you to do is provide a secret key. So, when any of our services trigger a webhook, it can send along that secret key as well. So, the service function can go ... has this guide
Jonathan: So, you just, kind of, check that in the service function and otherwise, return an error, right?
Jamie: Yeah, exactly. So, we'll only go and ... we'll only, kind of , send an email or sync to Algolia if that secret is, in fact, coming from Moltin. It's just a way to check its authenticity. We can provide more details with integration, like a description, the name. Then we can check all the observables here. So, if we, actually, wanted to run this auto-confirmation email when someone has authorized a payment or has refunded. We can just do that and we can save this if we wanted. You can, also, disable them, as well. And then, what we've got on the right here is a bunch of logs. So, every time that this service is ran, we’ve just been hacking around here, working on a bunch of examples we’ve had in the past. So, we can see the status codes that are coming back from the hook. So, when that event expired this is the service returning to us. So, in this case, the probably just forgot to just turn something on
Jamie: bunch of 500s or we just, kind of-
Jonathan: I think those need sorting right?
Jamie: Probably, yeah, I think these kind of need to flip the order, so you can see that we've been doing some work recently and-
Jonathan: We should probably fix that.
Jamie: Yeah, probably should. Hothe most recent one at the top, that's a great feature that we've discovered today, so we'll add that to your backlog.
Jonathan: Always moving that needle.
Jamie: Move that needle. Get that added to your backlog. So, yeah, obviously you can delete this by hook if you didn’t want it.
Jonathan: So, [inaudible 00:09:03] you know about the power of this and we can tie it in with the APIs but seems to me that's a bit of legwork. For example, if I just wanted to add confirmation email-
Jonathan: do we have some plans to offer some kind of 1-click enablement. Is that something we can do?
Jamie: Yeah, that would be super awesome andI think, Looking at our current GitHub example, that we got here. If you wanted to send a shipping email, you can do that today using the example that we have. You can extend to, kind of, custom item template. And this, specifically, uses PostMark and PostMark is a great email service. It just does transactional emails. That's all it does and it's really good at it.
Jamie: And they've got some nice templates, as well. So, if you're looking to send a receipt, they, kind of, got things like that already baked that work on pretty much all devices. Mobile devices and things like that. But you can just use for free, as well. So, you got a good free plan. You can sign up, it’s relatively cheap. And there's a wide variety of these, like SendGrid, Mail Gun and bunch of others. Obviously, Amazon has their own.
Jamie: Yeah, so I think what would be super cool is we've got instructions here how you can deploy this, in Zeit Now, Azure, all of the others. But wouldn't it be cool in the dashboard if there’s just a button to enable this? It would super cool-
Jamie: powerful. And it's definitely something that we could, potentially, hack on and get in there [inaudible 00:10:26] if our uses wanted that.
Jamie: Certainly, let us know if that's something of interest. Then we'll try and get that, kind of, done. Yeah, that's a great idea. It's a great idea.
Jonathan: So, what other kind of services would you like to see Moltin integrate with using these APIs. I mean, we've talked about Algolia indexing all of your catalog, talked about emails, SMS with Twilio. What do you think is the next thing? What about something like taxes? We don't do taxes or shipping.
Jamie: Yep, yep. So, we don't do taxes or shipping but with the serverless function, you can integrate it with a tax provider to update ... update something on your side when someone adds something-
Jonathan: So, there's like cart hooks, right?
Jamie: Yeah, yeah, the cart hooks. Let me have a look at those. So, we've got a cart updated. So, every time the cart's updated, we can get payload.
Jamie: And run some checks-
Jonathan: Recalculate the tax?
Jamie: Possibly, yeah. Yeah, that would be ... that would be definitely this case as well.
Jamie: And shipping, as well, when an order's been paid or marked as fulfilled. When the order has been fulfilled, we can, then, go and tell the partner shipping company, that the order can be shipped. So you can go and tell DHL, TNT, you can go tell all of those guys, "this order's been shipped. This is the reference for the order." And then, on their side, providing you have kind of, your own serverless function that's managing the logic. Pass that to that service and pass any relevant data back to Moltin. And that's important, as well, is inside the service function that you're passing data to, you can always send data back to Moltin, as well, which is-
Jonathan: So, essentially, you could have an order paid hook. On that order paid, we're going to use some kind of shipping provider. Once they mark that as shipped, then we can then update our order in the Moltin API. So-
Jonathan: it works both ways. Awesome.
Jamie: So, we recently published price on our website. It's been a hot topic, if you haven't been following. But, we’ve recently restructured our pricing plan. And pricing for webhooks is available. So, depending on, kind of, the revenue that you're generating and taking through your business that’s using Moltin. If you copy down to the free tier and we, kind of, used this hook to a hundred dollars a month. It's free to use. If you want to use events, it's going to be fifteen dollars a month. And the power to extend Moltin and do all this other stuff outside of it and then bring that data back, I think fifteen dollars to be able to do that is really-
Jamie: And that, obviously, expands as the price gets-
Jamie: tied for how much revenue you create and but, obviously, the amount of webhooks that you fire would probably increase, as well. The cost would be reflected in there to, kind of, the usage.
Jonathan: Sounds awesome. Yeah.
Jamie: It's really cool. Good. But also, just off the back of the pricing here, as well, if you're using webhooks with a JAMstack like Gatsby. So, every time a product is updated or created, you could, technically, build your website. And then, when a customer views your website, they wouldn't have to get the product from the Moltin API, so it would never make those API calls but it would just get the static HTML. So, that reduces API calls and that, you know, that would affect the pricing as well. So-
Jonathan: That's, kind of, why that shift in the pricing model has gone from what used to be API request based, model now is order revenue based. So, it's, kind of, adapted to the way people are building sites with Moltin now with using the JAMstack.
Jamie: And I think we’ve seen that across the industry, as well. People aren't just charging per API requests because there's ways to get around that. But, obviously, being able to charge for events, it's relatively cheap here and then going, you know, as we scale requests-
Jamie: kind of, just scales with the revenue of the store. So, it's, kind of, just an associate cost of running the business, which is far easier then asking, "How many API calls am I going to make this month".
Jonathan: Yeah, yeah.
Jamie: Nobody really knows. We can give you some indications based on our customers, currently, do it. But, your business is very, very different from someone elses. So-
Jonathan: So, a lot more predictable.
Jamie: Yeah. I really like integrations and I want to try and create more examples around integrations. So, if you guys, do have any ideas around how we can extend Moltin, I'd love to hear how your thoughts and messages on how we can do that. I know you love playing with events and-
Jonathan: Definitely, yeah, yeah. It's awesome. Yeah, it's been great talking.
Jamie: Yeah, yeah. Small chat this week but we'll-
Jonathan: We'll be back next week.
Jamie: back next week, for sure. So, thanks very much. I'm Jamie, developer advocate, here at Moltin. You can find me on Twitter @Notrab, that's Barton backwards, easy to remember. Check me out if you have any questions. Obviously, visit the Moltin website and our forum. If you've got any questions, at all. And Jonathan, how can people can in touch with you, as well.
Jonathan: Yes, so I, also, have a backwards Twitter handle, mine is ynnoj, Jonny backwards. So, yeah-
Jonathan: Yeah, I think that's how you pronounce it.
Jamie: I say Yonnage.
Jonathan: Hit me up on Twitter. Anyway, I'm sure it'll be up on the screen somewhere. So, yeah-
Jamie: Yeah, we'll put the notes in there on the comments below-
Jamie: and maybe, I can put some things here, here. That's your name. Yeah, we'll put it somewhere.
Jamie: So, cool. Great man. Well, see you guys next time.
Jonathan: Thanks for joining. So, you're going to introduce yourself and I'll introduce myself.
Jonathan: Hi, I'm Jamie, I'm drunk. Okay-
Jonathan: I'm Jonathan-
Jamie: Try again.
Jonathan: Say I'm Jamie, title and I'll-