R/updateText.R

Defines functions updateText

Documented in updateText

#' Updates a Text Property
#'
#' Id refers to a page in a database, and should be normalized using normalizeChromeId().
#'
#' @param secret API token
#' @param id Page id to be updated
#' @param property_name name of property to update (should be a text type property)
#' @param value value to update
#'
#' @importFrom httr PATCH
#' @export
updateText <- function(secret, id, property_name, value){

  payload  <- sprintf(
    "{\"properties\":{\"%s\":{\"rich_text\":[{\"type\":\"text\",\"text\":{\"content\": \"%s\"}}]}}}",
    property_name, value
  )

  auth_secret <- paste0("Bearer ", secret)

  headers = c(
    `Authorization` = auth_secret,
    `Notion-Version` = '2022-02-22',
    `Content-Type` = 'application/json' )

  res <- httr::PATCH(url = paste0('https://api.notion.com/v1/pages/', id),
                     httr::add_headers(.headers = headers),
                     body = payload,
                     encode = "json")
  d <- httr::content(res)
  return(d)
}
Eflores89/notionR documentation built on Feb. 8, 2025, 10:25 a.m.