Tuesday, August 9, 2022
No menu items!
HomeUncategorizedTranslating auto-generated cURL to FileMaker cURL

Translating auto-generated cURL to FileMaker cURL

When you set out to integrate with an API, you will often find cURL examples in the API’s documentation, like this one from box.com.

Picture of cURL examples in the API Reference section on box.com
cURL examples from box.com

Or you use a tool like Postman, Insomnia, or Paw to test the API calls and then use the cURL syntax that these tools can automatically generate for you.

Picture of using the cURL syntax in tools such as Postman, Insomnia, or Paw
Use the cURL syntax

These cURL examples are meant to be used in command-line cURL calls (they start by invoking the curl executable as the first word in the syntax), and when you try to use the syntax as-is in FileMaker, it will fail. That is something we wrote about a few years ago.  FileMaker uses a cURL library, not the cURL command line.

Translating the provided cURL examples into the components needed to make FileMaker’s Insert From URL script step work is fairly straightforward. To make things even easier, this blog post comes with a utility file that does it for you.

In FileMaker, you need to specify the URL and the cURL options separately.  And you need to make sure that your cURL options do not contain any single quote characters (‘).  Any regular quotes need to be escaped, of course, which can be a bit of pain.

FileMaker cURL Utility

In the utility, just paste in the cURL syntax that you get from your favorite tool or from the API documentation:

Picture showing pasting the cURL syntax into the FileMaker cURL utility
Pasting the cURL syntax into the FileMaker cURL utility

Click the button, and you will get a breakdown of the elements for your Insert From URL script step:

Picture showing the breakdown of the elements from your 'Insert From URL
Breakdown of the cURL syntax elements

The tool will also separate any data that you are sending and show how you can use a variable and the odd “@$” syntax as a placeholder for the data or file that you are sending.  The example above shows a JSON body that is being sent to the API.  You would build the $payload variable ahead of time with the FileMaker JSON functions.  That way, you never have to go through the trouble of escaping any quotes in the data you are transmitting.

When you are trying to send a file, the tool will alert you to the fact that Claris has deliberately neutered – for security reasons – the cURL library so that it cannot read from a file on the hard drive.  You will need to put the file in a container field or variable first and then reference that field or variable in the cURL options syntax.

Picture of referencing the field or variable in the cURL options syntax.
Reference the field or variable in the cURL options syntax

- Advertisment -spot_img

Most Popular