FormatException: Unexpected character (at character 1)
1,349
Issue:
doGet
is throwing a reference error because spreadsheetApp
is not defined: that's a typo; should be SpreadsheetApp instead, first letter capitalised.
Because of this, the request to the web app is returning an error page instead of the text output you expected.
You can check that's what's going on if you try to access the script URL with your browser.
Solution:
Fix the typo and open the spreadsheet this way instead:
var sheet = SpreadsheetApp.openById("1UWt6IVRcebqErf4mjURKAY-_oC7dBMtbOx1CQ8cfW0Q");
Reference:
Author by
Mir Faisal
Updated on December 21, 2022Comments
-
Mir Faisal over 1 year
i am making sheet in flutter, in which people will enter all the information and that information will be passed to google sheet. but when i try to pass the data, i recieve the following error :
I/flutter (23770): FormatException: Unexpected character (at character 1) I/flutter (23770): <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.co... I/flutter (23770): ^
My API call code is following:
import 'package:fooddeliveryapp/model/Customer_Information.dart'; import 'package:http/http.dart' as http; import 'dart:convert' as convert; class InformationController { final void Function(String) callback; static const String URL = "https://script.google.com/macros/s/AKfycbxuNeIu5cibZHs9sXM6vsl-X5Cf7muMP18xRiDCRXNDF--z0y8o/exec"; static const STATUS_SUCCESS = "SUCCESS"; InformationController(this.callback); void submitCustomerInformation( CustomerInformation customerInformation) async { try { await http.get(URL + customerInformation.toParams()).then((response) { callback(convert.jsonDecode(response.body)['Status']); }); } catch (e) { print(e); } } }
Following is my spreadsheet script editor code:
function doGet(request) { var sheet=spreadsheetApp.openById("1UWt6IVRcebqErf4mjURKAY-_oC7dBMtbOx1CQ8cfW0Q"); var result={"status": "SUCCESS"}; try{ var Name=request.parameter.Name; var PhoneNumber=request.parameter.PhoneNumber; var Address=request.parameter.Address; var rowData=sheet.appendRow([Name,PhoneNumber,Address]); }catch(exc){ result={"Status":"FAILED","message":exc}; } return ContentService .createTextOutput(JSON.stringify(result)) .setMimeType(ContentService.MimeType.JSON); }
help will be appreciated, thankyou!!
-
500 - Internal Server Error almost 4 yearsYou're getting an HTML response, not JSON - probably an error message page.
-
Mir Faisal almost 4 years@500-InternalServerError how to solve it?
-
Iamblichus almost 4 yearsIs the web app your trying to access public? If not, are you providing credentials to access it?
-
Mir Faisal almost 4 years@lamblichus, i am making an app which will send info to a spreadsheet.
-
Jagadish about 3 yearsDid you solve the problem??
-
-
Jagadish about 3 yearsI have already S capital but still getting this error.
-
Iamblichus about 3 years@Jagadish If this is a web app, make sure you deploy it again after making any change.
-
Jagadish about 3 yearsshould i make anew deployment again opr just deploy the same again in manage deplayoments? i tried to deploy again same one after clicking on manage deployments but it showed the web app requires authorization...nd when i cliked authorize it showed to sign and when i signed it showed up a warning page that google hasnt verified the app yet
-
Jagadish about 3 yearswhat to do? how to deploy again?
-
Iamblichus about 3 years@Jagadish
it showed up a warning page that google hasnt verified the app yet
Can't you just clickAdvanced
and continue anyway?