Insert From URL cURL Options
Do you need to work with online APIs and find yourself wishing there was an easy way to accomplish it? Well, there actually is. In fact, in much of technology, there's something or someone somewhere which has likely already solved the problem.
In the case of using REST (Representational state transfer) to interact with service APIs within FileMaker, it's nice to have a single tool which will handle most of the heavy work for you. When native JSON was added to FileMaker, the last piece to the puzzle was a more expanded method of interacting with the network. The cURL library was already being used by FileMaker and it was simply a matter of "opening things up" so developers could use the full suite of the cURL library.
By adding the cURL options calculation to the Insert From URL script step the world of the web opened up for our humble FileMaker Pro.
This video provides a comprehensive understanding of how curl is integrated into FileMaker and how you can use a freely provided script to manage all your REST based interactions. Knowing about HTTP status codes and request/response headers is what you'll find covered in this video and the associated file.
Comments
Content Length Error
Hi Matt, I wonder if you could help me out as I'm getting stuck trying to implement this. I'm calling a Web App (built in Google Apps Script) from Filemaker and Posting some simple JSON data. The Web App then has access to our company's entire Google Workspace account so it can go off and do all sorts of things like create forms and send back their URLs etc.
The google server is receiving the request. It runs the doPost function and I can parse out the JSON from the event parameter. I'm trying to send back JSON to Filemaker but I'm getting stuck as I'm getting a response from Google about content-length. Without going into lots of detail the $protocolResponse is being set as "HTTP/1.0 411 Length Required". The $responseBody serves up a small HTML page basically saying the same with the added detail of "POST requests require a Content-length header".
I have tried using the ignore-content-length option that you are supporting so my cURL headers are structured like this for the query...
--request POST --header "accept: application/json" --header "content-type: application/json" --data @$~curlData --ignore-content-length ""
--location "" --dump-header $responseHeaders
...but it's still not happy. Is there a way I can calculate the content-length and add it to my headers or am I trying to solve the wrong problem and actually I'm missing something obvious? Sorry for the very specific technical question but I've gone through it so many times I'm not sure where to go next.
Any help would be much appreciated.
Many thanks,
Craig
SOLVED - Method not needed
Hi Matt,
It's taken some hours and I've been distracted by others having similar errors but it not being the same issue. However when I stripped everything back to some simple requests I found that for the Google servers to be happy with a POST request from Filemaker I needed to actually remove the --method (or -X) cURL option and simply include data with the request.
I guess Filemaker knows to send it as a POST if it has data, as if it has no data it sends a GET request. As soon as I explicitly set the method in the cURL options, GET works but POST throws the 411 error saying it needs content-length.
I have no idea why it works but it works, so a quick edit of the curlOpts() custom function to not include a method if one isn't passed in, and we're good to go.
Thanks again for your work in putting all the code together to make it easy to set these options. I'd never be able to get to this place on my own!
Best wishes,
Craig
RE: SOLVED - Method not needed
Craig, thanks for posting the solution! I was getting the same error when sending a POST to an Apps Script web app.
I went down the same road as you, trying to calculate the content length but had no luck either. Googled the error and found your post- and I'm back in business. Thanks for the tip!
Way over my head, not at all useful
Discussing a behemoth script with not a single example of insert from URL, is not at all useful. I spent and hour expecting to learn a single thing about curl in the "insert from url" filemaker command and nothing. I learned nothing about how FileMaker uses insert from URL, how to configure curl, how to get error codes from the responses, how to configure headers. The list goes on and on. This video is not for beginners, but for super advanced users that probably know this info already, but maybe want to use a master script ?? Don't know, didn't understand it. Very disappointed.