A Node.js API that integrates with Google Sheets and Google Drive to manage medication data and orders.
- Google Sheets Integration
- Google Drive Integration
- OAuth2 Authentication
- Medication Data Management
- Order Management
- Folder Structure Management
- Node.js (v14 or higher)
- Google Cloud Platform Account
- OAuth2 Credentials
- Clone the repository:
git clone https://github.com/ADIMYY/Google_Script.git
cd Google_Script
- Install dependencies:
npm install
- Create a
config.env
file in the root directory with the following variables:
CLIENT_ID=your_client_id
CLIENT_SECRET=your_client_secret
REDIRECT_URI=your_redirect_uri
REFRESH_TOKEN=your_refresh_token
PORT=3000
GET /auth
- Initiates OAuth2 authentication flowGET /oauth2callback
- OAuth2 callback endpoint
-
POST /api
with action:createsheet
- Create a new sheetcreateordersheet
- Create a new order sheetdeletesheet
- Delete a sheetstoremedication
- Store medication dataupdatemedication
- Update medication datastoreorder
- Store order data
-
GET /api
with action:listsheets
- List all sheetsretrieve
- Retrieve medication datalistordersheets
- List order sheets
The API creates and manages the following folder structure in Google Drive:
NAQQAS/
├── SHEETS_FOLDER/
│ └── [user_email]/
└── ORDER_FOLDER/
└── [user_email]/
- Start the server:
node app.js
- Visit
http://localhost:3000/auth
to authenticate with Google - After authentication, you can use the API endpoints to manage your sheets and data
- Start the server:
node app.js
- Visit
http://localhost:3000/auth
to authenticate with Google
This project is configured for easy deployment on Vercel:
- Create a Vercel account at vercel.com if you don't have one
- Install the Vercel CLI:
npm install -g vercel
- Deploy to Vercel:
vercel
-
Set up environment variables in the Vercel dashboard:
- Go to your project settings
- Navigate to the "Environment Variables" section
- Add the following variables:
CLIENT_ID
CLIENT_SECRET
REDIRECT_URI
(set this to your Vercel deployment URL +/oauth2callback
)REFRESH_TOKEN
-
Update your Google Cloud Console OAuth 2.0 configuration:
- Add your Vercel deployment URL to the authorized redirect URIs
- Add your Vercel deployment URL to the authorized JavaScript origins
The API includes comprehensive error handling for:
- Authentication failures
- Missing required fields
- Sheet access issues
- Invalid actions
- Token refresh failures
- OAuth2 authentication
- Environment variable configuration
- Secure token management
- User-specific folder access
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request