FMP URL redirection with Node-RED

Have you ever tried to provide FMP URLs to users only to find that your environment was refusing to make the FMP URL a clickable link? This problem is common in web-based email clients, wikis, and other workgroup communications platforms.

The last post on Node-RED focused on installing and configuring a production-ready Node-RED server. In this post, we’ll look at how you can use Node-RED to improve the reliability of FMP URLs.

Scenario: Your system sends a notification to users via email, which includes an FMP URL to open the relevant record in FileMaker Pro or Go. But web based email clients might not output the FMP URL as a hyperlink.

Scenario 2: You wish to include FMP URLs in an environment that will not treat them as hyperlinks, like Microsoft Teams or a wiki platform.

Solution: Instead of including an FMP URL in the email, call a Node-RED service that will perform a redirection.

Configuration

Configure a Node-RED server (see our tutorial)

Click the hamburger menu and select “Import”, then paste the following:

                    



[{"id":"b552958e.7ec0e8","type":"http in","z":"eeefc321.bff","name":"","url":"/fmpredirect","method":"get","upload":false,"swaggerDoc":"","x":150,"y":240,"wires":[["599bfe68.89ece8"]]},{"id":"728fd6d5.566908","type":"http response","z":"eeefc321.bff","name":"","statusCode":"","headers":{},"x":530,"y":240,"wires":[]},{"id":"599bfe68.89ece8","type":"function","z":"eeefc321.bff","name":"","func":"msg.statusCode = 307;\n\nvar script = msg.payload.script;\nvar param = msg.payload.param;\nvar host = msg.payload.host;\nvar file = msg.payload.file;\n\nif ( !host ) { host = \"$\" }\n\nvar location = encodeURI ( \"fmp://\" + host + \"/\" + file + \"?script=\" + script + \"&param=\" + param );\n\nmsg.headers = { \n    Location: location\n}\n\ndelete msg.payload;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":240,"wires":[["728fd6d5.566908"]]}]

Click “Import” and place the nodes on your flow.

The nodes look like this:

Usage

https://yournodered.com/fmpredirect?host=yourfmpserver.com&file=filename&script=My%20Script&param=Hello%20World

Options

host (optional) – your FileMaker Server hostname. If omitted, file with matching name must be open on client.

file – the file name (excluding .fmp12), URL encoded.

script – the script name, URL encoded.

param – the script parameter, URL encoded.

Taking it to the next level

This solution is designed for maximum flexibility, but you can probably see how it would be easy to shorten your URLs by providing dedicated endpoints for particular use cases, so instead of:

https://yournodered.com/fmpredirect?host=yourfmpserver.com&file=filename&script=My%20Script&param=Hello%20World

You could provide a purpose-built endpoint that would let you do the same thing with:

https://yournodered.com/myscript?param=Hello%20World

Or you could use an approach like a URL shortening service, where the full instructions are stored in a database, and the user clicks a URL like:

https://yournodered.com/z?9s8d7f

In this example, the “z” endpoint tells Node-RED that this is a shortened URL. The key is then extracted and looked up in FileMaker via the Data API to determine the redirect URL, which is then returned to the original user via http redirect!

This is just one of the many things you can do with Node-RED! What are you doing with Node-RED?

Leave a Reply

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