The "One" REST Script

When it comes to programming, there's always more to learn and share. If you've worked with REST APIs in the past, then you may have already devised your perfect system. If not, then this video will showcase a freely available script which you might want to consider first before trying to solve the problem yourself.

In our ever expanding world of coding to standards and systems, many of which have existed for decades, it's always prudent to see if you can beg, borrow and... Ok, don't steal... code which already does the trick. When it comes to HTTP's REST implementation we've already got all the code necessary.

Thanks to a great community contribution by Todd Geist, you really don't need to fumble through all the variations and possibilities of HTTP's REST methods used by FileMaker's cURL features found within the Insert from URL step. Todd and company did the heavy lifting and made an open source file available to everyone.

In this video I showcase my own personal enhancements to the script and provide some insight into some of the ways I code and why I do the things the way I do.

Comments

Hi, I'am glad listening to this video, exactly what I needed but, I am concequently having the error:
"code" : -1,
"status" : "Expected header is missing"
The headers is set to {}, as you said. Acually the script stops on line 78.
Can you help me out? Thanks

Joost Wösten
Dhaag database techniek
Netherlands

Though you've hopefully found your answer ~1 year later, here is what I did to fix it:

Short answer:
You must determine which of your headers are not on the list of the script's expected header values. Then, add it to the list of values stored by $httpNonStandardHeaders.

Long answer:
Step through the script with the debugger + data viewer until you reach the the block that begins with 'Clean Headers'. The script will then compare the headers you've provided with a lists stored in $httpStandardHeaders & $httpNonStandardHeaders). If the script finds you have passed any headers *not on either of these lists*, the script will immediately fail (see 'If not $cleanSuccess' > Exit Script).

Just before the check for 'If not $cleanSuccess', use the data viewer to check what $updated gets set to. Any of your headers that are *missing* from $updated need to be included in $httpNonStandardHeaders; in my case, I needed to add "api-key". Once I did this, my next run of the script was successful.

I also changed the "status" text returned in the script result (in $responseJSON). Instead of a generic 'error: failed', it states that the failure was due to this 'unexpected header value' issue.

Filemaker version 19.6 is nessesary to use this script. Than it works fine. Great work.

Joost Wösten
Dhaag database techniek
Netherlands