# How can I POST a value to google sheets using Google App Script?

**URL:** <https://community.thunkable.com/t/how-can-i-post-a-value-to-google-sheets-using-google-app-script/2026992>\
**Category:** Web API's\
**Tags:** webapi, javascript, lowcode, google-app-script\
**Created:** [September 4, 2022, 6:46am UTC](https://community.thunkable.com/t/how-can-i-post-a-value-to-google-sheets-using-google-app-script/2026992 "2022-09-04T06:46:46Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![bibbi](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@bibbi](https://community.thunkable.com/u/bibbi)\
**Post date:** [September 4, 2022, 6:46am UTC](https://community.thunkable.com/t/how-can-i-post-a-value-to-google-sheets-using-google-app-script/2026992/1 "2022-09-04T06:46:46Z")

</div>

hi

I manage to post numerical data with the post block but not the character strings how should I proceed I am still looking

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [September 4, 2022, 7:03am UTC](https://community.thunkable.com/t/how-can-i-post-a-value-to-google-sheets-using-google-app-script/2026992/2 "2022-09-04T07:03:01Z")

</div>

Share more details…

---

<div class="post-metadata">

**Author:** ![bibbi](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@bibbi](https://community.thunkable.com/u/bibbi)\
**Post date:** [September 4, 2022, 7:21am UTC](https://community.thunkable.com/t/how-can-i-post-a-value-to-google-sheets-using-google-app-script/2026992/3 "2022-09-04T07:21:00Z")

</div>

hi

until now i sent numerical data in google sheets and it worked  
I want to send text and it’s not working anymore  
it’s a question of form I think but I haven’t found it yet

here are the blocks :

![Capture d’écran 2022-09-04 à 09.17.27](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/a/5acd48fb8c97637f5399334ed7a97dde98e1c028.png)

---

<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:** [September 4, 2022, 7:37am UTC](https://community.thunkable.com/t/how-can-i-post-a-value-to-google-sheets-using-google-app-script/2026992/4 "2022-09-04T07:37:59Z")

</div>

The `Query Parameters` for GAS (Google Apps Script) only accepts US-ASCII and your text has **ë** which is considered as an unsafe character.

You need to URL encode it.

**[Edit]**  
Type this in the text and it should update the sheet correctly  
**Ma%C3%ABva**

---

<div class="post-metadata">

**Author:** ![bibbi](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@bibbi](https://community.thunkable.com/u/bibbi)\
**Post date:** [September 4, 2022, 8:00am UTC](https://community.thunkable.com/t/how-can-i-post-a-value-to-google-sheets-using-google-app-script/2026992/5 "2022-09-04T08:00:22Z")

</div>

hi

I tried that before asking without success.

 ![Capture d’écran 2022-09-04 à 09.55.20](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/d/0de0e0f89b738bc434e2cc8f5b3c050c6fae09e5.png)

thank you for your support but I can’t see myself doing this for each first name or text 🙂

---

<div class="post-metadata">

**Author:** ![bibbi](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@bibbi](https://community.thunkable.com/u/bibbi)\
**Post date:** [September 4, 2022, 10:12am UTC](https://community.thunkable.com/t/how-can-i-post-a-value-to-google-sheets-using-google-app-script/2026992/6 "2022-09-04T10:12:37Z")

</div>

hi

I went through different posts and I found this one attended by a certain API Master Muneer 🙂

[https://community.thunkable.com/t/solved-can-you-help-me-make-a-post-to-shelly-using-x-www-form-urlencoded-calls/1890678](https://community.thunkable.com/t/solved-can-you-help-me-make-a-post-to-shelly-using-x-www-form-urlencoded-calls/1890678)

that seemed to correspond to what I wanted to do well it saves in the spreadsheet only the first parameter  
while when I try my script live I can write what I want numbers accented words or not

I’m still looking for a solution

---

<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:** [September 4, 2022, 10:44am UTC](https://community.thunkable.com/t/how-can-i-post-a-value-to-google-sheets-using-google-app-script/2026992/7 "2022-09-04T10:44:22Z")

</div>

You are using GAS (Google Apps Scrip) which has to ways to write to the sheet

- doGet()
- doPost()

When using **doGet()**, you have to pass the parameters as part of the URL (Query Parameters) and therefore you need to convert them to a form accepted by the URL scheme. This is the reason why you have to change the text to URLEncoded text.

However, when you use **doPost()** you will pass the data using the Body block and therefore you can use all type of text and numbers.

You can pass a JSON formatted data in text form using the Body component and in the Google script side read the text and convert it using JSON.parse() to use it as an object and update the sheet.

See a post using **doPost()**.

> [@Save Canvas Image to your Google drive](https://community.thunkable.com/t/save-canvas-image-to-your-google-drive/1609950):
>
> For this tutorial you will need to code a short script in Google Apps Script which you can access it from within Google Drive. You will need to use Web API component to talk to the script you created in Google Apps Script and pass the parameters using the Query Parameter section the the Body section. The Base64 image cannot fit into the Query Parameter section and therefore will will need to pass it using the Body section of the Web API. The Thunkable project is very simple and is used to demo…

---

<div class="post-metadata">

**Author:** ![bibbi](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@bibbi](https://community.thunkable.com/u/bibbi)\
**Post date:** [September 4, 2022, 1:46pm UTC](https://community.thunkable.com/t/how-can-i-post-a-value-to-google-sheets-using-google-app-script/2026992/9 "2022-09-04T13:46:38Z")

</div>

hi

so far i was consuming json i had saved in sheets or firebase  
it gets stuck

I’m trying to send a simple json string

 ![Capture d’écran 2022-09-04 à 15.42.18](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/e/9ed0a8fcdb1efe1f264f848d0a28b1c9fcacf049.jpeg)

and I want the script to send it back to me and even that doesn’t work

 ![Capture d’écran 2022-09-04 à 15.45.13](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/2/82f2b84ad17bb5d357879f8761600a68588d88be.png)

![Capture d’écran 2022-09-04 à 15.32.06](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/4/64ea8a79ef1c7ca16d4e24159a30179bbb86b5a4.png)

---

<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:** [September 4, 2022, 2:05pm UTC](https://community.thunkable.com/t/how-can-i-post-a-value-to-google-sheets-using-google-app-script/2026992/10 "2022-09-04T14:05:14Z")

</div>

You are using the `ContentService` to return **text** but `var j` is a JSON object not a text. If you want text to be return then you do not need to convert the **e.postData.contents**

The **Failed to fetch data** message requires to run the API from your phone not from the computer.

Follwoing is the easiest way to post data to Google sheet.

```auto
function doGet(e) {  
	Sheets.Spreadsheets.Values.append({"majorDimension":"ROWS","values": [[e.parameter.name ,e.parameter.age]]},
	[[Google Sheet ID]],
	 [[Sheet name]] + "!A:A",
	{valueInputOption:"USER_ENTERED"});
	return ContentService.createTextOutput("Updated");
}

```

The sheet needs to be **Shared** for this to work. Please note that I used **name** and **age** from your code. You can use the proper parameter names.

If your **script** is already inside the Google sheet then you can use the following:

```auto
function doGet(e) {  
	Sheets.Spreadsheets.Values.append({"majorDimension":"ROWS","values": [[e.parameter.name, e.parameter.age]]},
	SpreadsheetApp.getActiveSpreadsheet().getId(),
	SpreadsheetApp.getActiveSpreadsheet().getSheets()[0].getSheetName() + "!A:A",
	{valueInputOption:"USER_ENTERED"});
	return ContentService.createTextOutput("Updated");
}

```

This will add the values to the first sheet in the Google sheet file.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/f/0f59f292712368bce16ff80133ae10de8a6f27e8.png) [@system](https://community.thunkable.com/u/system)\
**Post date:** [December 3, 2022, 2:05pm UTC](https://community.thunkable.com/t/how-can-i-post-a-value-to-google-sheets-using-google-app-script/2026992/11 "2022-12-03T14:05:44Z")

</div>

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