RESTfm + FileMaker (Part 2 of 2)

OK, it’s been nearly a month since my last post – crap, sorry, I did say next week…

Quick recap, this is how to use a standalone FileMaker Go / iOS SDK app to sync to a FileMaker Server hosted file.

If you want to do a web page or stand alone iOS app with RESTfm, then send your web / iOS developer to Nick @ Goya’s RESTfm manaul.

Right, got that sorted, if you’re still reading, great – it probably applies to you.

 

Sifting through JSON data

OK, this is most likely the trickiest bit, I know of a few JSON data deciphers out there however I really wanted this app to be very light and not run with a plugin, as you can’t on FileMaker Go / iOS SDK. There is a custom function that I use (and I use this one a lot) called NthItem from Brian Dunnings website, kudos to the developer Drew Boone for this, it’s a cracker. I use it as a delimiter.

Here I standardise some of the data by substituting some of the delimiters put out by RESTfm so I can easily read the data with my eye.

Substitute

(

field_name ;

[ “[{” ; “¶[{” ] ;

[ “}]” ; “¶}]” ] ;

[ “appPhoneMobile” ; “¶appPhoneMobile” ] ;

[ “}],\”info\”” ; “appPhoneMobile}],\”info\”” ] ;

[ “skip” ; “fetchCount” ] ;

[ “\”:\”” ; “|” ] ;

[ “\”,\”” ; “|” ] ;

[ “},{” ; “|” ]

)

You’ll see that I’ve used the field appPhoneMobile in the substitute, that string is also the first data label returned in the data metadata.

I’ve also substituted skip with fetechcount, this enables be to get the number of records in the found count, which I use when looping through the data to know when to exit the loop, as well as ask the user if they want to sync 242 records.

Now we have some data that I can read and deal with logically, I’ll get a record by the first delimit being appPhoneMobile. I start with the 3rd delimit as 1 & 2 don’t contain data.

Set Variable [ $a : Delimit ( field_name ; “appPhoneMobile” ; 3 ) ]

This gives me 1 record effectively, then I delimit that by the pipe character ( | – which I’ve substituted above) to set each field.

Set Field [ appPhoneMobile : Delimit ( $a ; “|” ; 2 )

Set Field [ appFirstName : Delimit ( $a ; “|” ; 4 )

Set Field [ appLastName : Delimit ( $a ; “|” ; 6 )

Hopefully that makes sense, I am sure there is a better way to do it though now reading through it.

 

API CALLS

Below are some other API calls such as PUT, DELETE & POST from within FileMaker.

 

PUT Example

In FileMaker speak, this is to update field/s in a record. Hopefully you’ve still got an idea about the URL string from the previous post.

What we’re going to do here, is update the first name to Steven. We have already got Stevie Hallo’s data in our file, so we know the Record ID (65550), as it comes down with the data.

http://server_accountname:server_username@mywebsite.com.au/RESTfm/filename/layout/restfmClient/65550.json?RFMsF1=appFirstName&RFMsV1=Steven

You can see here that I’ve only bolded the information that needs to be pointed out here. Pretty easy huh?

Now, lets change the first and last names to Steve Hello.

http://server_accountname:server_username@mywebsite.com.au/RESTfm/filename/layout/restfmClient/65550.json?RFMsF1=appFirstName&RFMsV1=Steve&RFMsF2=appLastName&RFMsV2=Hello

You should be able to see the pattern of field and value pairs. Also you can use fields as opposed to hard coded values, or you can just build the URL string to be inserted.

 

DELETE Example

Ok, hopefully this is making sense. Now with FileMaker, we can only do GET requests, so we need to be creative here. With RESTfm with can do this by calling a script after the GET request. Here we are going to delete the record we have just updated above. The URL has a suffix which calls a script to run, being RFMscript, and the script we want is a 1 step FileMaker script titled DeleteRecord.

http://server_accountname:server_username@mywebsite.com.au/RESTfm/filename/layout/restfmClient/65550.json?RFMsF1=appFirstName&RFMsV1=Steve&RFMsF2=appLastName&RFMsV2=Hello&RFMscript=DeleteRecord

 

POST Example

Now we are going to create a record, a client called Jimi Hendrix.

Here we need to slightly modify the URL we’re posting to, but adding “post” in to the string, as well as a suffix RFMfixFM02=1.

httppost://server_accountname:server_username@mywebsite.com.au/RESTfm/filename/layout/restfmClient.json?RFMsF1=appFirstName&RFMsV1=Jimi&RFMsF2=appLastName&RFMsV2=Hendrix&RFMfixFM02=1

 

OK, I think that’s it…..for now.

 

Happy FileMaking!

Leave a Reply

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

ARE YOU READY? GET IT NOW!
Get in touch.
Fill in this form, and we will get back to you.
Thanks!
We've received your info and we'll be in touch soon.
PGlmcmFtZSBzcmM9Imh0dHBzOi8vcGxheWVyLnZpbWVvLmNvbS92aWRlby8yMDMwNDI4MzUiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZyYW1lYm9yZGVyPSIwIiB3ZWJraXRhbGxvd2Z1bGxzY3JlZW4gbW96YWxsb3dmdWxsc2NyZWVuIGFsbG93ZnVsbHNjcmVlbj48L2lmcmFtZT4=