Data source scores

Thanks Irene for the great solution!!! I’d like to share the R version based on Irene’s solution

library(httr)
library(jsonlite)

# Define the query string
query_string <- '
query associatedDiseases {
  target(ensemblId: "ENSG00000127318") {
    id
    approvedSymbol
    associatedDiseases {
      count
      rows {
        disease {
          id
          name
        }
        datasourceScores {
          id
          score
        }
      }
    }
  }
}
'

# Define the URL for the API endpoint
base_url <- "https://api.platform.opentargets.org/api/v4/graphql"

# Perform the POST request
response <- POST(
  url = base_url,
  body = list(query = query_string),
  encode = "json"
)

# Check the status code of the response
if (status_code(response) == 200) {
  # Parse the response from JSON
  api_response <- content(response, as = "parsed", type = "application/json")
  
  # Print the response in a readable format
  print(toJSON(api_response, pretty = TRUE))
} else {
  # Print the error message if the request failed
  print(paste("Error:", status_code(response)))
}