I need help with patching a value to a cell in a Google Sheet tab using a web API

Hi there!

I need to patch a value to a cell in a Google Sheet tab using a web API.
My Google Sheet is open to everyone with the elink
Created API ID. Active
Create OAuth. Set up as per Google recommendations.
etc

But always getting error 404.

I spent days on that, but obviously I misunderstand something.

Can someone help me with that? Thanks in advance

Hi wwinfried5p, welcome to Thunkable! :tada:

Be sure to check out How to ask Great Questions v2.0, the Community Guidelines, and our Getting Started Guide to make the best of your Thunkable Community experience!

Are you testing the API call on the web preview? If so, the 404 error might just be a CORS issue. CORS can prevent a web API from working on some devices or browsers.

You can check your browser console to see if this is the case. If so, you’ll see an error like this:

“Access to fetch at [URL] from origin ‘https://x.thunkable.com’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.”

You can find more information here: CORS Policy | Thunkable Docs

Hi Matt,

Many thanks for your very instructive answer. I read a lot the Community guidelines and the help files and I try my best to decrypt the browser console indeed. But I admit that I did zoom on the CORS topic. I will now and I will investigate even more to find a way to make my web API “patch” work. Maybe using:
Headers:
{
“X-HTTP-Method-Override”: “PATCH”,
“Authorization”: “Bearer {my access token}”
}

I’ll be back soon if I need more guidance.

Best,

Winfried, Geneva

Hello @wwinfried5p
As we said in a separate support channel, it would be easier to use data sources blocks to build this feature.

You can find more information about connecting a Google sheet and data sources blocks in our docs: Google Sheets Data Source | Thunkable Docs

Data Sources Blocks | Thunkable Docs

Hi Ioannis,

Thanks for the follow-up.

I understand that it would be easier to use Data Source Blocks, and that’s what I did in V1 of my project. But that meant recoding all my Data Source blocks every time I started a new client. So I switched to v2 with web APIs.

The advantage of web APIs is precisely the flexibility of working with variables. Web APIs are very easy to use with the GET method, but I’m finding that it’s quite complex to make a patch and a post it works. And that’s because I’m a novice web API geek. But I’ve got to get it right.

I’m working on a very big Android and iOS application project designed to collect visit reports from salespeople in distributors all over the world. Each corporate client will have access to Google sheets to set up the application’s data. Each distributor and distributor salesperson will be able to connect to brands via web APIs, to read information, and to send information to the brand’s Google sheet.

I’ve been working on this app 24/7 since July. I like Thunkable. Now I just need to find the trick that will allow me to patch or post data via a web API, and improve the app’s flow through the Google developers console.

I could probably use a specialist to spend an hour or two online with me to help me. Benevolently or not. It doesn’t really matter. The important thing is that he’s a specialist in web APIs, the Google API console and Google OAuth.

Best regards,

Winfried Windegger
WWINDER Sales Consulting SARL

Geneva.

Hello @wwinfried5p
Thank you for sharing more information.
This is something out of Thunkable but I did some research and found this:

curl --request POST
‘https://sheets.googleapis.com/v4/spreadsheets/[SPREADSHEETID]/values:batchClear?key=[YOUR_API_KEY]’
–header ‘Authorization: Bearer [YOUR_ACCESS_TOKEN]’
–header ‘Accept: application/json’
–header ‘Content-Type: application/json’
–data ‘{}’
–compressed

Have you tried this POST request?

Hello Ioannis,

Thank you so much for paying attention to my request. Thanks to you I’m discovering another way of doing things.
I modified my code to test, but I still get the same error:
{
“error": {
“code": 403,
“message": ”Method doesn’t allow unregistered callers (callers without established identity). Please use API Key or other form of API consumer identity to call this API.”,
“status": ”PERMISSION_DENIED”
}
}

I’m 99% sure that my header is correct. So is my body.
I deduce that the error must have come from the configuration of my API and my OAuth.

Does that make sense?

Hello @wwinfried5p ,
I talked with our engineers and said that a Google sheet token is created when adding a new data source to make the blocks work.
To make the web api blocks you would need to get the access token using a block.
Similar to what we have for Airtable: Airtable’s API keys will be deprecated by Airtable - Announcements - Community (thunkable.com)
Unfortunately, this feature is not available, at the moment, but it is a good suggestion!
I passed it on to the team.

Hello Ioannis,

Sorry for the delay in getting back to you.

Good news: I found the solution yesterday. Let me summarize.

After spending days consulting the posts on the community, and on Stack Overflow,
after configuring Google API and Google OAuth correctly, including permissions of course,
after correctly sharing my Google sheet,
I tried unsuccessfully to use call web API POST, PUT and PATCH for many long days.

I then concentrated on creating a Google Apps Script to manage my POSTs properly.
Looking at the Google Apps Script logs, I was very surprised to see that Google Apps Script was telling me that my “doGet” wasn’t working, even though I was calling a doPost.
(same problem with doPatch). That is is really strange!

I continued my research and managed to configure a doGET.gs that handles 4 functions:
getData, addData, updateData and deleteData.

I’m in the process of finalizing the pages of my app that send data to my clients’ Google sheets. Everything’s working fine. At last!

Like I said. I’m a beginner with Thunkable, Google API and Google OAuth. But I’m a fast learner :slight_smile:

Thank you for not giving up.

Best,

Winfried

1 Like