React-Google-Apps-Script icon indicating copy to clipboard operation
React-Google-Apps-Script copied to clipboard

Getting 400 error while using serverFunctions

Open FearTheBeard95 opened this issue 2 years ago • 4 comments

Hi, I'm trying to call a custom GAS function using the serverFunctions, but I'm getting a 400 response error from google sheets

FearTheBeard95 avatar Aug 08 '23 10:08 FearTheBeard95

Does it work with a fresh clone with no modifications?

enuchi avatar Aug 08 '23 15:08 enuchi

Does it work with a fresh clone with no modifications?

The function actually works when I pass in different parameters but certain parameters cause the 400 response. i also just realised that when it fails the function does get called at all but throws the error.

FearTheBeard95 avatar Aug 09 '23 07:08 FearTheBeard95

Please provide details when you open an issue. Throwing a 400 is not enough information to help. What parameters did you use? What is your function doing? Start with the base example here -- if it works for you then make small adjustments to it to narrow down what is happening.

Note Google only allows certain types of parameters to be used when calling server side functions from the client. Basically only primitives like string, number, object comprised of those.

enuchi avatar Aug 09 '23 12:08 enuchi

https://developers.google.com/apps-script/guides/html/communication#parameters_and_return_values

Legal parameters and return values are JavaScript primitives like a Number, Boolean, String, or null, as well as JavaScript objects and arrays that are composed of primitives, objects and arrays. A form element within the page is also legal as a parameter, but it must be the function’s only parameter, and it is not legal as a return value. Requests fail if you attempt to pass a Date, Function, DOM element besides a form, or other prohibited type, including prohibited types inside objects or arrays. Objects that create circular references will also fail, and undefined fields within arrays become null.

Note that an object passed to the server becomes a copy of the original. If a server function receives an object and changes its properties, the properties on the client are not affected.

enuchi avatar Aug 09 '23 12:08 enuchi