Google doc as rest api using Apps Script : xml
After a fight with wordpress, I said to myself: Can I use google doc as content management? .. Join me in this attempt
Configurations are equal to : https://medium.com/@jrichardsz.java/google-spreadsheet-as-api-rest-using-apps-script-756d13f8603d
Summarized steps
- create google doc
- add content as xml
- add an app script from tools
- copy and paste my code
- deploy
Create google doc
Just create a simple google doc with the following content:
Note the content, just have two parts:
- header with value : Welcome
- footer with value: made by JRichard
Text is available in this link: https://gist.githubusercontent.com/jrichardsz/b347036f14e8ad76abd5de7bbe8e92c1/raw/500b902816691ac8889ac172444a4510718171c9/sample%2520content.txt
Add an app script
In google doc, click on : Tools menu and select Script Editor
Paste this code
Just replace the url and token with your values!!
Deploy
- Save the script
- Scrip needs authorizations. To prompt them, click on “run” option and select testDoGetFindAll function. Accept the requested permissions.
- Go to view >> logs and review the success response
- If there is another response with error. Review the previous steps. If response is success, continue the steps!
- Click “Publish” in the Google Apps Script Menu
- Select “Deploy as web app”
- In Project version, select new
- In Who has access to the app select Anyone, even anonymous.
- Click on deploy or update
- An url will prompt you something like:
https://script.google.com/macros/s/AKfy***SdqWNw_g/exec
- Save it, this is the url of you new rest api!!
FindAll Test
Just perform a simple get invocation sending these parameters
- token = miaouhhh
- operation = findAll
You could see the entire google doc content as json ready to use in any javascript application
FindById Test
Just perform a simple get invocation sending these parameters
- token = miaouhhh
- operation = findById
- id = header
You could see the just the header section of your google doc content as json ready to use in any javascript application