Wix API, list_members endpoint returning different members each time called

110 Views Asked by At
headers = c(
  `Authorization` = access_key,
  `wix-site-id` = our_site_id
)

fetch_members <- function() {

  # set constants
  # endpoint <- "https://www.wixapis.com/members/v1/members"

  offset <- 0
  limit <- 1000
  is_paging <- TRUE
  output_list <- c()
  params <- list(`paging.limit` = limit, fieldSet = 'FULL', sort = c('createdDate'))
  
  # page through the api, fetching data 
  while(is_paging) {
    print(paste0('offset: ', offset))
    
    # set params, make fetch
    params$`paging.offset` <- offset
    res <- httr::GET(url = endpoint, httr::add_headers(.headers=headers), query = params)
    res
    
    # grab members, metadata from fetch
    content <- httr::content(res)
    metadata <- content$metadata
    this_list <- content$members
    length(this_list)
    
    # add to list, increment offset, and assess paging
    output_list <- c(output_list, this_list)
    offset <- offset + limit
    is_paging <- metadata$count == limit
  }
  
  # flatten the data
  members_df <- output_list %>%
    purrr::map(unlist) %>%
    purrr::map(t) %>%
    purrr::map(as_tibble, .name_repair = ~make.names(., unique = TRUE)) %>%
    dplyr::bind_rows() %>%
    readr::type_convert() %>%
    janitor::clean_names(case = 'snake')
  
  # and return
  return(members_df)
}

What is the proper way to handle paging and sorting with the wix API /members/v1/members endpoint?

frustrating issue when fetching a list of our website's members from the Wix API. We are using R in example above, but experiencing same issue in Python. We call this function above, it successfully returns the same number of members 9744 each time. However, a different set of members each time, never the correct 9744 unique members, rather, we always get some duplicates as well as some omissions. Clearly, either the sorting or pagination (or both) are messed up. We get outputs like the following:

members <- fetch_members()
which(members$login_email == '[email protected]')
[1] 8165

members <- fetch_members()
which(members$login_email == '[email protected]')
[1] 8165 9698

members <- fetch_members()
which(members$login_email == '[email protected]')
integer(0)

https://dev.wix.com/docs/rest/api-reference/members/members/list-members are the docs we are working with, and https://dev.wix.com/docs/rest/articles/getting-started/sorting-and-paging#sort-list-endpoints are the sorting, paging docs.

Frankly, I think the paging is fine and the sorting is the problem. In metadata, it shows offset, limit correctly. How do we sort properly here?

Edit: there is also an https://www.wixapis.com/members/v1/members/query endpoint, however with this endpoint we also cannot get either paging or sorting to work correctly. Even with the lower paging limit (100 instead of 1000), we'd happily use this endpoint if the paging and sorting would work.

1

There are 1 best solutions below

0
On

Judging by the documentation, I'd guess your problem is in your params. In particular, you use sort, and they seem to expect sorting like this

params <- list(`paging.limit` = limit, fieldSet = 'FULL', sorting = c('createdDate'))