Start Exploring Keyword Ideas

Use Serpstat to find the best keywords for your website

SEO April 12, 2019  |  18216   92   |  10 min read  – Read later

Serpstat JavaScript SDK: Programming Right In Your Browser

Serpstat Javascript SDK: Programming Right In Your Browser
How To Hack Your Competitors’ Content Plan: Step-By-Step Guide 16261788256933
Andrey Belousov
Growth Hacking Specialist at Serpstat
Again and again, the question arises as to whether a good SEO must be able to code. So far, only one thing is clear — programming knowledge helps you increase the efficiency of your work and go beyond standard options of the SEO tools.
Recently, we published our first hacking article, which tells how to use the Serpstat script to analyze competitors. This article explains how to use Serpstat API to code directly in the browser to analyze large amounts of data for SEO purposes and to systemize them according to your needs.

Why do you need an API?

Although Serpstat has many features, your daily tasks may require special effort. If you need an unusual analysis of a huge amount of data for your SEO routine, then Serpstat API is a perfect solution for you.

High-quality keyword research, checking the top search results in seconds, quick competitive analysis and finding unusual solutions are just a few of the many advantages offered by Serpstat API. Everything from the analysis of the individual site to crawling with complex evaluations is at your fingertips.

Important! You don't need programming skills to work with API. You can find more information about the application of the interface in the manual.

Here are a few examples of the tasks that API can solve:
Analysis of positions and visibility of your site and your competitors' one
Assessment of SEO services' success by region
In-depth competitor analysis
Keyword research and URL analysis
Search for thematically related forums, blogs, and websites
Serpstat API is well-liked among our clients because of reasonable API prices. We reach such low costs because we made our product recently compared to competitors and with new technologies to make many features cheaper.

You can use the API as part of your plan with the following features:

New opportunities with JavaScript SDK

In addition to the API console, which makes the API application much easier, JavaScript SDK from Serpstat has recently become available. This interface allows you to code directly in the browser as well as on the Node.js platform.

In this case, no web server setup is required, thus making the API application faster and easier than ever. To get started, just open our code in the browser.

Start of the tool

1
Create an HTML file.
2
Open it with any text editor.
3
Add this code:
<script src="https://cdn.jsdelivr.net/npm/serpstat-api-3/serpstat-api.js"></script>
<pre id="res"></pre>
<script>
    var api = SerpstatAPI.init({
         token   : "ENTER TOKEN HERE" 
    });
   api.databases_info().then(function(bases){
      document.getElementById("res").innerHTML = JSON.stringify(bases,null,"  ");
   })
</script>
4
Enter your Serpstat API token instead of "ENTER TOKEN HERE."
5
Save the file.
6
Open it in your browser.
As you can see, you can easily repeat this. Let me just explain some details in the code:
Adding SDK:
<script src="https://cdn.jsdelivr.net/npm/serpstat-api-3/serpstat-api.js"></script>
The results are listed here:
<pre id="res"></pre>
<script>
Entering the token:
 var api = SerpstatAPI.init({
         token   : "ENTER TOKEN HERE" 
    });
Selecting API method:
api.databases_info()
After that, the code is executed below:
.then(function(bases){
Results are posted in the tag with id res:
document.getElementById("res").innerHTML = JSON.stringify(bases,null,"  ");

Async/Await or then?

Next, we'll use the keywords async/await in the code. Although they facilitate programming, they have one drawback: outdated browsers cannot support them. If you create a public utility, better use the keyword then:
async/await
async function someFun(){
    var res1 = await(api.someMethod1(...));
    …
    var res2 = await(api.someMethod2(...));
    ….
}
then
function someFun(){
    api.someMethod1(...).then(function(res1){
             ...
             api.someMethod2(...).then(function(res2){
                ...
              });
    });
}
This is how the code looks with async/await:
<script src="https://cdn.jsdelivr.net/npm/serpstat-api-3/serpstat-api.js"></script>
<pre id="res"></pre>
<script> (async function(){
    var api = SerpstatAPI.init({
         token   : "ENTER TOKEN HERE" 
    });
   var bases = await(api.databases_info());
   document.getElementById("res").innerHTML = JSON.stringify(bases,null,"  ");
})();</script>

Application of Serpstat API Console

Interface and examples

Another way to start working with API is to run the JS code in the API Console. To do this, choose the method Misc. and the option → Run Javascript Code.
How To Hack Your Competitors’ Content Plan: Step-By-Step Guide 16261788256934
For example, if you want to see all regions available for the analysis in Serpstat, you should:
1
Enter your token.
2
Select the method Run Javascript Code.
3
Enter the code:
var bases = await (api.databases_info());
return bases; 
I'll show you how to accomplish a more complicated task. Suppose you want to find information about your domain in all regions. This is the code that supplies the data to the Serpstat domain.
//get databases
var bases   = await (api.databases_info());
//leave an array of database codes
var se = [];
for(var i = 0; i<bases .length; i++){
    se.push(bases [i].db_name);      
}
//get domain data by region
var res = await(api.domain_info({
   query: 'serpstat.com',
   se: se   
}));
return res; 
The execution of the code will take several minutes. Then you get the report on the analyzed domain, where the rows show the domain parameters (visibility, traffic, etc.) and the columns show the regions.
How To Hack Your Competitors’ Content Plan: Step-By-Step Guide 16261788256935
If you want to display the data differently and switch columns and rows of the report, you can use the following code:

Important! Before you run the code, you should disable Remove Duplicates.
//get database
var bases   = await (api.databases_info());
//leave an array of database codes
var se = [];
for(var i = 0; i<bases.length; i++){
    if(bases [i].db_name[0]==='y'){
         se.push(bases [i].db_name);   
    }   
}
//get domain data by region
var res = await(api.domain_info({
   query: 'serpstat.com',
   se: se   
}));
//turn the table
var transope = [];
var rowNames = Object.keys(res[0]) 
for(var i=0; i<rowNames.length; i++){
    var rowName = rowNames[i];
    var row     = {name: rowName};
    for(var j=0;j<res.length;j++){
        row['se_'+res[j]._se] = res[j][rowName];
    }
    transope.push(row);
}
return transope; 
How To Hack Your Competitors’ Content Plan: Step-By-Step Guide 16261788256935
The API Console has its own interface, which offers a variety of functions for displaying the code and editing the data: tables, filters, SQL and export in CSV and XLSX formats. In other words, you can play your own code, export received data as XLSX or CSV file and open it with MS Excel or Google Spreadsheets.

Options application

When "Show options" is active under the code entry field, then you can use the options that are entered into the console in the code. For example, opts.query or opts.se.
How To Hack Your Competitors’ Content Plan: Step-By-Step Guide 16261788256937
var res = await(api.domain_info({
   query: opts.query,
   se: opts.se  
}));
return res; 
Or:
var res = await(api.domain_info(opts));
return res; 
As you can see, Serpstat API opens new horizons for SEOs. Especially when it comes to large agencies and in-house teams, for whom the automation of SEO tasks is a must-have. It's easier than ever to code with Serpstat API Console because it doesn't require server setup and takes no more than 10 minutes to initialize.

Speed up your search marketing growth with Serpstat!

Keyword and backlink opportunities, competitors' online strategy, daily rankings and SEO-related issues.

A pack of tools for reducing your time on SEO tasks.

Get free 7-day trial

Rate the article on a five-point scale

The article has already been rated by 14 people on average 4.5 out of 5
Found an error? Select it and press Ctrl + Enter to tell us

Discover More SEO Tools

Backlink Cheсker

Backlinks checking for any site. Increase the power of your backlink profile

API for SEO

Search big data and get results using SEO API

Competitor Website Analytics

Complete analysis of competitors' websites for SEO and PPC

Keyword Rank Checker

Google Keyword Rankings Checker - gain valuable insights into your website's search engine rankings

Share this article with your friends

Are you sure?

Introducing Serpstat

Find out about the main features of the service in a convenient way for you!

Please send a request, and our specialist will offer you education options: a personal demonstration, a trial period, or materials for self-study and increasing expertise — everything for a comfortable start to work with Serpstat.

Name

Email

Phone

We are glad of your comment
I agree to Serpstat`s Privacy Policy.

Thank you, we have saved your new mailing settings.

Open support chat
mail pocket flipboard Messenger telegramm