Insert From URL V2

A few years back, we released a demo to discuss/review the cURL functionality introduced into the “Insert from URL” script step in FileMaker 16. While the cURL implementation introduced some data transfer standards into the FileMaker framework, the real magic happens in the “Insert from URL” script step.

In this new version of the cURL demo, we took the same demo from the cURL blog post and gave it some updates, applied a new theme, and added the feature to send HTML emails using the SMTP(S) protocol introduced in FileMaker 18. We’re also using a navigation module we’ve built that utilizes the JavaScript functionality introduced in FileMaker 19.

POST

The POST request is one of the primary functions of any API. Creating a POST request in the “Insert from URL” script step can take some trial and error, but can quickly become an effective tool in a developer’s toolbox with some practice. In this example, we’ve built a simple POST request to Postman Echo, which is a free tool offered by Postman to test API calls. In our line of work, Postman is one of the primary tools we use for building and testing such calls. 

This example is fairly straightforward. We’re defining a URL, setting the cURL options, sending the request to the API using “Insert from URL”, then capturing the response into a field. These steps define any basic call to an API.

Upload a File to an FTP

In this example, we’re using “Insert from URL” to upload a photo to an FTP service. Like the POST process, we’re gathering the data (file) into a variable, setting the URL, defining the cURL options (username and password for the FTP, along with the file variable), then sending the request. The FTP service being used is offered by dlptest.com, which offers free HTTP(S) tests, FTP tests, and a few sets of sample data to use for solution testing.

Validate URL

To validate a URL, we’re using the same process: defining the URL, setting the cURL options, sending the request, then capturing the response. FileMaker will use its basic “Open URL” function to load the URL. If FileMaker cannot access the URL, an error 5 or 1631 will be returned. Once FileMaker can open it, the URL is validated in the header response with “HTTP/1.1 200 OK”. All the other header data is cache and cookie info, which can be used for other purposes. The response HTML data can be further scraped for additional information.

List Directory

Listing an FTP directory is also straight-forward. The FTP service being used here is located at speedtest.tele2.net, which also offers an upload/download test service. The response from this request lists the directory of their test FTP service.

HTML Email

FileMaker introduced the ability to send SMTP emails in version 18, which uses the MIME (Multipurpose Internet Mail Extensions) format to compose each part of the message, separated by a boundary composed by an ASCII character string (like a UUID) into an “envelope”. In this example, we’ve recreated one of our newsletter emails. The first tab sets up the content, which contains the sender and recipient, and composes the email. The second tab contains the SMTP info, and the third tab contains the CSS which is applied to the message body to create the style. Once all that is put together into an envelope, the whole thing is sent as a request to the SMTP server using “Insert from URL”. The SMTP server then composes the email by breaking down each part within the “envelope” and sends the message to the supplied recipients.

In order to build the HTML-formatted email, we’re doing a number of substitutions to insert field values into the HTML body of the template. 

 

<body>
   <div class=”container”>
      <img src=”{{HEADER_IMAGE}}” id=”header” />
      <h1 class=”C title”>
         {{HEADER1}} 
      </h1>
      <h2>
         {{HEADER2}} 
      </h2>
      <h3>
         {{HEADER3}} 
      </h3>
      <h4>
         {{HEADER4}} 
      </h4>
      <table>
         <thead>
         <tbody> {{BODYLABEL}} {{BODYTEXT}} </tbody>
         </thead>
      </table>
      <img src=”{{SIGNATURE_IMAGE}}” id=”sig” /></br>
      </br>{{SIGNATURE_TEXT}}</br>
      <footer id=”footer”>
         <ul class=”footer__items”>{{FOOTER_TEXT}}</ul>
         <img class=”footer__logo” src=”{{FOOTER_IMAGE}}” alt=”footer”>
       </footer>
   </div>
</body>

 

Once we have the substitutions in place, we can preview the email in a web viewer, which is handy since the email will look the same in the recipient’s inbox. As you can see in the demo, we still need to inject some styling into the body content to get the hyperlinks and formatting just right, but since all of this can be done without plugins, we’re still pretty happy with the result.

With the introduction of the Claris Marketplace, we have plans to turn the HTML Email functionality into a standalone product. Keep an eye on this blog space or subscribe to our newsletter to be informed on upcoming products.

Conclusion

This article just scratches the surface of what can be done with the “Insert from URL” function, especially in regards to APIs. The fact that Claris continues to enhance that functionality only solidifies the need to dive into APIs as that world continues to evolve.

 

Bonus Content!

As I mentioned earlier in the post, we’re using this opportunity to show a navigation module that utilizes the JavaScript functionality introduced in FileMaker 19. The demo has two navigation variants: a FileMaker 18 version, which is composed of a card window and button bar, and a FileMaker 19 version, which is done in a web viewer. The web viewer loads the content from a field in the PREFERENCES table. Each button is composed of an “onclick” action that calls a “performFileMakerScript(id)” function.

<a id="sc1" href="#" onclick="performFileMakerScript(id), closeNav()" style='color:#F9F9F9;'>Overview</a>

The “(id)” passed into the new “FileMaker.PerformScript” function is the ID returned by the “onclick” function. The “FileMaker.PerformScript” function calls a FileMaker script, so the ID passed back into the FileMaker script is used to navigate to the corresponding object or layout.

function performFileMakerScript (id) { FileMaker.PerformScript("nav", id ); }

What initially started as a way to test new FileMaker 19 functionality has turned into a nice little navigation module. That open/close effect has that satisfying effect, similar to the click of the magnetic case closer of the Apple Airpods or a soft-close drawer.

If you have any questions regarding the functionality in the demo or if you would like assistance implementing these into your solutions, please feel free to send us a message.

 

Double Bonus!

Dark Mode in FileMaker 19! We’ve added a dark-mode theme to this demo. If you’re on a Mac and have dark-mode enabled, it’ll switch to the appropriate layout with the theme applied. Check it out and let us know what you think! If there’s enough interest, we may put it out as a free download.

PatternCount ( Get ( SystemAppearance ) ; "Dark" ) = 1

1 thought on “Insert From URL V2”

  1. Great post and lots of useful information. It seems that the ample file is locked and I cannot access any scripts, layouts, etc.

Leave a Reply

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