I have the following function in R to GET a response from Api calls from my website
get_results <- function(headers, experiment_id, ontology = "all") {
get_drugs_for_results <- function(gene_prioritization) {
cat("Extracting drugs for gene prioritization...n")
print(gene_prioritization) # Debug: Inspect gene_prioritization content
top_genes <- gene_prioritization$top_genes_configuration
gene_symbols <- sapply(top_genes, function(x) x$gene_symbol)
gene_symbols <- unique(gene_symbols)
cat("Gene symbols to query for drugs:n")
print(gene_symbols) # Debug: Print the gene symbols being queried
response <- GET(
paste0(url, "drugs"),
add_headers(.headers = headers),
query = list(genes = toJSON(gene_symbols))
)
cat("Response status code for drugs API:", status_code(response), "n")
if (status_code(response) == 200) {
results <- fromJSON(rawToChar(response$content))
return(results$genesDrugs)
} else {
cat("Error in drugs API response:", status_code(response), content(response, "text"), "n")
return(list())
}
}
cat("-- Results of experiment with ID: ", experiment_id, " --n")
# Inspect headers and experiment_id before the request
cat("Headers:n")
print(headers)
cat("Experiment ID:n")
print(experiment_id)
response <- GET(paste0(url, "results"),
add_headers(.headers = headers),
query = list(experimentId = experiment_id))
cat("Response status code for results API:", status_code(response), "n")
cat("Response content:n")
print(content(response, "text")) # Debug: Print raw response content for inspection
if (status_code(response) == 200) {
results <- fromJSON(rawToChar(response$content))
status <- results$status
cat("Experiment status:", status, "n")
results <- get_results(headers, experiment_id, ontology)
I am trying to solve the following error :
> No encoding supplied: defaulting to UTF-8.
> Error in results API response: 500 Internal Server Error
The url to the server and all headers(Content-Type: “application/json”, api-key :”your-api-key”), experiment id (“1234567890”) are correct but something is wrong with GET response ? Can you help ?
0