Both of them sends “null” with the custom url and displays “Missing Parameter” as a message when the user doesnt type anything besides the command(the URL has a propper text response), I’ve tested without the if/else and the message is displayed properly but I need to make sure that the “null” does not get sent with the URL
Did not worked, the ELSE code was still showing in the chat correctly but the urlfetch inside the IF was still running, I ended up adding a validation to check if passed argument is null at the url endpoint
now it is something like this:
$(eval '$(urlfetch URL$(1))';)
then the code checks the value and returns “Missing parameters” if its null or else it will return the sucess message.
It’s normal the $(urlfetch) is still running, since it runs inner variables before outer variables.
The solution you got is satisfying given the amount of detail you provided. We assumed you were only fetching data.
If you’re updating a database, but you want to update it only if $(1)!=null, then using an alias command is your best bet. Simply cut the URL in half, keep the first half in the alias and send the second half from the main command only if the if statement runs.
This solution comes from @RokettoJanpu! I had the same issue once and he helped me.
So let’s say you want to add a quote only if $(1)!=null:
You’d have your main command like this:
$(eval
if(`$(1)`!=`null`){
r=`PRIVATE_TOKEN&data=$(querystring)`;} //if true, send the token as well as the quote text
else{
r=`Quote missing.`;} //if false, send error message
r) //r is what you send to the alias command
Then you’d have you alias command like that:
$(eval
a=`$(urlfetch https://twitch.center/customapi/addquote?token=$(query))`; //can only add quote if token, so it won't do anything if error message
b=decodeURIComponent(`$(querystring)`);
b.includes(`PRIVATE_TOKEN`)?`${a}`:`${b}`) //if includes token, display "quote added", else display error message