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