By the way, I’m using eval because the actual !test command will contain more code, but the relevant problem is this one, trying to use a variable with urlfetch.
If you need more than two levels of nesting, you’ll have to make !test an alias to another command. !test can pass data to the alias, and the alias can access it with the query variable.