Grab Google Rankings from VALUE SERP API using R'

What is VALUE SERP?

It's a great paid API that provides ranking data for a cheap price.

How to use its API?

When you create your account, you are given a few dollars to test the service.

API Authentication

Grab your API key from your profile
⚠️ Developer credentials (such as passwords, keys and client IDs) should be kept confidential. ⚠️
Here is how you can send query, replace the api_key with your own below.
1
# Loading the right libraries
2
library(httr)
3
library(jsonlite)
4
5
# Parameters list
6
params = list(
7
`api_key` = 'XXXXXX',
8
`q` = "covid",
9
`gl` = "fr",
10
`hl` = "fr",
11
`num` = 20,
12
`google_domain` = 'google.fr'
13
)
14
# q : the search query
15
# gl : 2 letter country code
16
# hl : language code
17
# num : number of result asked
18
19
# ask for the data
20
res <- httr::GET(url = 'https://api.valueserp.com/search', query = params)
21
22
# translate to string
23
res_text <- httr::content(res, "text")
24
25
# translate to a more readable format
26
res_json <- jsonlite::fromJSON(res_text, flatten = TRUE)
Copied!
You can inspect the result by running this command line
1
View(res_json)
Copied!
To make it easier for you, I have created a function that you can copy and paste, just replace the api_key with your own below.
1
serpValueRank <- function(myKwd, glang, hlang, nbr, tld){
2
library(httr)
3
library(jsonlite)
4
all_full_txt <- data.frame(matrix(ncol = 2, nrow = 0))
5
colnames(all_full_txt) <- c("kwd", "POS1")
6
for (i in 1:length(myKwd)) {
7
params = list(
8
`api_key` = 'XXXXXX',
9
`q` = myKwd[i],
10
`gl` = glang,
11
`hl` = hlang,
12
`num` = nbr,
13
`google_domain` = paste0('google', tld)
14
)
15
message(i, " ", myKwd[i])
16
all_full_txt[i, "kwd"] <- myKwd[i]
17
res <- httr::GET(url = 'https://api.valueserp.com/search', query = params)
18
res_text <- httr::content(res, "text")
19
res_json <- jsonlite::fromJSON(res_text, flatten = TRUE)
20
for (rslt in 1:length(res_json[["organic_results"]][["link"]])) {
21
all_full_txt[i, paste0("POS", rslt)] <-
22
res_json[["organic_results"]][["link"]][[rslt]]
23
}
24
}
25
return(all_full_txt)
26
}
Copied!
after this has been copy-pasted, you can just launch the function as many times as you want. you can ask for one ranking
1
ranking <- serpValueRank("covid", "fr", "fr", 20, ".fr")
2
View(ranking)
Copied!
or several at once
1
2
kwds <- c("covid", "covid test", "covid booster")
3
4
kwdsRankings <- serpValueRank(kwds, "fr", "fr", 20, ".fr")
5
6
View(kwdsRankings)
Copied!
You can also save those results as a CSV or an Excel file
⚠️ By default, VALUE SERP will separate all SERP features. Meaning 'organic result' will exclude the video carousel for example. If you would like all of them flattened into the organic_results array, then you could use “flatten_results=true”. The flattened “position” property will include every SERP features