Dictionary to / from TXT file

shortcuts

#1

Somewhat related to my IFTTT topic in the Web section on this forum I’m trying to get a TXT file to load as a Dictionary within a shortcut.

The shortcut has two options:
Create webhook dictionary entry
Run dictionary entry (I say Run since I’ll be calling this shortcut from other shortcuts, primarily)

The dictionary is written in proper JSON to the TXT file when choosing Create, but when I choose run, instead of a list showing the entries, I get a long list of “Metadata” like this

What am I doing wrong, I wonder!?!:thinking:

/////////

Shortcut actions - in Text:
Create)
Ask for Input = “event Trigger name”
URL= IFTTT Webhook URL with event Trigger name"
Set dictionary entry = “event Trigger name”; URL
Append to TXT file in iCloud/Shortcut directory/IFTTT webhooks/webhooks.txt

Run)
Fetch iCloud/Shortcut directory/IFTTT webhooks/webhooks.txt
Get dictionary from input
Choose from list

Hope I can get some pointer to what I’m doing wrong​:crossed_fingers:t2::grin:


#2

Here’s an example:

Scanning through what you have, I think your JSON is wrong.

Taking a combinaton of my example and your screenshot, I think you have something like this:

{"Test" : "https://maker.ifttt.com/trigger/Test/with/key/1x2x3x4x5x6x"}
{"Hejsa" : "https://maker.ifttt.com/trigger/Hejsa/with/key/1y2y3y4y5y6y"}

But I think you should have something more like this:

{
    "Test" : "https://maker.ifttt.com/trigger/Test/with/key/1x2x3x4x5x6x",
    "Hejsa" : "https://maker.ifttt.com/trigger/Hejsa/with/key/1y2y3y4y5y6y"
}

i.e. it’s like you have created two isolated ditionaries in one file each containing a single key value pair, rather than creating a single dictionary containing two key value pairs.

It may be worth you validating any future data using something like JSONLinter, just to ensure you have your format correct.

Hope that helps.


IFTTT: run shortcut through rich notification?
#3

Oh, now I see what’s wrong (problem with working on several points in same shortcut(s) workflow simultaneously😅) - when the shortcut creates a new dictionary input, it’s really a new dictionary that is then appended to the existing txt file that acts a the dictionary database.

I’ll have to do some heavy duty text separation and combination in the workflow, to append to the TXT file - but I’m getting there :joy:

Thank you for the help with this part of the workflow - hope I’ll have the IFTTT workflow running soon, as well - so I can post the shortcut here for easy reference for others, as well :slight_smile:


#4

Finally got this shortcut working thanks to your help @sylumer - you definitely saved my bacon :smile:

So, here’s the shortcut - it kinda grew on me, so what it does now is:

  • It checks for a specific file intended as the dictionary, and if missing creates the file with a dummy dictionary entry
  • Present a menu letting the user:
    • create an IFTTT Webhook entry into the dictionary - simple or with variables (variable option not working properly atm, though
    • Fetch value from dictionary
    • Print the dictionary to screen
    • Edit the dictionary in app by choice
    • Cancel use and exit shortcut

It’s intended to be used from other shortcuts but can run stand-alone though this does give some minor lag (will also lag if Show when run (I think it’s called in the English Shortcut app) is enabled when running within shortcut).

The reason I’m posting the shortcut here is that even though I made it for use with IFTTT it can be transformed into other dictionary use cases, so if anyone find this useful feel free to use it as you see fit :smile:

IFTTT Webhook Database shortcut

This is a work in progress as I’m intending to expand this with the option to create a working IFTTT Webhook from scratch to server side creation done as well through this shortcut (if that’s even possible :crossed_fingers:)