R/get_product_metadata.R

Defines functions get_product_metadata

Documented in get_product_metadata

#' Download StatsCan Metadata from Product Cube
#'
#' This function allows you to download product metadata from
#' Statistics Canada.
#' @param productId The Statistics Canada Product ID.
#' @keywords productId, product, metadata
#' @importFrom httr POST content content_type
#' @export
#' @examples
#' get_product_metadata('14100287')
#'
get_product_metadata <- function(productId) {
  url <- 'https://www150.statcan.gc.ca/t1/wds/rest/getCubeMetadata'

  req <- POST(
    url,
    content_type('application/json'),
    body = toJSON(data.frame(productId = as.numeric(productId)))
  )

  response <- content(req)[[1]]

  if (response$status == "SUCCESS") {
    return(response$object)
  } else {
    print('ERROR')
  }
}
andrewjdyck/statscanr documentation built on Aug. 11, 2019, 2:38 a.m.