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.
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.â
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 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.
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.
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.
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