Good afternoon, please help me fix the doGet code

601 views
Skip to first unread message

Avito Bot

unread,
Nov 2, 2023, 5:22:38 AM11/2/23
to Google Apps Script Community
Good afternoon, please help me fix the doGet code
https://script.google.com/macros/s/AKfycbzuXtq85SiH69pzNNoyWn-tRSLRGqm2JE5Cy5Bk7bO4gc39K7A3EkrNPvisAPQMvnWu/exec?word=%D0%90%D0%B1%D0%B0%D1%81

Exception: An error occurred when calling the openById method or property for the "SpreadsheetApp" object. (line 3, file code)

function doGet(e) {
  var wordToCheck = e.parameter.word;
  var spreadsheet = SpreadsheetApp.openById('1GPJMQT7NSrtbwdpq1bBj9xJdhb4i5-1nPkSENIsDeMI');
  var sheet = spreadsheet.getSheetByName('price');

  var data = sheet.getRange('A:A').getValues();
  for (var i = 0; i < data.length; i++) {
    if (data[i][0] === wordToCheck) {
      return ContentService.createTextOutput('1');
    }
  }

  return ContentService.createTextOutput('0');
}

Brett Grear

unread,
Nov 2, 2023, 6:54:18 AM11/2/23
to Google Apps Script Community
That usually means the Id doesn't exist or you don't have access to it.
How is the webapp executed? As you or the person using it?

Also, have you set the appscript.json manifest yourself or was it auto created? openById() required the /spreadsheets permission as opposed to the /spreadsheets.currentonly

Avito Bot

unread,
Nov 2, 2023, 6:59:48 AM11/2/23
to Google Apps Script Community
appscript.json no my

четверг, 2 ноября 2023 г. в 13:54:18 UTC+3, Brett Grear:

Brett Grear

unread,
Nov 2, 2023, 7:08:15 AM11/2/23
to google-apps-sc...@googlegroups.com
?
Kind regards,

Mr Grear
St Vincent's Primary School


--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/9j1QzTW0V74/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/ea749202-fd9f-42f9-981e-61efe063dc66n%40googlegroups.com.

Avito Bot

unread,
Nov 2, 2023, 12:25:00 PM11/2/23
to Google Apps Script Community
I didn't create this file appsscript.json

11.PNG
12.PNG

четверг, 2 ноября 2023 г. в 14:08:15 UTC+3, Brett Grear:

Avito Bot

unread,
Nov 2, 2023, 12:26:34 PM11/2/23
to Google Apps Script Community
I gave access, what else do I need to do?

четверг, 2 ноября 2023 г. в 13:54:18 UTC+3, Brett Grear:
That usually means the Id doesn't exist or you don't have access to it.

Brett Grear

unread,
Nov 2, 2023, 12:42:29 PM11/2/23
to Google Apps Script Community
The code you provided above is correct but when I opened your script the Id provided in openById() is 'AKfycbzuXtq85SiH69pzNNoyWn-tRSLRGqm2JE5Cy5Bk7bO4gc39K7A3EkrNPvisAPQMvnWu'
Try using as your code pasted originally says
'1GPJMQT7NSrtbwdpq1bBj9xJdhb4i5-1nPkSENIsDeMI' as the Id instead

Avito Bot

unread,
Nov 2, 2023, 1:14:31 PM11/2/23
to Google Apps Script Community
Так?
https://script.google.com/macros/s/1GPJMQT7NSrtbwdpq1bBj9xJdhb4i5-1nPkSENIsDeMI/exec?word=%D0%90%D0%B1%D0%B0%D1%81

13.PNG

четверг, 2 ноября 2023 г. в 19:42:29 UTC+3, Brett Grear:

Avito Bot

unread,
Nov 2, 2023, 1:21:59 PM11/2/23
to Google Apps Script Community
14.PNG

четверг, 2 ноября 2023 г. в 20:14:31 UTC+3, Avito Bot:

Brett Grear

unread,
Nov 2, 2023, 1:42:48 PM11/2/23
to Google Apps Script Community
I don't understand Russian but that is the id of the webapp. Not the Sheet.  SpreadsheetApp.openById() access a Spreadsheet, not a webapp.
Seeing as you've changed the code, you need to deploy a new version before the exec url will access the new code.

Click the drop down and select new version and give it a description.

Avito Bot

unread,
Nov 2, 2023, 2:25:02 PM11/2/23
to Google Apps Script Community
I selected a web application and gave access to everyone
16.png
15.PNG

четверг, 2 ноября 2023 г. в 20:42:48 UTC+3, Brett Grear:

Avito Bot

unread,
Nov 2, 2023, 2:31:17 PM11/2/23
to Google Apps Script Community
https://sheets.googleapis.com/v4/spreadsheets/1GPJMQT7NSrtbwdpq1bBj9xJdhb4i5-1nPkSENIsDeMI/values/exec?word=Абас?majorDimension=COLUMNS&key=API

{ "error": { "code": 400, "message": "Invalid JSON payload received. Unknown name \"word\": Cannot bind query parameter. Field 'word' could not be found in request message.", "status": "INVALID_ARGUMENT", "details": [ { "@type": "type.googleapis.com/google.rpc.BadRequest", "fieldViolations": [ { "description": "Invalid JSON payload received. Unknown name \"word\": Cannot bind query parameter. Field 'word' could not be found in request message." } ] } ] } }

четверг, 2 ноября 2023 г. в 21:25:02 UTC+3, Avito Bot:

Avito Bot

unread,
Nov 2, 2023, 2:33:29 PM11/2/23
to Google Apps Script Community
https://sheets.googleapis.com/v4/spreadsheets/1GPJMQT7NSrtbwdpq1bBj9xJdhb4i5-1nPkSENIsDeMI/values/price!A:A2?majorDimension=COLUMNS&key=API

{ "range": "price!A2:A40001", "majorDimension": "COLUMNS", "values": [ [ "МетПромИнтекс Екатеринбург", "MGP Metall", "VD.MARKET", "Абас", "АвиаПромСталь", "АНЭП-Металл Екатеринбург", "АО АМК-Групп" ] ] }

четверг, 2 ноября 2023 г. в 21:31:17 UTC+3, Avito Bot:

Avito Bot

unread,
Nov 2, 2023, 2:39:30 PM11/2/23
to Google Apps Script Community
function doGet(e) {
  var wordToCheck = e.parameter.word;
  var spreadsheet = SpreadsheetApp.openById('1GPJMQT7NSrtbwdpq1bBj9xJdhb4i5-1nPkSENIsDeMI');
  var sheet = spreadsheet.getSheetByName('price');

  var data = sheet.getRange('A:A2').getValues();

Avito Bot

unread,
Nov 2, 2023, 2:44:38 PM11/2/23
to Google Apps Script Community
17.PNG
18.PNG

четверг, 2 ноября 2023 г. в 21:39:30 UTC+3, Avito Bot:

Brett Grear

unread,
Nov 2, 2023, 3:08:03 PM11/2/23
to google-apps-sc...@googlegroups.com
What is it you are trying to do?

The webapp URL is from the deployment page, it starts script.google... and ends /exec?word=ABC

You don't need any other parameters or script properties

Avito Bot

unread,
Nov 2, 2023, 4:05:13 PM11/2/23
to Google Apps Script Community

Brett Grear

unread,
Nov 2, 2023, 4:18:08 PM11/2/23
to google-apps-sc...@googlegroups.com
What is the webapp supposed to do?

What does this mean? %D0%90%D0%B1%D0%B0%D1%81

What error are you getting?

That exec url looks correct

Avito Bot

unread,
Nov 2, 2023, 4:34:47 PM11/2/23
to Google Apps Script Community
When requesting, it should receive 1 in response, since the value ABC is available
And 0 if there is no value
But instead I get an error


Exception: An error occurred when calling the openById method or property for the "SpreadsheetApp" object. (line 3, file code)
четверг, 2 ноября 2023 г. в 23:18:08 UTC+3, Brett Grear:

Avito Bot

unread,
Nov 3, 2023, 4:14:09 AM11/3/23
to Google Apps Script Community
Good morning

четверг, 2 ноября 2023 г. в 23:18:08 UTC+3, Brett Grear:

Avito Bot

unread,
Nov 3, 2023, 12:03:02 PM11/3/23
to Google Apps Script Community
please help me

пятница, 3 ноября 2023 г. в 11:14:09 UTC+3, Avito Bot:

Avito Bot

unread,
Nov 4, 2023, 3:41:18 AM11/4/23
to Google Apps Script Community
Good morning

четверг, 2 ноября 2023 г. в 23:18:08 UTC+3, Brett Grear:

Avito Bot

unread,
Nov 4, 2023, 1:35:44 PM11/4/23
to Google Apps Script Community
good evening

четверг, 2 ноября 2023 г. в 23:18:08 UTC+3, Brett Grear:

Brett Grear

unread,
Nov 4, 2023, 1:54:32 PM11/4/23
to Google Apps Script Community
What is the final purpose of your web app? What are you trying to achieve?

Avito Bot

unread,
Nov 4, 2023, 3:18:11 PM11/4/23
to Google Apps Script Community
Send a GET request to Apps Script
/exec?word=Text test1
The script should check if there is a string with the value Text test1
If the written is present, Apps Script will answer 0
If the written is missing, Apps Script will add Text test1 to a new line and answer 1

суббота, 4 ноября 2023 г. в 20:54:32 UTC+3, Brett Grear:

Brett Grear

unread,
Nov 4, 2023, 6:42:17 PM11/4/23
to google-apps-sc...@googlegroups.com
No I mean why are you trying to do it

Avito Bot

unread,
Nov 5, 2023, 4:10:34 AM11/5/23
to Google Apps Script Community
I want to understand whether Google can accept data through a GET request and respond to me if such data is already available

воскресенье, 5 ноября 2023 г. в 01:42:17 UTC+3, Brett Grear:

Avito Bot

unread,
Nov 6, 2023, 4:33:29 AM11/6/23
to Google Apps Script Community
Good morning

воскресенье, 5 ноября 2023 г. в 01:42:17 UTC+3, Brett Grear:
No I mean why are you trying to do it

Andrew Apell

unread,
Nov 6, 2023, 9:29:42 AM11/6/23
to Google Apps Script Community
You do not need to keep posting "Good morning" and "Good evening" every day.
Your post will be seen and answered by those who can.

Avito Bot

unread,
Nov 6, 2023, 12:26:23 PM11/6/23
to Google Apps Script Community
Good evening OK
But so far no one has helped

понедельник, 6 ноября 2023 г. в 17:29:42 UTC+3, Andrew Apell:

Avito Bot

unread,
Nov 6, 2023, 1:29:25 PM11/6/23
to Google Apps Script Community
No one could help me for a week
And I found the solution myself
If you are interested, write and I will tell you how it was

Да ладно вот вам решение:
21.PNG

понедельник, 6 ноября 2023 г. в 20:26:23 UTC+3, Avito Bot:

Andrew Apell

unread,
Nov 6, 2023, 2:12:18 PM11/6/23
to Google Apps Script Community
Welcome to the club!
I have also posted questions here numerous times but ended up getting the answer myself. It is a common occurrence.

Avito Bot

unread,
Nov 6, 2023, 2:20:07 PM11/6/23
to Google Apps Script Community
Got angry and found a solution through AI
Thank you for pissing me off, otherwise I would have waited another week

понедельник, 6 ноября 2023 г. в 22:12:18 UTC+3, Andrew Apell:
Reply all
Reply to author
Forward
0 new messages