Contact Search API in R | XM Community
Skip to main content

Hi all,

Referencing api.qualtrics.com/c79e78a949572-search-directory-contacts, I had ChatGPT help me create a script to search my Directory for emails that equal “test@test.ca”. I already know that there are over 12,000 of these.

Using the black windows on the page above, I am able to (a) change the pageSize and return fewer records (and different skipTokens) and (b) use the new skipToken to retrieve different records.

In my code, if I put the pageSize in the url I can modify the pageSize and return fewer records. If I put the pageSize into the body of the request nothing happens, I always get 100 records. For skipToken, I can never get it to work - I always get the same 100 records and the same skipToken returned. Can anyone help?

I know this is code-specific to R 😞 If you have another way to use the API (secure and free, doesn’t store my API or the data) or to accomplish my task that works too. I am trying to pull a list into Excel so that I can verify with all of our users that I can delete these records from our Directory.

Code in R is:

url <- paste0("https://", data_center, ".qualtrics.com/API/v3/directories/", directory_id, "/contacts/search")

headers <- add_headers(
  "X-API-TOKEN" = api_token,
  "Content-Type" = "application/json"
)

url
#test_url <- paste0(url, "?pageSize=4&skipToken=", skip_token)
test_url <- paste0(url, "?skipToken=", skip_token)
response <- POST(
  test_url,
  headers,
  body = toJSON(list(
    filter = list(
      filterType = "email",
      comparison = "eq",
      value = "test@test.ca"
    )
  ), auto_unbox = TRUE),
  encode = "json"
)

# Parse and check response
if (status_code(response) != 200) {
  stop("Request failed: ", status_code(response), " - ", content(response, "text"))
}

parsed <- content(response, as = "parsed", simplifyVector = TRUE)
skip_token <- parsed$result$skipToken
clipr::write_clip(skip_token)
skip_token
contacts <- parsed$result$elements

# For the response structure, I have also tried:

response <- POST(
  url,
  headers,
  body = toJSON(list(
    filter = list(
      filterType = "email",
      comparison = "eq",
      value = "test@test.ca"
    ),
    skipToken = skip_token
  ), auto_unbox = TRUE),
  encode = "json"
)
 

Be the first to reply!

Leave a Reply