# 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?

[>> Create an account <<](https://app.valueserp.com/signup)

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

### API Authentication

Grab your API key from your [profile](https://app.valueserp.com/profile)

![⚠️ Developer credentials (such as passwords, keys and client IDs) should be kept confidential. ⚠️](/files/DGOp4wos0P020cfT4d4q)

Here is how you can send query, replace the api\_key with your own below.

```r
# Loading the right libraries
library(httr)
library(jsonlite)

# Parameters list
params = list(
      `api_key` = 'XXXXXX',
      `q` = "covid",
      `gl` = "fr",
      `hl` = "fr",
      `num` = 20,
      `google_domain` = 'google.fr'
)
# q : the search query
# gl : 2 letter country code 
# hl : language code
# num : number of result asked

# ask for the data
res <- httr::GET(url = 'https://api.valueserp.com/search', query = params)

# translate to string
res_text <- httr::content(res, "text")

# translate to a more readable format
res_json <- jsonlite::fromJSON(res_text, flatten = TRUE)
```

You can inspect the result by running this command line

```r
View(res_json)
```

![](/files/0MY86dn0j6Nt4lXgQWbI)

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.

```r
serpValueRank <- function(myKwd, glang, hlang, nbr, tld){
  library(httr)
  library(jsonlite)
  all_full_txt <- data.frame(matrix(ncol = 2, nrow = 0))
  colnames(all_full_txt) <- c("kwd", "POS1")
  for (i in 1:length(myKwd)) {
    params = list(
      `api_key` = 'XXXXXX',
      `q` = myKwd[i],
      `gl` = glang,
      `hl` = hlang,
      `num` = nbr,
      `google_domain` = paste0('google', tld)
    )
    message(i, " ", myKwd[i])
    all_full_txt[i, "kwd"] <- myKwd[i]
    res <- httr::GET(url = 'https://api.valueserp.com/search', query = params)
    res_text <- httr::content(res, "text")
    res_json <- jsonlite::fromJSON(res_text, flatten = TRUE)
    for (rslt in 1:length(res_json[["organic_results"]][["link"]])) {
      all_full_txt[i, paste0("POS", rslt)] <-
      res_json[["organic_results"]][["link"]][[rslt]]
    }
  }
  return(all_full_txt)
}
```

after this has been copy-pasted, you can just launch the function as many times as you want.\
you can ask for one ranking

```r
ranking <- serpValueRank("covid", "fr", "fr", 20, ".fr")
View(ranking)
```

or several at once

```r

kwds <- c("covid", "covid test", "covid booster")

kwdsRankings <- serpValueRank(kwds, "fr", "fr", 20, ".fr")

View(kwdsRankings)
```

You can also save those results [as a CSV or an Excel file](/export-data/send-and-read-seo-data-to-excel.md)

⚠️ 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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.rforseo.com/apis/grab-google-rankings-from-value-serp-api-using-r.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
