notion_client/endpoints/pages/
update.rs1pub mod request;
2
3use crate::{
4 endpoints::NOTION_URI,
5 objects::{page::Page, Response},
6 NotionClientError,
7};
8
9use self::request::UpdatePagePropertiesRequest;
10
11use super::PagesEndpoint;
12
13impl PagesEndpoint {
14 pub async fn update_page_properties(
15 &self,
16 page_id: &str,
17 request: UpdatePagePropertiesRequest,
18 ) -> Result<Page, NotionClientError> {
19 let json = serde_json::to_string(&request)
20 .map_err(|e| NotionClientError::FailedToSerialize { source: e })?;
21
22 let result = self
23 .client
24 .patch(format!(
25 "{notion_uri}/pages/{page_id}",
26 notion_uri = NOTION_URI,
27 page_id = page_id
28 ))
29 .body(json)
30 .send()
31 .await
32 .map_err(|e| NotionClientError::FailedToRequest { source: e })?;
33
34 let body = result
35 .text()
36 .await
37 .map_err(|e| NotionClientError::FailedToText { source: e })?;
38
39 let response = serde_json::from_str(&body)
40 .map_err(|e| NotionClientError::FailedToDeserialize { source: e, body })?;
41
42 match response {
43 Response::Success(r) => Ok(r),
44 Response::Error(e) => Err(NotionClientError::InvalidStatusCode { error: e }),
45 }
46 }
47}