In this activity we’re going to work in FileMaker to replicate the queries made in the previous exercise with Postman. This provides an opportunity to interact with the FileMaker Data API in a programming environment I hope you’re familiar with. It may also provide an opportunity to learn about interacting with external APIs in FileMaker if that’s not something you’ve done a lot of.
In this activity
- In the session resources folder locate and open the file
- Replicate each of the requests in the Postman collection
- If you get (really) stuck take a peak in the ‘Help me out’ script folder (not all the answers but lots of tips and tricks and scripts which will work 🙂
- Build from there to write a script which will upload newly created records in the contact table to your remote file.
The key FileMaker requirement is the
Insert from URL script step. Under the hood this is using a library called cURL, so we’ll often need to pass in cURL options to achieve the desired results.
The cURL website lists all of the options available in cURL, though please be aware that not all of them are supported in FileMaker (see this help document for those which are) and there are some specific FileMaker nuances you need to be aware of with regards to binary data.
Base64Encode ( $$username & ":" & $$password )
// for debugging ONLY set error reporting on
"--show-error " &
"--dump-header $$Headers " &
// explicity say we are performing a post
"-X POST " &
// set the textual data
"--data-ascii @$data " &
// set the Contet type header to JSON
"--header Content-Type:application/json " &
// add in the authorization token
"--header \"Authorization: Basic " & GetValue($credentials ; 1) & "\""
The slightly odd setting in the authorization header where we’re getting the first value of the
$credentials variable as if it were a list comes about because the FileMaker
Base64Encode function tends to leave a carriage return after the encoded string.
If you find you’re running into issues then refer back to what Postman was doing and look to replicate the same thing in terms of structuring and setting data.
And if you get really stuck – take a sneaky peak in the script folder ‘Help Me Out’ where you’ll find working examples of most of the scripts that you need.