If you are FileMaker developer, but new to the notion of web APIs and web development in general, then you might take on a kind of deer-in-the-headlights look when confronted with FileMaker Server 16’s new Data API, aka “REST API”. Fear Not! It really is simpler and more straightforward than you might expect. I like to take the attitude that no skill is difficult, only unfamiliar. With study and repetitive exposure and practice, any skill can be mastered.
First, get familiar with REST
Let’s start by getting familiar with REST! First off, I’d like to limit the scope of this post to understanding FileMaker’s implementation of REST, not REST in general. If you need to start from the beginning, I would suggest this tutorial. Frankly, I just chose this from a Google search for “REST API Tutorials”. I would suggest you do the same and review a variety of materials until you get it.
Ok, thanks for coming back. Now that you understand the basics, let’s dig into the particulars of FileMaker’s implementation of a REST API. It is not always readily apparent how to structure the syntax for successful API calls. After quite a bit of fiddling and trial-and-erroring, I believe I have figured most of it out. So you get to benefit from my suffering. Lucky you!
What does the FileMaker Data API do?
The Data API provides all of the basic CRUD operations (Create, Read, Update, Delete) against your hosted FileMaker data. Note the emphasis on hosted as this is a feature of FileMaker Server and its ability to respond to REST requests for your hosted FileMaker solutions and return a data response in JSON format. This will not work on an un-hosted FileMaker solution.
FileMaker Pro 16 ships with additional cURL options in the Insert from URL script step. This upgrade brings the FileMaker client up-to-date with an ability to interact with REST APIs without the use of a plugin. This is important, because in the sample file available below, we are leveraging the new cURL options to allow a FileMaker solution to talk to its own hosted Data API, giving it the power to interrogate and alter its own data through the API. The sample file is a great way to learn how to work with both the cURL options and the Data API.
Getting Started
So let’s get started. First, download and host the sample file on FileMaker 16 Server. Note that to make the Data API available for a hosted solution, you need to enable such in the privilege sets that require Data API access. In the sample file, I created an account and assigned it to the Data Entry Only privilege and activated the Access via FileMaker Data API extended privilege for Data Entry Only. Note that in production, you should create a custom privilege for Data API access and limit the privileges so that the Data API user account only has access to the solution resources dictated by your requirements.
The REST Layout
Nearly all of the REST calls you will make to a FileMaker solution require that you pass in the name of a specific layout. Placing fields and related data portals on this layout will define the data that you can interact with for all of the CRUD operations. In the sample file, this layout is called rest_layout. Those of you familiar with using the PHP API for FileMaker will understand this concept, as the PHP API also requires a defined layout that provides the data access functionality to the API.
The Sample File
From here on out, I suggest you host the sample file on FileMaker Server 16 and dig in the demos provided there. Make sure you use FileMaker Pro 16 (or 16 Advanced) to access the file. The sample file walks thorough most of the functionality provided by the Data API and clearly illustrates the cURL syntax required to execute Data API calls using the Insert From URL script step.
The sample file (check out the scripts!), plus the documentation for the Data API (provided in the sample file) and cURL options will help you develop an understanding of this new feature of FileMaker Server. Note that the sample file is a learning resource, not an example of robust production-ready code. In the first tab of the sample file you will need to enter server and account information. This is required for the demo to work.
Good luck and please do reach out if you have questions or comments!
darren_b(at)beezwax.net
Perfect
Thanks’
Can’t tell you how much time and frustration your article and demo saved me.
My test server is using the default SSL certificate, I suspect that is the reason I’m getting an 802 error. When testing with Postman I had to shut off SSL certificate verification. Any thoughts?
Thank you for reaching out with your question. I have seen 802 errors when the file is not set to “Access via FileMaker Data API”
I believe the Default SSL Cert could cause it as well, as you may have found. Do you have access to a server with a signed certificate? That may be the best way to test your assumption.
Again, thank you for your question and I am glad the file was helpful to you.
Thank you for this enormously helpful file. It works great if the target is another file on the server, but I’m getting an error on login when I target the file itself.
{“errorMessage”:”Unable to open file”,”errorCode”:”802″}
Write privs are granted at the OS level, and I’ve otherwise left the settings alone. Mac client/server. Any suggestions?
Thanks for writing. This may be because you need to check the Access via FileMaker Data API extended privilege in the target file. See the screen shot. Also is the file hosted on FileMaker 16 server? Are you accessing it with FileMaker 16 client?
I am a bit confused by your question though. You say that it works great if the target is another file, but you get an error when you target the file itself. I am not sure what you mean by this. Send me an email to darren_b(at)beezwax.net as I would like to diagnose this error.