21

iOS Shortcuts to the FileMaker Data API

 5 years ago
source link: https://www.tuicool.com/articles/hit/n6773qI
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Shortcuts, on iOS, are a new way to automate tasks by mixing together apps, content on your iOS device and web APIs into custom workflows. Now, via the FileMaker Data API, you can use shortcuts as a way to interact with your FileMaker solutions.

Here’s an example of automatically uploading a photo from your iPhone into a FileMaker container field, via iOS shortcuts to the FileMaker Data API.

Here’s the example file and shortcut for you to download: Shortcuts and FileMaker

What’s a shortcut?

A shortcut is a set of tasks, built in multiple steps, managed through the Shortcuts app on iOS . The building block of a shortcut is called an “action”. Each action is a single step in a task, and each shortcut consists of one or more actions.

Documentation for the Shortcuts app ( What’s a shortcut? ) gives an example of building a “Surf Time” shortcut: grabbing the surf report, giving an ETA to the beach and then launching your surf music playlist.

Shortcuts? "Hey, I’m a FileMaker developer!"

No problem! Think of a shortcut as similar to a FileMaker script. And an action would be like a single script step. So, how can we use this fantastic app with FileMaker?

Easy! Using the FileMaker Data API , you can integrate a shortcut with the FileMaker Platform to do things like create, edit and delete records.

And not only that: you can also build a shortcut to upload a file or an image to a container field. Or imagine using Siri to ask questions and get all kind of answers from your FileMaker solutions…yes, shortcuts controlled with your voice!

And please note, FileMaker Go is not required, at all. Users on iPhone and iPad can use shortcuts from their iOS apps and content directly to FileMaker, through the Data API. Let me show you how this is done…

Let’s start with the basics

In this simple example, I will create a shortcut that, after connecting via the Data API to my FileMaker server, will take an image from the Photos application on my iPhone and upload it into a container field.

First of all, download and install the Shortcuts app from the App Store (it is free) from the following link:

https://itunes.apple.com/us/app/shortcuts/id915249334

QZBfYb7.png!web

Once installed and opened, just click on “Create Shortcut” to create a new document.

Select the actions you want to use from the guided search and add them to the document.

Each action is performed progressively from the beginning to the end of the document.

In our case the steps will be the following:

Step 1

Set a variable from a text block with the URL value of our server where the FileMaker Data API is active.

Note: Remember to use an SSL certificate on your FileMaker Server!

Text+ Add to variable

qQniIjV.jpg!web

Step 2

Ask the user to enter the credentials and save them in a variable.

Ask for Input+ Add to variable

(this to avoid storing the credentials in our action)

Repeat the steps also for the password request.

Jbme6f6.jpg!web

Step 3

Concatenate username and password separating them with a “:” and then perform an encode in base64, to manage the Basic Authentication provided by the Data API.

Text+ Base64 Encode

R3qMRjF.jpg!web

Step 4

Set the URL to log in via Data API ( URL / fileName /sessions).

Make an HTTP POST call to receive the token and authenticate the user.

URL+ Get Contents of URL

Set as Method: POST and as Headers:

Content-Type: application/json

Authorization: Basic Base64 Econde (this value comes from our previous variable set above)

6fiIZzQ.jpg!web

Step 5

Get the response from the endpoint, parse the received object and save the token to a variable.

Get Dictionary Value( response ) + Get Dictionary Value ( token ) + Add to Variable

VRvUzib.jpg!web

Note: I’m using the If statement to check if the token variable exists.

Step 6

Set the URL to make the record creation request via Data API ( URL / fileName /layouts/ layoutName /records)

Make a http POST call to receive the ID of the new record created.

URL+ Get Contents of URL

Set as Method: POST and as Headers:

Content-Type: application/json

Authorization: Bearer token

euAn63u.jpg!web

In the request body add a new field and name it: fieldData and as value compile the JSON object (dictionary) with the information of the fields that you want to enhance when creating the record. In our case we are passing the following item: data = “Test from shortcuts”.

Step 7

Get the response from the endpoint, parse the received object and save the value of the ID record created in a variable.

Get Dictionary Value( response ) + Get Dictionary Value ( recordId ) + Add to Variable

yYNfAnQ.jpg!web

Step 8

Open the camera roll (Photos, on iOS) to select the image to be loaded into the container field.

Select Photos

jaq6zaF.jpg!web

Step 9

Set the URL to request the upload container via Data API ( URL / fileName /layouts/ layoutName /records/ id /containers/ containerNameField / repetition )

Make a http POST call to receive the ID of the new record created.

URL+ Get Contents of URL

Set as Method: POST and as Headers:

Content-Type: multipart/form-data

Authorization: Bearer token

Request body (type Form):

Add a new field and name it: upload and select the photo variable using the “ Magic Variable “*

eQnqEba.jpg!web

Step 10

Set the URL to log out via Data API ( URL / fileName /sessions/ token )

Make an http DELETE call to delete the session on the FileMaker server for the logged in user.

URL+ Get Contents of URL

Set as Method: DELETE and as Headers:

Content-Type: application/json

YVbAjuV.jpg!web

*Magic Variable

In the steps of our actions, you can enter manual values or recall them from the variables created…Or, in some cases, you can use the “Magic Variable” selector to get help from the application in using a variable in the next step.

Ij6Bbez.png!web

Conclusion

Shortcuts, on iOS, are very interesting and may open up a lot of new opportunities for FileMaker interactions with third party applications, content and web APIs. I built an example of automatically uploading a photo from your iPhone into a FileMaker container field, via iOS shortcuts to the FileMaker Data API. Hopefully, you’ll test it out, and also try building shortcuts that work with other iOS apps, or perform tasks that interact with other functionality in FileMaker.

And, please stay tuned! In a followup blog post, we’ll be asking different questions to Siri to show how it can interact with FileMaker to provide you with answers.

Download the example file and shortcut: Shortcuts and FileMaker


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK