1

I have a website that needs a JSON file to display a sort of timetable that's hosted on GitHub pages. People who do not know what javascript or GitHub are need to be able to change that JSON file each week.

To solve this I've created a website that reads data from a google sheet they can edit, and turns it into a js object at the click of a button. I now just need to get this object from the website into the JSON file on the first GitHub repo, but I have no clue how to do this. I know you can use the GitHub API somehow, but how??

P.s. I know making the token built into the website is a security risk which is why I plan to only put tokens in the google sheet, which requires the user to authenticate a google account before being accessed.

  • 3
    I would suggest not using github to store user data? – evolutionxbox Dec 12 '22 at 18:00
  • 1
    Did you consult the API documentation [Create or update file contents](https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28#create-or-update-file-contents)? – jsejcksn Dec 12 '22 at 18:16
  • @evolutionxbox that would definitely be the best move but I can't find anything that I can "store" the data in that can be read to and written to. I need a thing that you can store data from a website A on, and then read that data from a different website B. Would you know anything I could use? – Hallojvjknvve Dec 12 '22 at 18:33
  • @jsejcksn Thanks, that seems like it should work but could you please tell me what the auth-token would be in this case? – Hallojvjknvve Dec 12 '22 at 18:52
  • 1
    [^](https://stackoverflow.com/questions/74775379/how-to-commit-to-a-github-repo-from-a-website-in-browser-using-javascript#comment131968914_74775379) @Hallojvjknvve What do you find when you search for "token" in the documentation I linked you to? Being a good programmer is being a good researcher. – jsejcksn Dec 12 '22 at 18:54
  • @jsejcksn oh, I'm blind ty. But now it's just giving an error of `Uncaught (in promise) ReferenceError: Octokit is not defined` even thought I've added `import { Octokit } from "https://cdn.skypack.dev/@octokit/core";` to a script tag as specified by the github? When I add it to the script.js file, one function that handles the button click (i.e. does everything) isn't defined – Hallojvjknvve Dec 12 '22 at 19:23

0 Answers0