如何使用 Notion 更新我的区块?我尝试按照有关如何更新 API 的说明进行操作,但失败了。即使使用requests.patch
,响应文本也不会改变。
这是代码:
import json, requests
import dotenv, os
def main():
dotenv.load_dotenv(dotenv.find_dotenv())
TOKEN = os.environ.get("TOKEN")
BLOCK_ID = os.environ.get("BLOCK_ID")
headers = {
"Authorization": "Bearer " + TOKEN,
"Notion-Version": "2021-08-16"
}
new_body = {
"paragraph": {
"text": [{
"text": {
"content": "bye bye"
}
}]
}
}
readurl = f"https://api.notion.com/v1/blocks/{BLOCK_ID}"
# res = requests.request("PATCH", readurl, headers=headers, data=json.dumps(new_body))
res = requests.patch(readurl, headers=headers, data=new_body)
print(res.status_code)
print(json.dumps(json.loads(res.text), indent=2))
if __name__ == "__main__":
main()
状态代码和文本是:
200
{
# other properties... then,
"paragraph": {
"text": [
{
"type": "text",
"text": {
"content": "hello there!",
"link": null
},
"annotations": {
"bold": true,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
},
"plain_text": "hello there!",
"href": null
}
]
}
}