Translating Auto-generated cURL to FileMaker cURL

Update: August 21, 2023

The download for the cURL parser file below is a new version that adds support for the unique URL syntax for SharePoint APIs.

Update: March 27, 2023

The download for the cURL parser file below is a new version that contains bug fixes.

Update: January 30, 2023

The download for the cURL parser file below is a new version that contains bug fixes.

Update: January 12, 2023

The download for the cURL parser file below is a new version that contains bug fixes.

Update: November 15, 2022

The download for the cURL parser file below is a new version that contains bug fixes.

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:

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

Moving Forward with FileMaker cURL

If you have any questions about how to translate your auto-generated cURL or would like help further customizing your FileMaker application, our team of consultants may be able to help. Contact us today.

21 thoughts on “Translating Auto-generated cURL to FileMaker cURL”

  1. Very useful concept and file, will be useful in the community for those without the experience to do this task by hand…
    A great idea, well executed

  2. David Wikström

    This is a very handy little utility – I just tested it with SendGrid, and it worked nicely to get started a little bit quicker.

    There is a minor issue in the Substitute on line 37 of the script “parse” – you are removing all spaces from the payload, which is not correct, as it e.g. – in this case – also removes all spaces from the e-mail Subject and Content.

      1. Hi – just come across this file and it works really well apart from the issue raised by David re line 57 (I am using version 3 so the line number is different but the problem is the same). I have tried to sort it out by removing a variety of numbers of spaces and it works but is not flexible enough to cope with anything that does not have those set number of spaces:
        Substitute ( $payload ; [ “‘{” ; “{” ] ; [ “}'” ; “}” ] ; [ “: ” ; “:” ] ; [ Char ( 9 ) ; “” ] ; [ ” ” ; “” ] ; [ ” ” ; “” ] )
        I feel sure there’s a better way – any ideas?
        Thanks again
        John

        1. Hi John,
          Can you email me an example of what you are trying to parse? I can then see about coming up with something generic.

          Best regards,
          Wim

  3. Your explanation and your utility have been very helpful.
    In your example, although I understand that $payload refers to the JSON object in the box printed below the boldfaced word $payload, I do not understand the references or meanings of either
    1. option -D, following the variable $payload
    2. the variable $header

    If you could explain the meaning of both, I would be greatly appreciative.

    1. The -D $header entry is there for FileMaker to dump the response headers into. Those response headers are crucial in your script to determine if the API call was successful or not. Here’s an example of a set of response headers:

      HTTP/1.1 200 OK
      Server: nginx/1.14.0 (Ubuntu)
      Date: Mon, 14 Nov 2022 08:03:02 GMT
      Content-Type: application/json; charset=utf-8
      Content-Length: 505
      Connection: keep-alive

      You’ll almost always want to know what the http response code was (200 in this case).
      The syntax is a bit odd because we’re not giving the cURL command what is currently in $header. In fact $header doesn’t exist at this point but the cURL command will set that variable with whatever response headers were returned.

  4. Wim, I greatly appreciate your great explanations on constructing curl syntax using a data variable, and your explanations on the matter in which the header variable, created during the FMP’s insert from cURL process, is deletable. Thank you so much for your great help.

    1. Thanks, John!
      Turns out that example you were working on had non-space whitespace between the parts of the cURL string, v3 of the demo file takes care of that.

  5. Hi, please could you advise how I would build the $payload variable ahead of time with the FileMaker JSON functions? Would I use JSONGetElement? I get errors stating that the table cannot be found. I use the data produced by the Curl tool on this page. TIA 🙂

  6. Thank you Wim. This utility file helps me a lot to configure my first API request with Filemaker. I spent hours without success when I discover your magical file.

  7. When I use the utility it provides some output but the file appears to freeze / crash so I have to crash out of FM. Am I doing something wrong?

    1. It shouldn’t crash so I would suggest downloading a fresh copy and trying with that. Perhaps something got damaged in the download.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top