Shortcuts for iPhone and iPad
Using Modzy within an iPhone, iPad or MacOS shortcut is simple
Short tutorial on building a Sentiment Analysis Shortcut.
Intro to Shortcuts on iPhone and iPad
What’s a shortcut?
A shortcut provides a simple way to add features or actions within apps or by asking Siri. Shortcuts can automate a wide variety of things—in example, analyzing text for sentiment.
Build a Modzy Shortcut
- In My Shortcuts in the Shortcuts app on iPhone or iPad, tap + in the upper-right corner. An empty shortcut called New Shortcut appears in the shortcut editor.
-
Tap [...] Shortcut Name, type the name of your shortcut, and select where you'd like your shortcut to work, then tap Done. For this example turn on Share Sheet and select only Rich Text, Safari pages and Text.
-
Tap Add Action, search for URL and tap the blue URL action. Type in the Jobs URL for your instance of Modzy (such as
https://trial.app.modzy.com/api/jobs
).

- Tap Add Action again and select "Get Contents of URL", then type Show More.

-
Choose POST as the Method
-
Add two new header fields:
- Key of
Authorization
with TextApiKey <paste your key here>
- Key is
Content Type
with Textapplication/json
- Key of
-
The Request Body should be JSON. Now add two new fields:
- Add a Dictionary field with Key
model
. Tap the '0 items' and add a Text item with keyidentifier
and Text ofed542963de
, then a key 'version' and a Text of1.0.1
This is our sentiment analysis model. - Add another Dictionary field with key
input
Tap the '0 items' and add a Text with keytype
and Texttext
, then add another Dictionary field with keysources
and tap the0 items
to add another Dictionary field of keymy-text
and a text item with keyinput.txt
and the Text you can click the Shortcut Input variable. - Click Done until you are back in the main shortcut editing screen. You should have a Request body with fields
model
andinput
with 2 items each.
- Add a Dictionary field with Key
- This action will call a Modzy model with the payload of the shortcut input!




-
Modzy is asynchronous so now we need to retrieve the results of the job. When creating the job, Modzy will return a job identifier we can use to retrieve the results. To get this jobId, tap + and select Get Item from list. This should autofill to Get First Item from Contents of URL.
-
Tap + and select Get Dictionary Value. Tap key and type
jobIdentifier
-
Tap + and select the blue URL. Edit this to include the URL of the Get results endpoint your instance of Modzy (such as
https://trial.app.modzy.com/api/results/
) and then tap the Dictionary Value variable.

- This is the location our results are stored. To retrieve the results, add a Get Contents of URL action, this time leave the method as GET but enter the Authorization and Content type as before.

-
This will retrieve the results of the analysis job, which we must now parse by walking through the JSON object tree.
-
Add a Get Dictionary Value action, tap key and type
results
-
Add a Get Dictionary Value action, tap key and type
my-text
-
Add a Get Dictionary Value action, tap key and type
results.json
-
Add a Get Dictionary Value action, tap key and type
data
-
Add a Get Dictionary Value action, tap key and type
result
-
Add a Get Dictionary Value action, tap key and type
classPredictions
-
Finally, we are at our results!


- From here, let's just display an alert with the results and not parse them further. Add a Show Alert action with the Dictionary Value from the previous step, and the Shortcut Input as the Title.

- That's all! It was a lot of steps to parse through that JSON object, but that is just how Shortcuts works.
- Let's try it out: go find some text, select it, click Share... in the popup menu, then scroll down until you see your Shortcut in the actions menu.
Updated over 1 year ago