# Url encoding string

**URL:** <https://community.thunkable.com/t/url-encoding-string/1408899>\
**Category:** Questions about Thunkable X\
**Tags:** webapi, url, text\
**Created:** [July 22, 2021, 12:42pm UTC](https://community.thunkable.com/t/url-encoding-string/1408899 "2021-07-22T12:42:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giuseppe\_Geppo\_Catta](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@Giuseppe\_Geppo\_Catta](https://community.thunkable.com/u/Giuseppe_Geppo_Catta)\
**Post date:** [July 22, 2021, 12:42pm UTC](https://community.thunkable.com/t/url-encoding-string/1408899/1 "2021-07-22T12:42:43Z")

</div>

Is there an easy way to encode a string to make it a valid URL?  
I need to send an SQL query using a web api, but int he query there is a field that contain a “free string” so It can contain whatever chars such as à,é," and not only spaces,quotation marks and apex.  
How can i transform it to a valid URL?

---

<div class="post-metadata">

**Author:** ![overturner](https://avatars.discourse-cdn.com/v4/letter/o/53a042/32.png) [@overturner](https://community.thunkable.com/u/overturner)\
**Post date:** [July 22, 2021, 2:12pm UTC](https://community.thunkable.com/t/url-encoding-string/1408899/2 "2021-07-22T14:12:51Z")

</div>

I was having this question too ❓

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [July 22, 2021, 3:02pm UTC](https://community.thunkable.com/t/url-encoding-string/1408899/3 "2021-07-22T15:02:05Z")

</div>

It is easy to encode strings. I can do a simple JavaScript function and demonstrate it but the actual question is:  
When you encode characters from your side, will the server know this is encoded to decode it before using it.

You need to provide more info because Thunkable has a block for `Web API Query` which should pass the required text without problems.

---

<div class="post-metadata">

**Author:** ![overturner](https://avatars.discourse-cdn.com/v4/letter/o/53a042/32.png) [@overturner](https://community.thunkable.com/u/overturner)\
**Post date:** [July 22, 2021, 3:17pm UTC](https://community.thunkable.com/t/url-encoding-string/1408899/4 "2021-07-22T15:17:15Z")

</div>

> [@muneer](#):
>
> It is easy to encode strings

How to do this , i needed it for a get function(not query parameters)

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [July 22, 2021, 6:03pm UTC](https://community.thunkable.com/t/url-encoding-string/1408899/5 "2021-07-22T18:03:04Z")

</div>

You could easily do that by using **btoa()** JavaScript function with the use of the `Web Viewer Extension`

```auto
<!DOCTYPE html>
<html>
<head>
<script src="https://thunkable.github.io/webviewer-extension/thunkableWebviewerExtension.js" type="text/javascript"></script>
<script>
    ThunkableWebviewerExtension.receiveMessage(function(message) {
        ThunkableWebviewerExtension.postMessage(btoa(message));
    } );
</script>
</head>
<body>
</body>
</html>

```

This will accept a string from the `Web Viewer PostMessage` block, convert it to Base64 string and send it back to `Web Viewer ReceiveMessage` block to use it in your app.

---

<div class="post-metadata">

**Author:** ![overturner](https://avatars.discourse-cdn.com/v4/letter/o/53a042/32.png) [@overturner](https://community.thunkable.com/u/overturner)\
**Post date:** [July 23, 2021, 3:17am UTC](https://community.thunkable.com/t/url-encoding-string/1408899/6 "2021-07-23T03:17:06Z")

</div>

Thank you @muneer Will try this

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Geppo\_Catta](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@Giuseppe\_Geppo\_Catta](https://community.thunkable.com/u/Giuseppe_Geppo_Catta)\
**Post date:** [July 23, 2021, 5:40am UTC](https://community.thunkable.com/t/url-encoding-string/1408899/7 "2021-07-23T05:40:01Z")

</div>

Will it work even with thunkableX?

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [July 23, 2021, 5:47am UTC](https://community.thunkable.com/t/url-encoding-string/1408899/8 "2021-07-23T05:47:25Z")

</div>

Yes, this code is designed for Thunkable X.

However for your SQL request, I need more details of what type of SQL DB are you using and what type of API and why do you want the “query” text to be part of the URL.

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Geppo\_Catta](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@Giuseppe\_Geppo\_Catta](https://community.thunkable.com/u/Giuseppe_Geppo_Catta)\
**Post date:** [July 23, 2021, 6:09am UTC](https://community.thunkable.com/t/url-encoding-string/1408899/9 "2021-07-23T06:09:44Z")

</div>

The API is made by myself as an interface with an SQL SERVER DB on my local net.  
A simple software that receive a query as parameter from an URL.  
This is an example:

```auto
http://192.222.115.245:8001/SQL_Server_API/SELECT?QUERY=SELECT%20*%20FROM%20MYTABLE%20WHERE%20ID=%27559%27%20AND%20LINEA=%27TR389%27

```

I have some problem when I have an original string like this to pass to the URL:  
WHERE DESCRIZIONE='Controllo conicità e verifica diametro 4" ’

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [July 23, 2021, 6:18am UTC](https://community.thunkable.com/t/url-encoding-string/1408899/10 "2021-07-23T06:18:45Z")

</div>

In this case you will need to change the accented characters to numbers like %20 for a space. So for á you use %C3%A1 and so on.

You can find the codes by using [urlencode.io](http://urlencode.io) for example or any similar site.

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Geppo\_Catta](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@Giuseppe\_Geppo\_Catta](https://community.thunkable.com/u/Giuseppe_Geppo_Catta)\
**Post date:** [July 23, 2021, 7:03am UTC](https://community.thunkable.com/t/url-encoding-string/1408899/11 "2021-07-23T07:03:16Z")

</div>

Of course, this is why I was asking for a simple way like a “url encoding” function.  
I know I can do it coding a behavior for every special char, but you know, maybe in a web API a similar function could have been already developed and I didn’t know 😉

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [July 23, 2021, 7:33am UTC](https://community.thunkable.com/t/url-encoding-string/1408899/12 "2021-07-23T07:33:29Z")

</div>

API(s) are server side apps created by developers like me and you to serve a certain purpose. The developer may add functionality in the service and may not.

This is why every API is different. One API could use encoding and another would not.

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Geppo\_Catta](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@Giuseppe\_Geppo\_Catta](https://community.thunkable.com/u/Giuseppe_Geppo_Catta)\
**Post date:** [July 23, 2021, 7:38am UTC](https://community.thunkable.com/t/url-encoding-string/1408899/13 "2021-07-23T07:38:55Z")

</div>

> [@muneer](#):
>
> encoding and another would no

In this case i should be able even to use a browser to get a SELECT result so I need encoding

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [July 23, 2021, 9:07am UTC](https://community.thunkable.com/t/url-encoding-string/1408899/14 "2021-07-23T09:07:55Z")

</div>

The standard format of an API response is JSON or XML format and both can include characters of different languages.

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Geppo\_Catta](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@Giuseppe\_Geppo\_Catta](https://community.thunkable.com/u/Giuseppe_Geppo_Catta)\
**Post date:** [July 23, 2021, 9:28am UTC](https://community.thunkable.com/t/url-encoding-string/1408899/15 "2021-07-23T09:28:43Z")

</div>

The problem is not the response but the request 🙂

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Geppo\_Catta](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@Giuseppe\_Geppo\_Catta](https://community.thunkable.com/u/Giuseppe_Geppo_Catta)\
**Post date:** [July 23, 2021, 9:47am UTC](https://community.thunkable.com/t/url-encoding-string/1408899/16 "2021-07-23T09:47:11Z")

</div>

```auto
You could easily do that by using btoa() JavaScript function with the use of the Web Viewer Extension

```

However it’s not clear tome how to use it.  
I’ve tried like this

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/8/08087730cc294060cc4a47ba3e4c4b8f740936f4.png)

But I got nothing back…

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [July 23, 2021, 10:43am UTC](https://community.thunkable.com/t/url-encoding-string/1408899/17 "2021-07-23T10:43:23Z")

</div>

As I have explained earlier, you cannot just an encoding algorithm on one side of the equation and not the other. If you encode your URL query then there should be a function in the receiving side to **decode** it back.

My suggestion is to use the character encoding as I showed in the previous post.

> [@muneer](#):
>
> So for á you use %C3%A1 and so on.

---

<div class="post-metadata">

**Author:** ![Giuseppe\_Geppo\_Catta](https://avatars.discourse-cdn.com/v4/letter/g/2acd7d/32.png) [@Giuseppe\_Geppo\_Catta](https://community.thunkable.com/u/Giuseppe_Geppo_Catta)\
**Post date:** [July 23, 2021, 11:03am UTC](https://community.thunkable.com/t/url-encoding-string/1408899/18 "2021-07-23T11:03:03Z")

</div>

Don’t care about the receiving side.  
On that side, the decoding is implicit in the GET function, no need to decode it back.  
At the moment my only need is to decode to URL.  
But as I understood I need to do it replacing special chars one by one,no automatic function.

---

<div class="post-metadata">

**Author:** ![Andrea\_Marchisio](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@Andrea\_Marchisio](https://community.thunkable.com/u/Andrea_Marchisio)\
**Post date:** [October 13, 2021, 3:15pm UTC](https://community.thunkable.com/t/url-encoding-string/1408899/19 "2021-10-13T15:15:39Z")

</div>

@muneer,  
as I already wrote in my post “Web app passing parameter URL”, I’d like to call my web app (Thunk) encoding the paramenter and get it inside the app.  
In your advice is it possible that?

Thanks  
Andrea

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [October 13, 2021, 3:27pm UTC](https://community.thunkable.com/t/url-encoding-string/1408899/20 "2021-10-13T15:27:27Z")

</div>

You can always pass parameters between a `Web Viewer` and the containing app but I don’t know if a `web app` will receive parameter from the URL.

The only way to find out is to try it.

[Next page](https://community.thunkable.com/t/url-encoding-string/1408899.md?page=2)
