Arrived in Texas

Yesterday I arrived here in San Antonio in the JW Mariott Hill Country Hotel for the FileMaker Developer Conference.

I already found my way through this huge resort and found the registration desk.
So if you are here nearby, we can of course meet for diner or a coffee and chat about FileMaker, Xojo or Plugins.

Translate PHP script with CURL to FileMaker Script

Today we want to show you how to translate a PHP script with CURL commands step by step to a FileMaker script. Here is a PHP script:

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($params))
);
$result = curl_exec($ch);
curl_close($ch);

So lets go through the script line by line. First line is "$ch = curl_init();" which simply creates a new curl session in PHP. The result is the handle which is stored in $ch variable. This handle value (a number) is than used to to reference the CURL session later in the script. In FileMaker, the call to the MBS plugin is MBS("CURL.New"). This function starts a new session and we store it in a variable, exactly as in PHP.

Next calls set a couple of options. First for SSL, you should use a certificate to have the plugin verify the identity of the server. But in this example we simply disable verification. So we use the calls MBS("CURL.SetOptionSSLVerifyPeer"; $curl; 0) and MBS("CURL.SetOptionSSLVerifyHost"; $curl; 0). The option CURLOPT_RETURNTRANSFER in PHP is not needed by the plugin. The plugin automatically collects the data downloaded and your script can query the result later.

Next option sets the URL to use. This can be an URL for one of the supported protocols including FTP(S), HTTP(S) or SFTP. In the script we use MBS("CURL.SetOptionURL"; $curl; $URL) to pass the URL as text to the plugin. Than we can set other options like a 30 seconds timeout using MBS("CURL.SetOptionTimeout"; $curl; 30).

As this example transfer is a HTTP Post operation for sending form data, we have to turn on the post option. All the web services like SOAP normally use POST queries which use the request xml as the form data. So with the call MBS("CURL.SetOptionPost"; $curl; 1) we enable post operation. With the custom request option you can of course explicit also set POST, but here it is optional: MBS("CURL.SetOptionCustomRequest"; $curl; "POST"). Often we custom requests like DELETE with a REST API.

For the actual content of the transfer we have a couple of functions to set input data. So for the CURLOPT_POSTFIELDS we can use the plugin function MBS("CURL.SetOptionPostFields"; $curl; $params) with the right text in the variable. The plugin will copy the data for the transfer and also set internally the size for the transfer. So when setting the http headers (CURLOPT_POSTFIELDS), we don't need to include the Content-Length line with MBS Plugin. For the http headers we need to pass the content type to the plugin to inform our web server that we pass data as JSON here: MBS("CURL.SetOptionHTTPHeader"; $curl; "Content-Type: application/json").

To run the transfer, the PHP script calls curl_exec function. In the plugin we call MBS("CURL.Perform"; $curl) and get back an error code. This error code is zero on success. For a list of error codes, please check the plugin documentation. The PHP function returns the result directly. But with our plugin, we have the function CURL.GetResultAsText. Depending of the transfer, the result could be text, an image or some other data. To show text in a field in FileMaker, we also need to make sure the line endings match. FileMaker always uses Mac line endings, so we use the String.ReplaceNewline function. So we get the result with the calculation MBS("String.ReplaceNewline"; MBS("CURL.GetResultAsText"; $curl);1).

To know what reason a failure has, you can get debug messages. So before the perform call, we enable verbose debug messages with a call to MBS("CURL.SetOptionVerbose"; $curl; 1). To actually get the text for showing in a field, we query the messages as text with this call: MBS("String.ReplaceNewline"; MBS("CURL.GetDebugAsText"; $curl);1).

Finally we do some cleanup. In PHP the curl_close call and in FileMaker the MBS("CURL.Cleanup"; $curl) call. As you see the function calls are quite similar and you can easily translate PHP scripts using CURL for use in FileMaker.

The final script looks like this:

Set Variable [$curl; Value: MBS("CURL.New")]
Set Variable [$result; Value: MBS("CURL.SetOptionURL"; $curl; $URL)]
Set Variable [$result; Value: MBS("CURL.SetOptionSSLVerifyPeer"; $curl; 0)]
Set Variable [$result; Value: MBS("CURL.SetOptionSSLVerifyHost"; $curl; 0)]
Set Variable [$result; Value: MBS("CURL.SetOptionVerbose"; $curl; 1)]
Set Variable [$result; Value: MBS("CURL.SetOptionTimeout"; $curl; 30)]
Set Variable [$result; Value: MBS("CURL.SetOptionPost"; $curl; 1)]
Set Variable [$result; Value: MBS("CURL.SetOptionPostFields"; $curl; $params)]
Set Variable [$result; Value: MBS("CURL.SetOptionHTTPHeader"; $curl; "Content-Type: application/json")]
Set Field [Webservice::Error; MBS("CURL.Perform"; $curl)]
Set Field [Webservice::Input; $input]
Set Field [Webservice::Result; MBS("String.ReplaceNewline"; MBS("CURL.GetResultAsText"; $curl);1)]
Set Field [Webservice::DebugMessages; MBS("String.ReplaceNewline"; MBS("CURL.GetDebugAsText"; $curl);1)]
Set Variable [$result; Value: MBS("CURL.Cleanup"; $curl)]

MBS Filemaker Plugin, version 4.3pr3

New in this prerelease of the 4.3 plugins:
  • Added QLPreviewPanel functions.
  • Added String.EncodeEmailSubject function.
  • Updated FileDialog.SelectFolderDialog to use newer API to get nicer dialog.
  • Added support for Windows for ListDialog functions.
  • Added String.DecodeFromXML and String.EncodeToXML.
  • Updated LibXL to version 3.6.0.
Download at monkeybreadsoftware.de/filemaker/files/Prerelease/ or ask for being added to the dropbox shared folder.

FileMaker Developer Conference 2014


Over 70 sessions at the biggest FileMaker event of the year!

Still time to register for the FileMaker Developer Conference!
There is still time to register for the FileMaker Developer Conference with over 70 sessions to choose from at the biggest FileMaker event of the year. Come to DevCon 2014 and discover how the FileMaker Platform can help you run your business without boundaries. Join over 1,200 developers in San Antonio, Texas from July 28-31, 2014 and take the first steps to achieving your business goals.

Take a look at this year's DevCon Exhibitors. The FileMaker community is rich with smart, creative developers that are creating add-ons, plug-ins, and ready-made solutions to use with the FileMaker Platform. They also offer services that will make using FileMaker even more delightful and customized to your needs. If you’re looking to solve a business problem, come to DevCon and see how others can help make your job easier.

Other FileMaker conferences:

MBS Filemaker Plugin, version 4.3pr2

New in this prerelease of the 4.3 plugins:
  • The functions Time.UnixTimeStamp, ZipFile.CreateFile and SQL.SetParamAsDateTime now report an error if the timestamp parameter is not a time, date or timestamp value. So please don't simply pass text there.
  • Added NetworkInterfaces functions.
  • Fixed a problem with reading file data from container.
  • The plugin can now read compressed container data.
  • Added DialogModifications functions.
  • Added Barcode.WriteFile function.
  • Added functions to query special folders.
  • Updated to OpenSSL 1.0.1h.
  • Added DragDrop.CreateWithControl parameters to define an offset relative to container.
  • WebViewer field setter/getter functions can now find field by name if form name is empty and find fields in all forms.
  • Changed CGImageSource.ImageAtIndex and CGImageSource.ThumbnailAtIndex to convert image to RGB color space if necessary.
  • For DynaPDF PDF import we now automatically enable duplicate check and normalize by default.
Download at monkeybreadsoftware.de/filemaker/files/Prerelease/ or ask for being added to the dropbox shared folder.

FileMaker Stammtisch Hamburg 3rd July

Less than 24 hours until the FileMaker users meeting in Hamburg.
You can come and learn about our latest MBS FileMaker plugin.
Meeting is in Block House Wandsbek in Hamburg at 7pm.

see filemaker-magazin.de/service/filemaker-stammtische/hamburg

MBS Filemaker Plugin, version 4.3pr1

New in this prerelease of the 4.3 plugins:
  • Added Container.ExtractStream and Container.RenameStream.
  • Added IsClient, IsRuntime and IsServer functions.
  • Added ZipFile.CRCFile function.
  • Added Socket.LastError function.
  • Updated DynaPDF to version 3.0.33.96.
  • Added DragDrop.GetTypes function.
  • Changed DragDrop.CreateWithSize to be relative to content frame.
  • Changed GMImage.Annotate to accept gravity parameter also as text and not just as number.
  • Weak linked all libraries. This way even on older Mac OS X versions the plugin should load again. But if functions like GraphicsMagick use a function which does not exist on Mac OS X 10.4 or 10.5, it may crash.
  • Added SQL.GetFieldAsPDF and SQL.GetParamAsPDF.
  • Added Files.SetPosixPermissions and Files.GetPosixPermissions.
  • Added function to control size of list dialog.
  • Fixed an issue where ListDialog being closed left FileMaker window disabled.
Download at monkeybreadsoftware.de/filemaker/files/Prerelease/ or ask for being added to the dropbox shared folder.

Archives

May 2026
Apr 2026
Mar 2026
Feb 2026
Jan 2026
Dec 2025
Nov 2025
Oct 2025
Sep 2025
Aug 2025
Jul 2025
Jun 2025
May 2025
Apr 2025
Mar 2025
Feb 2025
Jan 2025
Dec 2024
Nov 2024
Oct 2024
Sep 2024
Aug 2024
Jul 2024
Jun 2024
May 2024
Apr 2024
Mar 2024
Feb 2024
Jan 2024
Dec 2023
Nov 2023
Oct 2023
Sep 2023
Aug 2023
Jul 2023
Jun 2023
May 2023
Apr 2023
Mar 2023
Feb 2023
Jan 2023
Dec 2022
Nov 2022
Oct 2022
Sep 2022
Aug 2022
Jul 2022
Jun 2022
May 2022
Apr 2022
Mar 2022
Feb 2022
Jan 2022
Dec 2021
Nov 2021
Oct 2021
Sep 2021
Aug 2021
Jul 2021
Jun 2021
May 2021
Apr 2021
Mar 2021
Feb 2021
Jan 2021
Dec 2020
Nov 2020
Oct 2020
Sep 2020
Aug 2020
Jul 2020
Jun 2020
May 2020
Apr 2020
Mar 2020
Feb 2020
Jan 2020
Dec 2019
Nov 2019
Oct 2019
Sep 2019
Aug 2019
Jul 2019
Jun 2019
May 2019
Apr 2019
Mar 2019
Feb 2019
Jan 2019
Dec 2018
Nov 2018
Oct 2018
Sep 2018
Aug 2018
Jul 2018
Jun 2018
May 2018
Apr 2018
Mar 2018
Feb 2018
Jan 2018
Dec 2017
Nov 2017
Oct 2017
Sep 2017
Aug 2017
Jul 2017
Jun 2017
May 2017
Apr 2017
Mar 2017
Feb 2017
Jan 2017
Dec 2016
Nov 2016
Oct 2016
Sep 2016
Aug 2016
Jul 2016
Jun 2016
May 2016
Apr 2016
Mar 2016
Feb 2016
Jan 2016
Dec 2015
Nov 2015
Oct 2015
Sep 2015
Aug 2015
Jul 2015
Jun 2015
May 2015
Apr 2015
Mar 2015
Feb 2015
Jan 2015
Dec 2014
Nov 2014
Oct 2014
Sep 2014
Aug 2014
Jul 2014
Jun 2014
May 2014
Apr 2014
Mar 2014
Feb 2014
Jan 2014
Dec 2013
Nov 2013
Oct 2013
Sep 2013
Aug 2013
Jul 2013
Jun 2013
May 2013
Apr 2013
Mar 2013
Feb 2013
Jan 2013
Dec 2012
Nov 2012
Oct 2012
Sep 2012
Aug 2012
Jul 2012
Jun 2012
May 2012
Apr 2012
Mar 2012
Feb 2012
Jan 2012
Dec 2011
Nov 2011
Oct 2011
Sep 2011
Aug 2011
Jul 2011
Jun 2011
May 2011
Apr 2011
Mar 2011
Feb 2011
Jan 2011
Mar 2010
Dec 2009
Nov 2009