Shortcut fails when I remove the debugging?

Just wondering if anyone has come across this problem before or can share any insight with me.

I have a shortcut that does this just fine:

  1. make an API call, it’s a GET call
  2. use the “Show Result” action to check I got something back
  3. save the contents of the URL - which are a JSON dictionary - as response
  4. then I get the dictionary from response and loop through it

But if I miss out Step 2, which is only there for debugging purposes, then the shortcut just seems to give up and not loop through the dictionary made from response.

Stuff I have tried:

  • The API is kind of slow to respond (like 2 seconds or so maybe) so I’ve tried making the shortcut wait instead of showing the response, for various lengths of time. Nothing worked.
  • Tried showing the result in the loop through the dictionary. Nothing happens, I don’t think it ever gets the dictionary from the response to get into the repeat with each item loop.
  • Tried moving the “Show response” to the very end of the shortcut. That does show the response, so it did get it, but the loop doesn’t get looped around all the same.
  • Tried it on iOS and macOS, same thing happens on both.
  • Tried putting a “Nothing” block in instead of the “Show response”, not helping either.

I don’t want to share the whole shortcut because you’d need an API key to get it to work but this is the relevant bit. If I remove the highlighted “Show response” block then the “repeat with each item in Dictionary” bit doesn’t fire.

Is there something I’m missing here? Or another way I could turn a JSON response into something a shortcuts loop can handle maybe?

It is of course hard to investigate without access, but what happens if you don’t set the response variable, but instead access directly via a magic variable? Same failing?

Thanks. If I just use the url contents to set the dictionary then I get the same failing, it doesn’t go round the loop.

It’s frustrating! I’m going to have a look later and see if I can mock something up that does the same kind of thing without the API access being needed, see if I get the same behaviour elsewhere.

Hmm, well I tried grabbing data from some random APIs from Free API - Huge List of Public APIs For Testing [No Key] - Apipheny and I couldn’t reproduce the problem with those so I figure there must be something up with the data returned by this particular API.

I just tried putting in a Text block instead of the Show Result block and that seems to make everything work ok, and isn’t interactive which is what’s needed. I wonder what those blocks are doing to my variable though! I feel like it might be trimming white space or changing line break formats or something like that but haven’t got time to look at it further at the moment.

Just a hunch here. Try removing the Get Dictionary from Input action and use the output of Get Contents of URL directly on the Repeat.

With the lack of sample data, here are my assumptions.

  • the output of the API is an array (List i. shortcuts), because you’re doing a repeat from it
  • Shortcuts is “funky” when trying to convert dictionary from an array. It fails most of the time (at least from my experience)
  • since the output is already a list, conversion is not needed, you can directly use it as input on Repeat with Each