Skip to content

Instantly share code, notes, and snippets.

@letswritetw
Created July 14, 2023 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save letswritetw/18c6004367ab827cfc08fe3b207c97a6 to your computer and use it in GitHub Desktop.
Save letswritetw/18c6004367ab827cfc08fe3b207c97a6 to your computer and use it in GitHub Desktop.
gas-backup-postman-collections
// 存進雲端
function saveJsonToDrive({ name, json }) {
const today = getToday({ divider: '-' });
const folderName = name; // 資料夾名稱
const time = new Date().getTime();
const fileName = `${time}_backup.json`; // 檔案名稱
// 取得「備份」資料夾
const folder = DriveApp.getFoldersByName(folderName).next();
// 在「備份」資料夾中建立 JSON 檔案
const file = folder.createFile(fileName, JSON.stringify(json));
}
// 取得 Postman 的 collection 資料
function getPostmanCollection({ name, uri }) {
const response = UrlFetchApp.fetch(uri);
const content = response.getContentText();
const json = JSON.parse(content);
saveJsonToDrive({ name, json })
}
// 要備份的 Postman Collections
const uri = [
{
name: '資料夾名稱',
uri: '從 Postman 取得的 URL'
}
];
// 進行自動備份
function autoBackup() {
uri.forEach(u => {
getPostmanCollection({ name: u.name, uri: u.uri })
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment