求助:如何通过R调用API获取MoveApps的分析输出结果?
Using R to Retrieve MoveApps Workflow Output via API
Here's a step-by-step implementation to fetch MoveApps workflow outputs using R, leveraging the httr package for API requests:
Prerequisites
- A valid MoveApps API token (available in your MoveApps account settings under API credentials)
- The ID of your target workflow and its corresponding output ID (find these in the MoveApps web interface: workflow ID is in the workflow URL, output IDs are listed in the workflow's "Outputs" tab)
Step 1: Install Required Packages
install.packages(c("httr", "jsonlite", "readr")) library(httr) library(jsonlite) library(readr)
Step 2: Configure Authentication & Variables
# Load your API token (store securely in .Renviron instead of hardcoding!) api_token <- Sys.getenv("MOVEAPPS_API_TOKEN") # Replace with your workflow and output IDs workflow_id <- "YOUR_WORKFLOW_ID" output_id <- "YOUR_OUTPUT_ID" # Set up authorization headers auth_headers <- add_headers( Authorization = paste("Bearer", api_token), "Content-Type" = "application/json" )
Step 3: Fetch Output Data
For CSV Outputs
# Construct the download endpoint download_endpoint <- paste0("https://api.moveapps.org/workflows/", workflow_id, "/outputs/", output_id, "/download") # Send GET request response <- GET(download_endpoint, auth_headers) # Validate response and parse data if (http_status(response)$category == "Success") { output_data <- read_csv(content(response, "text")) cat("Output retrieved successfully!\n") print(head(output_data)) } else { cat("Request failed:", http_status(response)$message, "\n") print(content(response)) }
For JSON Outputs
Replace the parsing line with:
output_data <- fromJSON(content(response, "text"))
Step 4: List All Outputs for a Workflow (If You Don't Know the Output ID)
outputs_list_endpoint <- paste0("https://api.moveapps.org/workflows/", workflow_id, "/outputs") outputs_response <- GET(outputs_list_endpoint, auth_headers) if (http_status(outputs_response)$category == "Success") { outputs <- fromJSON(content(outputs_response, "text")) cat("Available outputs:\n") print(outputs[, c("id", "name", "type")]) # Display key details } else { cat("Failed to fetch outputs:", http_status(outputs_response)$message, "\n") }
Key Tips
- Secure Token Storage: Never hardcode your API token in scripts. Use a
.Renvironfile to store it as an environment variable (runusethis::edit_r_environ()to open the file). - Workflow Status: Ensure the workflow has completed successfully before attempting to fetch outputs—you can check workflow status via the API using the
/workflows/{workflowId}endpoint. - Rate Limits: Respect MoveApps API rate limits; add
Sys.sleep()delays if making repeated requests.
内容的提问来源于stack exchange,提问作者Nova
相关产品推荐
相关产品推荐

