R/getAllOrganizations.R

Defines functions getAllOrganizations

Documented in getAllOrganizations

getAllOrganizations <- function(){
        curl = getCurlHandle()
        stopPaging <- FALSE
        result <- list()
        i <- 1
	
	## Need to page through the results since only 100 are returned at a time
	while(stopPaging == FALSE){
            result[[i]]<-getURL(paste(.ZendeskEnv$data$url, .ZendeskEnv$data$organizations, "?page=" ,i, sep=""), curl=curl, ssl.verifypeer=FALSE,
				.opts=list(userpwd=(paste(.ZendeskEnv$data$username, .ZendeskEnv$data$password, sep=":"))))
            if(is.null(fromJSON(result[[i]])$next_page)){
                stopPaging <- TRUE
            }
            i <- i + 1
        }

        ## Transform the JSON data to a data.frame
	json.data <- lapply(unlist(result), fromJSON)
        pre.result <- lapply(json.data, function(x) do.call("rbind", x$organizations))
        final.result<-do.call("rbind", pre.result)
        orgs.df <- data.frame(final.result)
 	orgs.df <- unlistDataFrame(orgs.df)
	return(orgs.df)
}

Try the zendeskR package in your browser

Any scripts or data that you put into this service are public.

zendeskR documentation built on May 30, 2017, 12:39 a.m.