UrlEncode usernames

Hi,

Is there any chance you could provide a way to urlencode anything sent in an UrlFetch command because I’m having serious problems dealing with usernames with unicode characters in, in youtube chat requests. The chat messages arrive and get processed fine because you urlencode those but not so with the username attached to it. So those with foreign or unicode characters are tripping up all manner of decoding at my end.

Thanks for any help,

Pat

Hey @Birbman_Pat!

Use $(querystring) instead of $(query) inside of your $(urlfetch), documentation.

Hi Emily,

Thanks for that. I do already use $querystring but that is only the message content. I am also sending the username ($user variable) which is not url encoded and as such is causing this issue.

Pat

Ah, right, sorry, I misread you.
Okay, so you’ll need two commands for this, second one being the alias for the first one.

First we’ll use JavaScript to encode the username:

!addcom !commandName -a=_commandName $(eval `${encodeURIComponent('$(user)')} $(querystring)`)

Then you’ll call your API with the output of that command:

!addcom _commandName $(urlfetch URL?q=$(querystring))

Of course you’ll need to adapt this a bit to suit your needs, but that’s the main way to go about it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.