enuchi / React-Google-Apps-Script

This is your boilerplate project for developing React apps inside Google Sheets, Docs, Forms and Slides projects. It's perfect for personal projects and for publishing complex add-ons in the Google Workspace Marketplace.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting 400 error while using serverFunctions

FearTheBeard95 opened this issue · 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

Does it work with a fresh clone with no modifications?

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.

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.

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.