Include or exclude respondents


Here is how to use R to include or exclude a respondent from analysis:

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

actionRespondent <- function(experiment_id, participant_id, action = c("include", "exclude"), TOKEN = CONJOINTLY_TOKEN) {
  library(httr)
  library(jsonlite)

  experiment_id <- as.numeric(experiment_id)
  participant_id <- as.numeric(participant_id)
  action <- match.arg(action)

  headers <- add_headers(
    `Authorization` = paste("Bearer", TOKEN),
    `Content-Type` = "application/json",
    `Accept` = "application/json",
    `X-Requested-With` = "XMLHttpRequest"
  )

  POST(
    sprintf("https://api.conjoint.ly/api/experiments/%s/participants/%s/%s", experiment_id, participant_id, action),
    headers,
    body = toJSON(list(
      command = action,
      participantId = participant_id
    ))
  )

  return(participant_id)
}

includeRespondent <- function(experiment_id, participant_id, TOKEN = CONJOINTLY_TOKEN) {
  actionRespondent(experiment_id, participant_id, "include", TOKEN)
}

excludeRespondent <- function(experiment_id, participant_id, TOKEN = CONJOINTLY_TOKEN) {
  actionRespondent(experiment_id, participant_id, "exclude", TOKEN)
}

includeRespondent(1234, 12345)
excludeRespondent(1234, 12345)