Table of Contents

How to encode a variable

Ana Updated by Ana

It is common that some inputs from the users need to be processed so that they can be recognized as valid URLs by any API.

You will see in some URLs, that when you are using two words with a space, it becomes something like this: firstname%20lastname, you can do it manually but it will be painful. To fix it, here I have a solution step by step.

  1. Once you select the variable in Landbot that needs to be encoded, we will add a Code block:

  1. In the Code block we will add the following code, where "toencode" is the variable that you want to have encoded, and "encodedvariable" is the new variable where the encoded value will be set. You can also change the names as you need.


  1. Now, we have a new variable called @encodedvariable, but it's value cannot be used inside Landbot yet. To be used we need to add a user input, like a Buttons type of question. Here we have an example of how it can be set:

  1. Once we pass the user input, we can use our new encode variable in a URL or a webhook

How did we do?