We have released fmRESTor 19. Even though there were no news in FileMaker 19 Data API that would require fmRESTor to be updated, we wanted to bring a significant improvement to you anyway, so here it goes.
Creating a simple webhook
For the case you have not heard the term yet, webhook is usually defined as a “user-defined HTTP callback”. In plain English, it’s a web URL you can access and pass data to in order to perform some action in the target application. In the simplest form it’s just a link you can click and that alone performs the action.
As an example, I took the built-in FileMaker starter solution for task management, and slightly modified it to send an e-mail when I assign someone to a task.
In order to make the notification look good and be able to provide an intuitive link to click on, I used Insert from URL to send a formatted HTML e-mail as described so well by Mislav Kos in his blog article.
The idea was to let the assignee confirm the task as done simply by clicking a link. So instead of linking to the database itself, I used a link to my webhook in the e-mail.
Now whenever I assign someone to a task, that person receives a nicely formatted e-mail message with the task details, due date, and a link to click to change the task status to “Completed”.
In my video I intentionally made the webhook as simple as possible. In real life you will certainly want to add at least a little bit of security and error handling. To make it easy for you, I have prepared a better version of the webhook script for you. Feel free to download it by clicking the button below:
Full access credentials for the included Tasks database: admin / T45k4dm1N
What’s new in fmRESTor 19
As mentioned, we have just recently updated fmRESTor to version 19. The changes we made are based on feedback from users, as well as our own experience using fmRESTor in our projects. Here’s a brief list of the new improvements:
- Added “autorelogin” option to fmRESTor.php
- fmRESTor.php can store the Data API token in a file instead of PHP session
- All CURL options can be adjusted for fmRESTor.php
- fmRESTor.php methods return more information to make error handling and debugging easier
- fmRESTor.js was added to Nine Percent Milk
The last three items are probably self-explanatory for those of you who need them, but let me write more about the first two…
Session token storage
One of my favorite features of fmRESTor is that it automatically logs into the FileMaker database on the first cal, then maintains and recycles the same access token for subsequent calls, without me having to care about it at all.
The previous version of fmRESTor.php used PHP session variables for this. That works great when you access the PHP scripts from a web browser. But if you want to call it with a CURL or any other way directly from a custom app, such as when implementing a custom API and integrating two apps together, every request will start a new session, allocate resources for it, and that session will stay there until it times out.
With fmRESTor.php 19 you can now choose to store the session token in a file instead of PHP session variable. That way you can recycle the same session not only for subsequent calls from the same client, but even for connections coming from other clients, and optimize the FileMaker Server load this way.
Every FileMaker Data API session has a limited lifetime, controlled by the access token expiration. fmRESTor automatically starts a new session when the token expires. But what if the token becomes invalid sooner than that? This may happen, for instance, when you manually disconnect users from the FileMaker Server Admin console, or when you restart the FileMaker Server processes.
By default, fmRESTor simply returns the error it got from the FileMaker Data API, indicating that the access token is invalid. The new version, however, lets you also ask fmRESTor to take care of this situation automatically by trying to login again when it detects this kind of error.
What else you can use fmRESTor for
In the beginning of this article I have explained how you can use fmRESTor to easily implement webhooks. But there are other interesting integrations you can use this framework for. The possibilities are really only limited by your imagination. Let me try to inspire you with a few examples of where we have already used it:
On our Teachers Summit website we share links to apps we presented on each year’s summit. We keep the list of these apps in a FileMaker database, so that we can easily update it whenever we need to. The website uses fmRESTor to get the app names, links and icons from the database.
In the Collector itself, we use Web Viewer to manage detailed schedule, day by day, with over 4000 editable fields displayed on the screen simultaneously. With AJAX and fmRESTor the response to changing these fields is instantaneous…
For a client providing a gym management solution we created a responsive web portal, which, besides other things, shows each client’s member an instant overview of their member account balance, taking live data from the FileMaker based database.
All these examples share one thing in common. The need to display live data and/or update data on the fly, using web technology on one side, and FileMaker database on the other side. Using fmRESTor, you can have a web expert implement the web side of the solution without having to learn FileMaker, and your FileMaker developer does not have to learn anything from the web world.