Get a list of experiments


Here is how to use R to list experiments on Conjointly:

CONJOINTLY_TOKEN <- "YOUR_TOKEN" # Get a token from https://run.conjoint.ly/utilities/tokens

listExperiments <- function(count = 20, TOKEN = CONJOINTLY_TOKEN) {
  library(httr)
  library(jsonlite)
  library(data.table)
  
  count <- as.integer(count)
  
  headers <- add_headers(
    `Authorization` = paste("Bearer", TOKEN),
    `Content-Type` = "application/json",
    `Accept` = "application/json",
    `X-Requested-With` = "XMLHttpRequest"
  )
  
  result <- GET(
    paste0("https://api.conjoint.ly/api/experiments?paginate=", count),
    headers
  ) |> content("parsed", encoding = "UTF-8")

  experiments <- do.call(rbind, result$data) |> data.table()
  for (i in colnames(experiments)) {
    experiments[[i]][sapply(experiments[[i]], is.null)] <- NA
    experiments[[i]] <- unlist(experiments[[i]])
  }
  experiments
}

experiments <- listExperiments(20)