R API Pagination Data Extraction with Loop

27 Views Asked by At

I'm working with Active Campaign API and I was already able to establish the proper connections. I know already how to extract data and I have access, the problem is with pagination.

I was able to access the list I want to extract, but I can just extract 100 by 100 and the data is around 3,656.

The 8 strings you are seeing are for extracting the Tag ID associated with the contacts that have the "Ads_" tag, which is the already created list.

This is the code:

headers <- c('Api-Token' = 'zzz')

These are the 8 Tag Ids where I have "Ads_"
tag_id_string <- c(1197, 1230, 1235, 1256, 1257, 1275,1276,1278)
tag_ids_string2 <- paste(tag_id_string, collapse = ",")
ad_tag_list <- list()

This is the offset variable, where I want to extract all the info in batches of 100, because of the limit
offset_c <- 100
url_c <- paste0("https://cbsaust.api-us1.com/api/3/contacts?limit=100&tagid=",tag_ids_string2,"&offset=",offset_c)

# Request res from API
res <- VERB("GET",
            url_c,
            add_headers(headers))


# Print the content of the response
content <- fromJSON(content(res, "text"),)
content <- content$contacts

# At this point, I already have a data frame with 100 observations, which is CONTENT
  1. Do you know how can I know the length of the data frame, how can I get the 3,656 length?
  2. How could I extract the 3,656 observations 100 by 100?

Appreciate the help,

0

There are 0 best solutions below