Created
May 27, 2022 13:32
-
-
Save takasek/5fac61a307de49ec6c40a9e74f014be5 to your computer and use it in GitHub Desktop.
Notion API で、databaseの "Done" がついてるかどうかを見て "Name" の頭に "■" をつけたり消したりする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doGet() { | |
const notion_token = 'secret_...'; | |
const database_id = '...'; | |
const headers = { | |
'Content-Type' : 'application/json; charset=UTF-8', | |
'Authorization': `Bearer ${notion_token}`, | |
'Notion-Version': '2021-05-13', | |
}; | |
const fetched = UrlFetchApp.fetch(`https://api.notion.com/v1/databases/${database_id}/query`, { | |
"method" : "post", | |
"headers" : headers, | |
}); | |
const json = JSON.parse(fetched.toString()); | |
for (x of json.results) { | |
var id = x.id; | |
var is_done = x.properties.Done.checkbox; | |
var name = x.properties.Name.title[0].text.content; | |
var name_without_square = name.match(/(■?)(.+)/)[2]; | |
var name2 = (is_done ? "■" : "") + name_without_square; | |
if (name != name2) { | |
UrlFetchApp.fetch(`https://api.notion.com/v1/pages/${id}`, { | |
"method" : "patch", | |
"headers" : headers, | |
"payload" : JSON.stringify({ | |
'properties': { | |
'Name': { | |
'title': [{ | |
'text': { 'content': name2 } | |
}] | |
} | |
} | |
}) | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment