Help with a Shortcut making an API call

I’m trying my first more advanced Shortcut and running into a wall. I don’t know if it’s a bug in shortcuts or if I’m doing something wrong.

I have a process that I need to run that requires 2 curl commands. One to get an access token and another that uses that token to kick off a different process using our API.

The first part works great, and I figured out how to get the token out of the JSON that is returned by the first curl. When I try to send the second command, part of the path needs to be a variable, which I’ve called customerName. When I hardcode the path in the filename key, it works. Using the variable fails.

I added a step two copy the value of the customerName to the clipboard after I set it so I could troubleshoot, and then when I paste it in after the call fails, it’s appeneded the extra bit from the fileName key. It’s very frustrating. Any ideas for how I could make this work?

Well, I worked around it by actually using the clipboard value in the filename path key instead of the variable that should be identical. That kind of offends me on an aesthetic level, but what are you gonna do? It works.

1 Like

Let me be sure I understand correctly. Should the value of fileName be one of the following?

  • customerName/Config.xml (in which case, the crossed-out part is what’s getting added)
  • customerName/crossed-outText (so Config.xml is what’s getting added)

If, as I suspect, it’s Config.xml that’s the trouble, you might be able to remove the offending extra bit using regex. Something like this:

That won’t be exactly what you need, but hopefully it’s helpful in thinking about how to adjust the customerName variable.

I see you beat me to a solution, and yours is much simpler! :+1:

The value of filename should be customerName/[proprietaryservice]Config.xml. The crossed out bit is the name of the Config file (which includes the name of the service being configured), but every customer’s config file is named the same. It’s just the directory name that is customer specific.

My workaround works, but I’m just wondering why setting the variable name didn’t work.

In the interest of science, here’s what the workaround looks like.

1 Like

Yeah, that’s odd that using the variable doesn’t work.

I’d misunderstood, and thought that something was getting appended to the variable for some strange reason.

Shortcuts can be weird. ¯_(ツ)_/¯

1 Like

Without having a copy of the Shortcut to physically examine, it appears that, in action 2, you are setting the customerName variable to a blank. Where the action shows Input in light blue, it should say Provided Input and have the action symbol at the start:

Tap on the word Input and select the variable Provided Input from the list of available variables.

Hope this helps.