BlogFileMaker

New cURL Options in FileMaker 19 – Sending an SSL Certificate Along with Your “Insert from URL” Requests

By May 28, 2020 June 1st, 2020 No Comments

The Insert from URL script step is the keystone for all API integrations; it is how you call an external API and get its response back.

At the core of this powerhouse script step, sits the cURL library with its rather arcane set of command-line switches to specify all the different options for putting the request together.

Tools like Postman and Insomnia help you construct the syntax by allowing you to build the request and then translate it into cURL.

Screenshot of Postman translation of an API request into cURL syntax

Figure 1. Postman translation of an API request into cURL syntax

But even with that translation, it remains difficult to remember what some of the options stand for and what the difference is, for instance, between -x and -X, especially if you don’t live and breathe cURL every day.

Moreover, FileMaker supports a subset of the available cURL options, so once in a while, these translation tools would use a cURL option that does not work in FileMaker or does not work in exactly the same way. For instance: FileMaker deliberately – for security reasons – disallows sending files that live on the hard disk of your computer. It only allows files that are in container fields or have been set to a variable.

And as you can see in Figure 1, tools like Postman (and many API documentation sites) use the backslash (\) character to indicate line continuation; that the syntax really is just one long line but broken up for readability. The backslash has a totally different meaning in FileMaker, however. It indicates that the next character should be escaped, taken literally. When you paste that syntax from Postman or the API documentation you have into FileMaker, then it may not work as you expect it to because of that difference in meaning.

Back when FileMaker 16 introduced the cURL options to the Insert from URL script step, we started building a library of custom functions to help us quickly pick from the supported cURL options and to keep the whole cURL options syntax readable.

Every version of FileMaker since then has added a few cURL options to the supported list. The new options in 19 are all about the ability to send an SSL certificate with your request. The full list of all supported options is in the online help. (Although at the time this blog was written, the online help was not yet updated with the changes for 19).

cURL Options Library

Get the Library File

Our library has also been updated with the new cURL options. If you have never worked with the library, here’s a quick overview of how it works.

Copy over the custom functions into your solution. Yes, there are many, but they are named in such a way that they will not get in your way.

When you construct an Insert from URL call to an API, you may want to set a variable ahead of time with the cURL options that you need. This gives you a chance to inspect them when you are debugging. The extra line of code has no effect on FileMaker’s execution speed.

A simple example below; we are using the free “postb.in” service to test out a few mock API calls.

The URL to create a ‘bin’ is on line 28 and the cURL options are set on line 31. The call to the API is executed by the Insert from URL on line 32.

Screenshot showing using the free "postb.in" service

Figure 2. Using the free “postb.in” service to test out mock API calls

Line 31 is where we use our custom functions. As you can see, we can simply string together all the options we need without worrying about single or double quotes or any other string formatting issues.

And because these are functions, they are available in FileMaker’s type-ahead auto-complete: if you type in different parts of the name, you can quickly see and select the option you are after.

Screenshot showing type-ahead auto complete

Figure 3. Type-ahead auto complete

That significantly cuts down on any typos in the cURL syntax and takes the guesswork out of remembering which options are supported in FileMaker.

Similarly, the library contains custom functions to replace hard-to-remember general options such as the various RFC numbers for the Base64 Encoding function:

Screenshot of RFC number for Base64 Encoding function

Figure 4. RFC numbers for the Base64 Encoding function

You will find custom functions that represent text encoding options, JSON data types, and encryption algorithms.

Specifically for FileMaker 19, creating an API call that requires you to send an SSL certificate along with the private key and the key passphrase is as simple as this, after having set variables $key and $cert with the content of the container field where you store the SSL certificate and the key files.

Screenshot showing certificate type

Figure 5. Certificate type

Which FileMaker will then translate into the proper cURL syntax for us:

Screeenshot showing translation into the proper cURL syntax

Figure 6. Translated into the proper cURL syntax

We hope this library can make your development work easier; feel free to reach out to us with questions and ideas.

Wim Decorte

Wim Decorte

Wim is a Senior Technical Solution Architect at Soliant. He is a FileMaker 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 and 18 Certified FileMaker Developer and the author of numerous Tech Briefs and articles on FileMaker Server. Wim is one of the very few multiple FileMaker Excellence Award winners and was most recently awarded the FileMaker Community Leader of the Year award at the 2015 FileMaker Developer Conference. He is also a frequent speaker at the FileMaker Developer Conference and at FileMaker Developer groups throughout the world. In addition to being a renowned expert on FileMaker Server, Wim also specializes in integrating FileMaker with other applications and systems. His pet project is the open source fmDotNet connector class that he created.

Leave a Reply

Need to adjust your business processes quickly? We're helping clients use technology to keep their teams productive and running smoothly in these times of uncertainty. Our team can guide yours if you need help in these areas.

Talk to a Consultant