I am trying to integrate the performance testing of certain websites using GTmetrix. With the API, I am able to run the test and pull the results using the SEO connector tool in Microsoft Excel. However, it uses the xml with older version of API, and some new tests are not available in this. The latest version is 2.0
The link for the xml is here: GTmetrix XML for API 0.1.
I tried using the libraries httr and jsonlite. But, I don't know how authenticate with API, run the test and extract the results.
The documentation for API is available at API Documentation.
library(httr)
library(jsonlite)
url <- "https://www.berkeley.edu" # URL to be tested
location <- 1 # testing Location
browser <- 3 # Browser to be used for testing
res <- GET("https://gtmetrix.com/api/gtmetrix-openapi-v2.0.json")
data <- fromJSON(rawToChar(res$content))
Update 2021-11-08:
I whipped up a small library to talk to GTmetrix via R. There's some basic sanity checking baked in, but obviously this is still work in progress and there are (potentially critical) bugs. Feel free to check it out, though. Would love some feedback.
Update 2021-11-12: It's available on CRAN now. :-)
Start test (and get results)
This will start a test and wait for the report to be generated, returning the result as data.frame. Optionally, you can just simply return the test ID and other meta data via the parameter
wait_for_completion = FALSE.Other optional parameters:
location,browser,report,retention,httpauth_username,httpauth_password,adblock,cookies,video,stop_onload,throttle,allow_url,block_url,dns,simulate_device,user_agent,browser_width,browser_height,browser_dppx,browser_rotate.Show available browsers
Show available locations
Get specific test
Get specific report
Get all tests
Get account status
Original answer:
Pretty straightforward, actually:
0. Set test parameters.
1. Start a test
2. Get test ID
3. Get report ID
4. Get report
I'm kinda tempted to build something for this as there seems to be no R library for it...