Variable in API query will not evaluate to a value that is sent in with additionalScope

@discobot Any insights?

Hi! To find out what I can do, say @discobot display help.

@discobot display help

I currently know how to do the following things:

@discobot start {name-of-tutorial}

Starts an interactive tutorial just for you, in a personal message. {name-of-tutorial} can be one of: tutorial, advanced tutorial.

@discobot roll 2d6

:game_die: 3, 6

@discobot quote

:left_speech_bubble: Don't compromise yourself. You are all you've got. — Janis Joplin

@discobot fortune

:crystal_ball: You may rely on it

hey @shawncrocker
In order to test "doesn't seem to be actually sent to the variable to be accessed by the api query":
Can you re-route your query to some temporary JS query to console.log(item) ?
e.g. replace on line 14 get_metadata with temp_deubgout_or_what_you_name_me, a newly created JS query that will console.log the passed parameter item to test
I'm not sure if my advice is the same as what you're describing ("return the results of the endPoint variable and then copy and paste it directly into the query I'm trying to send it...") or if I've helped any. I have seen due to scoping and the way dynamic strings are built that what's seen hovering above a variable in the UI isn't necessarily the same as what's captured at runtime in the call stack. I think my troubleshooting tip would narrow down pre or post additionalScope being where the problem lies. Can you let me know?
And your onSuccess is misspelled

Hi Thanks for this. I did notice that misspelled function after posting and hoped gleefully it would solve my issue but no, it didn't. I will try narrowing this down with you suggested technique. Can you tell me, what part of the chrome console displays the messages sent there using the console.log() function?

Yes, It's the info part of the console

There is also a Debug Tools beta feature you can turn on in /settings/beta

With it on, you can access the in-app console\


Ok Thanks! I can't wait to get to the bottom of this. I started this app to automatically pull thumbnail images from our design system to populate bills of materials and it turns out its the one thing I still haven't been able to complete! :rofl:

Let us know how it goes!

So I was able to perform some productive testing. When sending to a JS query and having the receiving JS query send the variable to console, the console shows the correct information. If I copy the text from the console that represents the information contain in the received "item" variable, paste it into the API query in place of the variable, the API query runs and returns the desired JSON file. Just to clarify, this is how I am writing the variable into the API query. {{item}}.

I recognize the red doesn't actually mean an error. The query does actually return a 404 and in the request URL that was sent out, you can see something that doesn't belong in place of the string that should be there.

Here is a picture of the console after the test loop of 5 tries a different endpoint each time.

In the console tab, you won't see the URL params, but, in the network tab, you'll find the value. In my example, additionalScope is received by query2 as {item: 'queryasdf'} and this corresponds with the network request for /query?queryName=query2 whose request's metadata contains the URL params. Thus instead of{{item}}

Are you seeing that the additionalScope value in your screenshot when hard-coded into your URL succeeds (e.g. runs and returns the desired JSON file) while the query using {{item}} returns a 404 thus indicating its passing a different URL param? Or, are you saying that the "d/b43cb46" is a different value than that of the one you copy/pasted from console?

In either case, how do the two {{item}} strings differ from the successful response and the failure?

1 Like

Yes I'm saying if I copy and paste the value that was generated and is listed in the additional scope from the console straight into the API query URL, it returns the desired JSON properly. But using the {{item}} it returns a 404

Not sure if this gif helps at all(4mb limit makes it hard to create a clear .gif)

2022-08-26 07-15-30 (3)

+1 here I have been seeing issues with using additionalScope recently as well

@ScottR Hi. Thanks for adding that tidbit. I will set this up for a try. I am able to get this working when passing into a JS query so I have hopes that I am almost at a solution or at least, a work around?

@shawncrocker what value do you see is sent in the metadata of the network tab's request?

Ya! It looks like the URL is actually getting sent to the API query. From the place you have indicated, I copied out the the URL that was sent. It seems the URL that I want to send and am sending over to the query, contains a "?". This is needed on the receiving end API. Looks like retool is for some reason receiving the variable and then converting the "?" into a "%3F". Thanks for narrowing this down for me. I'm sure I can do some text manipulation in the API query to fix this but, is there a setting to stop retool from changing values like this? I get there may be common scenarios where this is desirable behavior. I ask because in some of my other queries, I have also have to manipulate the data received by a variable to correct "?" and I think "%" from being changed.

So it looks like putting " {{item.replaceAll("%3F", "?")}} " in still didn't work. The passed url still contains a "%3F" inplace of a "?"

Holy &*%$. I didn't think I would see this tonight but it now works! Becaue I new the "?" would always be there, I broke the variable into an object with two parts. The part before the "?" and the part after the "?". In API query, I manually inserted a "?" between the two variable object properties, and, this baby, bees workin! Here is the code I put into the API query. {{item.firstPart}}?{{item.secondPart}}.

My curiosity still persist however. Is this normal? Should I have to be strong arming it into submission like this? What if the "?" sometimes was at the end or changed places according to other logic being used to create the URL? What is it with the "?" that retool doesn't like transferring through variables. As it has no problem with it when it is statically entered into the URL field.

1 Like