FileMaker tips, techniques, and news.

By Mason Stenquist  Posted on  May 9th, 2017  in  FileMaker, Web

FileMaker Data API

FileMaker has added a new and exciting way to access all your FileMaker data with an easy-to-use data format that is the industry standard REST API. By going with a standardized format developers are able to integrate any platform they choose with FileMaker solutions on FileMaker Server. One of the biggest benefits from this are that front end developers are able to integrate popular Javascript Frameworks, such as Google's Angular Framework or FaceBook's React library, with FileMaker Server.

Enabling the REST API

The first thing you need to do is to enable the API in FileMaker 16 Server's admin console. You will also need to enable the new fmrest extended privilege set in the security settings in your FileMaker file. All the same rules that apply to XML and the PHP API apply here: all calls must specify a layout, and only the fields and portals available on the layout will be available to the REST API.

FileMaker Rest API FileMaker 16 Admin Console

FileMaker Rest API Security Options

Authentication

Authenticating with a FileMaker database through the REST API can be done in 2 different ways: using the standard username and password credentials you normally access the file with or using OAuth. For simplicity's sake, we'll be focusing on authenticating just using our standard FileMaker username and password. To do so you will need to send a POST request with the following settings and parameters.

Request Format:  POST ipaddress/fmi/rest/api/auth/:solution
Request Example: POST https://localhost/fmi/rest/api/auth/FM_QUICKSTART_v3
Headers: Content-Type: application/json
Body: {"user":"admin","password":"admin","layout":"Contact"}
Response:
{
  "errorCode": "0"
  "layout": "Contact",
  "token": "e86d7d4f4fa602ccb5a6b498a6634576b2da1b3efc67a7d907"
}

Once we have the token, we can use that to authenticate the rest of our API calls until it expires.

Viewing Data

To access the actual data from our FileMaker file, we'll make use of the "Get Records" and "Get Record" API methods. To get a list of records from FileMaker you need at a minimum to specify the file you want to access, the layout, and the token generated in the previous step. There are also a number of more advanced parameters you can include to adjust the range, offset, sort, and even what portals to include in the results.

Request Format:  GET ipaddress/fmi/rest/api/record/:solution/:layout
Request Example: GET https://localhost/fmi/rest/api/find/FM_QUICKSTART_v3/ContactWeb
Headers: FM-Data-token: e86d7d4f4fa602ccb5a6b498a6634576b2da1b3efc67a7d907
Response:
{
  "errorCode": "0",
  "result": "OK",
  "data": [
    {
      "fieldData": {
        "firstName": "Clark",
        "lastName": "Kent",
        "company": "DC",
        "isActive": "1",
        "picture": "https://localhost/Streaming_SSL/MainDB/0958204726F9842D89B1CD71DE2FB7CC.bmp?SessionKey=0958204726F9842D89B1CD71DE2FB7CC&RCType=EmbeddedRCFileProcessor"
      },
      "portalData": {
        "PORTAL:Address1": [],
        "PORTAL:Quotes": [],
        "NotesPortal": []
      },
      "recordId": "40",
      "modId": "9"
    },
    {
      "fieldData": {
        "firstName": "Peter",
        "lastName": "Parker",
        "company": "Marvel",
        "isActive": "1",
        "picture": "https://localhost/Streaming_SSL/MainDB/CDD151DF736F445D002D95A0FAE4F160.bmp?SessionKey=CDD151DF736F445D002D95A0FAE4F160&RCType=EmbeddedRCFileProcessor"
      },
      "portalData": {
        "PORTAL:Address1": [],
        "PORTAL:Quotes": [],
        "NotesPortal": []
      },
      "recordId": "44",
      "modId": "5"
    }
  ]
}

And if you only wanted one record you'd include the recordId like so.

GET ipaddress/fmi/rest/api/record/:solution/:layout/:recordId

Creating and Editing Records

Creating and editing records via the REST API are very similar, the only differences being the method, POST vs PUT and including a recordId when editing. Below is a sample for how you would create a new record.

Request Format:  POST ipaddress/fmi/rest/api/record/:solution/:layout
Request Example:  POST https://localhost/fmi/rest/api/record/FM_QUICKSTART_v3/ContactWeb
Headers: FM-Data-token: e86d7d4f4fa602ccb5a6b498a6634576b2da1b3efc67a7d907
Headers: Content-Type: application/json
Body: 
{
"data": {
    "firstName": "Joe",
    "lastName" : "Bob",
    "isActive" : "1",
    "company" : "New Company" 
     }
 }
Response:
{
  "errorCode": "0",
  "result": "OK",
  "recordId": "74"
}

And if you then wanted to update that record you would do the following.

Request Format:  PUT ipaddress/fmi/rest/api/record/:solution/:layout/:id    
Request Example: PUT https://localhost/fmi/rest/api/find/FM_QUICKSTART_v3/ContactWeb/74
Headers: FM-Data-token: e86d7d4f4fa602ccb5a6b498a6634576b2da1b3efc67a7d907
Headers: Content-Type: application/json
Body: 
{
"data": {
    "firstName": "Joey",
    "lastName" : "Bob",
    "isActive" : "0",
    "company" : "Other Company"
     }
 }
Response:
{
  "errorCode": "0",
  "result": "OK"
}

Deleting Records

The last API call I want to go over is how to delete a record. Deleting a record is very similar to viewing a single record, the only difference is the HTTP method you would use is the delete method. Here is an example of how to delete a record.

Request Format:  DELETE ipaddress/fmi/rest/api/record/:solution/:layout/:id     
Request Example:  DELETE ipaddress/fmi/rest/api/record/FM_QUICKSTART_v3/ContactWeb/34
Headers: FM-Data-token: e86d7d4f4fa602ccb5a6b498a6634576b2da1b3efc67a7d907
Response:
{
  "errorCode": "0",
  "result": "OK"
}

Notes

Currently, there is no way to run a FileMaker script or get the contents of a value list like you can do using the XML or PHP API's. One thing that the new REST API does much better than previous CWP options is how it handles container fields, basically, it just works. There is no complicated container-bridge file to determine the mime type or anything like that, just a simple URL where you can view or download the item in the container.

Another thing you might run into while working with the API is that it does not return the number of records found when doing a find or accessing all records for a layout. This doesn't sound like a big deal, but without knowing the total number of records found you can't paginate your results reliably. Luckily there is a workaround for this. You'll need to create a new unstored calculation that calculates as "get( foundCount)" and put it on the layout you are using for your web call. The correct found count will be returned for every record, even if you are only pulling the first few records.

Conclusion

There's a lot to like with the new FileMaker REST API and we're excited to start using it in our web development. REST allows other technologies to integrate with your FileMaker solution that aren't well suited to the XML or PHP APIs. REST APIs are quickly becoming the number one way to interact with outside programs and services; you can view our article specifically about REST APIs for more info on what a REST API is.

Did you know we are an authorized reseller for FileMaker Licensing?
Contact us to discuss upgrading your FileMaker software.

Mason Stenquist thumbnail
Mason Stenquist

Mason is an experienced and Certified FileMaker developer motivated by creating innovative solutions for his clients. His interest and talent in the realm of art combine to form the foundation for his exceptional design skills, which helped him win the FileMaker Developer Cup at DevCon.

FileMaker 18 Certified Developer
FileMaker 17 Certified Developer
FileMaker 16 Certified Developer
FileMaker 15 Certified Developer
FileMaker 14 Certified Developer
FileMaker 13 Certified Developer
FileMaker 12 Certified Developer
FileMaker 11 Certified Developer
"We were actually able to add more features than we thought would be possible within our budget. We always experienced a ‘can do’ attitude and DB Services was incredibly patient and easy to work with."
Courtney Hartman
Art Director
"The new FileMaker custom website interface is very user-friendly and easy to follow for our clients. In addition, it is much faster than the old Instant Web Publishing (IWP) interface. Thank you and all the others who have helped us out at DB Services. I am very grateful for the excellent service you provide us. Its nice to know we can call you for help if we have an issue."
Wayne Capek
President
"We needed a solution that would simplify the administration of our responsibilities under our contract with the State of Indiana. We have seen a dramatic increase across the state in the number of potential foster and adoptive parents that have begun the preparation and training process. This increase has resulted in a significant opportunity for children available for adoption. That’s a big win for everyone! And it’s all because we can refer potential parents to the proper state contacts efficiently and quickly."
Chris Morrison
Executive Director
"Thank you for all of your expertise and valuable help. I am so grateful to have found DB Services."
Linda Findlay
Owner
"Thank you for our new database system. We transitioned from a carbon copy paper based system to a digital database. The software has saved us time and money. We used to archive all our jobs in cabinets, now we can look up a job in seconds from anywhere. The software allows us to easily email estimates to our customers in pdf format. In a year there was a return on investment just from eliminating the purchasing of our carbon forms."
Todd Cartmel
Owner
"The new system allows us to create and track jobs for customers along with inventory, something we had been doing with separate word and spreadsheet files. Because it’s now so intuitive, new staff members are able to begin using the database immediately without our usual training session and ‘cheat sheets’ for getting around within the file."
Tom Andrews
President