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 403 error while using serverFunctions

ramkumar2098 opened this issue · comments

Basically, when I tried to call serverFunctions.getSheetId(), it is automatically hitting this endpoint: https://docs.google.com/a/macros/google.com/d/{scriptId}/callback with request: "[\"getSheetId\",\"[]\",null,[0],null,null,true,0]" as formdata.

And these are query params for the given URL:
nocache_id = 15
csid = 205ff006bfccf346
mid = ACjPJvF7r3BdwrPIuUsNLNUmzaziSPkRoIUIXIlvi8-zRHi4pYeDB_mp9OJNgm1hgZVPjJe3htp3z89CugHCKehFcwzxN_2pqVyetzzc5mzJSfomGi4
mctx = {"gid":"849385243","scol":2,"ecol":3,"srow":2,"erow":3,"sel":{"1":{"1":"849385243","2":2,"3":2},"2":[{"1":"849385243","2":2,"3":3,"4":2,"5":3}],"5":0}}
eei = ACZUsOc_cGs0P5IvPTwSCHL1Y2k5PNkfzS-SQEtpx4xHqxULyzbD392uh8TxxEaGCHq7AWXcPUCS24OJHzYDZ8cp48jj8QzDMWxPijzSKPUIZIW9rSlunXr9XZD9vnCYbjDhMWzXyA3PM2akIrKBQDii02LrCahbrcGq6o2UqR3DMYE0Bmlb8HrTJltLff1x6BqVIXvQZpqImBVqMj6JvPAbDnCekUsRmA
token = AJuLMu1UcJ-P1Rm4b1OnNbcJJ4H3efamNQ:1678208014086

This "403 Forbidden" error happens only once in a while. I am not sure how to fix this since this api is getting called automatically.

Not sure. If it is only happening periodically it may be google's API being down. You should be able to catch it and handle it though.

But if the google's API is down, how are they throwing 403 error? Can you also tell me how this API call is being made? Is there any documentation for it?

serverFunctions here is just a wrapper around google.script.run which is what Google exposes on the client to execute server functions. You can read more at link below. Under the hood it is generating that API request but you will not have direct access to it. You should be able to catch that error using a catch block on the client.

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

@enuchi I have discovered that this 403 error happens because the token in the query param expires every 30 minutes. After that the serverFunction keeps using the same token. Is there a way to make serverFunction update itself to use a new token or maybe change the token expiration time?

I very much doubt it, as the auth mechanism is handled behind the scenes by google's design. Does it refresh if you just close and reopen the dialog?

Yes it only refreshes when i reopen the sidebar. But I need to it refresh without doing so.

serverFunctions here is just a wrapper around google.script.run which is what Google exposes on the client to execute server functions. You can read more at link below. Under the hood it is generating that API request but you will not have direct access to it. You should be able to catch that error using a catch block on the client.

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

I can catch that error; however, I'm unable to make any serverFunctions call since the token has expired.

I don't think there's a way to refresh it. You can catch the error and show a message to the user telling them to re-open the modal/sidebar.

Okay, don't close the issue now. Someone might post any solution/suggestion in this thread.