Hi,
I am trying to download some data for a list of around 5000 patents from PatentsView API through patentsview package in R. However, after downloading information of 570 patents, I am getting the following error:
"Error in xheader_er_or_status(resp) : Internal Server Error (HTTP 500)."
Could you please help me to solve this problem?
Here are my code if it helps:
library(patentsview)
###(patentsview::fieldsdf)
setwd("/Users/alisamei/Dropbox (IESE)/Ali-Remote folder/FDA Patent Product Database")
##patents_field <- read.csv("patentsviewfields_patents.csv")
patent_no <- read.csv("FDA_patent_product_2014_2018.csv")
##creating empty dataframe to feed in final data
patents <- data.frame(matrix(NA_character_, nrow = 4858, ncol = 31))
inventors <- data.frame(matrix(NA_character_, nrow = 4858, ncol = 24))
assignees <- data.frame(matrix(NA_character_, nrow = 4858, ncol = 31))
IPCs <- data.frame(matrix(NA_character_, nrow = 4858, ncol = 16))
cited_patents <- data.frame(matrix(NA_character_, nrow = 4858, ncol = 7))
citedby_patents <- data.frame(matrix(NA_character_, nrow = 4858, ncol = 6))
uspcs <- data.frame(matrix(NA_character_, nrow = 4858, ncol = 11))
cpcs <- data.frame(matrix(NA_character_, nrow = 4858, ncol = 15))
nbers <- data.frame(matrix(NA_character_, nrow = 4858, ncol = 10))
gov_interests <- data.frame(matrix(NA_character_, nrow = 4858, ncol = 8))
## just running the search_pv query for the first patent on the list to fill in the first row of the data frame
result <- search_pv(query = qry_funs$contains(patent_id=as.character(patent_no[2,])),
fields = get_fields(endpoint = "patents", groups = c("patents","assignees", "inventors", "cpcs","nbers","uspcs", "gov_interests","ipcs","coinventors","cited_patents","citedby_patents")))
output <- unnest_pv_data(data=result$data, pk="patent_id")
output_patents <- output$patents
output_inventors <- output$inventors
output_assignees <- output$patents
output_ipcs <- output$IPCs
output_cited_patents <- output$cited_patents
output_citedby_patents <- output$citedby_patents
output_uspcs <- output$uspcs
output_cpcs <- output$cpcs
output_nbers <- output$nbers
output_gov_interests <- output$gov_interests
patents<- output_patents
inventors<- output_inventors
assignees<- output_assignees
ipcs <- output_ipcs
cited_patents <- output_cited_patents
citedby_patents <- output_citedby_patents
uspcs <- output_uspcs
cpcs <- output_cpcs
nbers <- output_nbers
gov_interests <- output_gov_interests
##looping over the whole list
for (i in 571:nrow(patent_no)){
result <- search_pv(query = qry_funs$contains(patent_id=as.character(patent_no[i,])),
fields = get_fields(endpoint = "patents", groups = c("patents","assignees", "inventors", "cpcs","nbers","uspcs", "gov_interests","ipcs","coinventors","cited_patents","citedby_patents")))
if (is.null(dim(result$data$patents))==TRUE) {
patents[i,1]<- as.character(patent_no[i,1])
patents[i,2:31]<- "."
inventors[i,1]<- as.character(patent_no$patent_id[i])
inventors[i,2:24] <- "."
assignees[i,1]<- as.character(patent_no$patent_id[i])
assignees[i,2:31]<- "."
ipcs[i,1]<- as.character(patent_no$patent_id[i])
ipcs[i,2:16] <- "."
cited_patents[i,1]<- as.character(patent_no$patent_id[i])
cited_patents[i,2:7] <- "."
citedby_patents[i,1]<- as.character(patent_no$patent_id[i])
citedby_patents[i,2:6] <- "."
uspcs[i,1]<- as.character(patent_no$patent_id[i])
uspcs[i,2:11] <- "."
cpcs[i,1]<- as.character(patent_no$patent_id[i])
cpcs[i,2:15] <- "."
nbers[i,1]<- as.character(patent_no$patent_id[i])
nbers[i,2:10] <- "."
gov_interests[i,1]<- as.character(patent_no$patent_id[i])
gov_interests[i,2:8] <- "."
} else {
output <- unnest_pv_data(data=result$data, pk="patent_id")
output_patents <- output$patents
output_inventors <- output$inventors
output_assignees <- output$patents
output_cited_patents <- output$cited_patents
output_citedby_patents <- output$citedby_patents
output_uspcs <- output$uspcs
output_cpcs <- output$cpcs
output_nbers <- output$nbers
output_gov_interests <- output$gov_interests
patents[i,]<- output_patents
inventors[i,]<- output_inventors
assignees[i,]<- output_assignees
ipcs[i,] <- output_ipcs
cited_patents[i,] <- output_cited_patents
citedby_patents[i,] <- output_citedby_patents
uspcs[i,] <- output_uspcs
cpcs[i,] <- output_cpcs
nbers[i,] <- output_nbers
gov_interests[i,] <- output_gov_interests
}
}