Search our Knowledge Base
Search

Search Query API



The search_api_query is a direct query rank on-demand API method that returns the HTML of the search results for a keyword and search engine query. This is a real-time tracking API method that features a callback URL option for automation with your software. 

Search Engines: data is available for Google Desktop, and Google Mobile. Note that desktop and mobile can vary in the type of SERP features available in the results, for example, desktop results may include an image URL in a Featured Snippet, but mobile does not.

Frequency: one-time on-demand.

API Type: this is a stand-alone API-only package, it does not include access to our reporting platform reports or Reporting API methods.

Data Retention: data generated by this API is stored for 24 hours

Data Format: XML is the default format, and JSON can be obtained by adding an output parameter to the request

User-Agent: Only used for mobile search engines. By default the user agent is android, however, if the data is required for IOS then the user agent has to be set.

Package Capacity: 
  • The recurring monthly fee is based on the number of units purchased (1 unit = 1 keyword tracked 1 time on 1 search engine).
  • Units are available in multiples of 1000. 
  • At the beginning of each month, the package capacity is reset (unused capacity is not transferable from the previous month).
Contact us with the number of keyword queries you want to run per month and we'll provide you with pricing.

Search Query API


 

API Options & Restrictions

 

API package capacity can be upgraded at any time.

Search API packages do not include access to Rank Ranger's reporting platform or white label features, these are data-only packages.

This on-demand API does not require a campaign setup, it is used for one-time queries on one search engine per query so it can be built into your software or website, and as such, there is no data storage.


 

Query Parameters

 
key string The unique API key assigned to your account
&key=yourAPIkey
keyword string Keyword
&keyword=your keyword
se_id int Search Engine ID (get search engine ID list)
&se_id=XXX
geo
string Optional: custom Location can be entered to target a specific location by adding &geo=location name or postal code. For example:
  • miami, fl  OR 90210 (specific postal code within the area of Google USA)
  • california (the entire state) 
  • london  or  wc1n (specific postal code within the area of Google.co.uk)
  • amsterdam or 1012nx (specific postal code within the area of Google.nl)
useragent string Related only to mobile search engines requests. To obtain a search query for IOS, add &useragent=ios to the search query request.
callback int Optional: When &callback=true is included in the request, the system will send a callback to the URL that is defined for your account as the 'callback_url'. 
A callback is a POST request sent to your machine informing it that the data extraction task has been completed, and it provides the URL for downloading the HTML of the search results pages. 

Important! Account Setup - when you subscribe to the Search Query API if you want to use the Callback URL option you must send a message to service@rankranger.com with the URL that you want us to send the callback URL to so we can set it up in our system.



Keyword Query with Callback URL

             
 
To receive the URL for downloading the HTML of the search results when the data extraction task has been completed, add the callback parameter to your keyword query and a POST response will be sent to your machine.

Example of Keyword Query to obtain Callback URL
https://www.rankranger.com/api/v2/?search_api_query&key=YOUR-API-KEY&keyword=YOUR-KEYWORD&se_id=XXX&callback=true


Sample Callback URL Response



AخA
 
{  
   "id":12345,
   "_links":[  
      {  
         "rel":"results",
         "href":"https://www.rankranger.com/api/v2/?search_api_query_results&key=APIKEY&query_id=12365789101112",
         "method":"GET"
      }
   ]
          }


Keyword Query Examples without Callback

 

Run Keyword Query for XML output

https://www.rankranger.com/api/v2/?search_api_query&key=YOUR-API-KEY&keyword=YOUR-KEYWORD&se_id=XXX

Run Keyword Query for JSON output

https://www.rankranger.com/api/v2/?search_api_query&key=YOUR-API-KEY&keyword=YOUR-KEYWORD&se_id=XXX&output=json

Run Keyword Query for specific USA location

https://www.rankranger.com/api/v2/?search_api_query&key=YOUR-API-KEY&keyword=YOUR-KEYWORD&se_id=XXX&geo=nashville, tn

Run Keyword Query for a specific city for a non-USA location when using a country-specific search engine (e.g., Google UK)
https://www.rankranger.com/api/v2/?search_api_query&key=YOUR-API-KEY&keyword=YOUR-KEYWORD&se_id=XXX&geo=london
The default output is in XML format, if you would like the output to be JSON then add "&output=json” at the end of the string.



Response: Successful Query Processing

 
Query ID

A successful search_api_query request returns a status of success, along with a Query ID (query_id) that can be used to call the rank results.

 
<tracking-data provider="rankranger" date="03/18/2018" time="12:50:10" status="ok">
    <status>success</status>
    <query_id>6381119358524982273</query_id>
</tracking-data>


Get Results Parameters

 

se_id int Search Engine ID (get search engine ID list)
query_id int Query ID is used to request rank results after submitting a keyword query
parse_results string To obtain parsed results, add &parse_results=true&se_id=XXX to the request
parse_serp_features string Optional: Adding &parse_serp_features=true to the search_query-api_results request provides the special SERP indicators from our Google SERP Features API and Related Search API when those features are present in the search results for the query.
output string To obtain JSON format, add &output=json to the request


HTML Results Request Example

 
The Parse Results, Parse SERP Features, and/or Output parameters can be added to the Callback URL or it can be used in its original form to obtain the HTML SERP results.  

Example of a Callback URL
https://www.rankranger.com/api/v2/?search_api_query_results&key=YOUR-API-KEY&query_id=QUERY-ID


HTML Results Example

The Callback URL produces the full HTML results inside of content tags. For example:
 
x
 
<tracking-data provider="rankranger" date="03/19/2018" time="11:21:01" status="ok">
    <results>
        <created_at>2018-03-18 12:50:49</created_at>
        <updated_at>2018-03-18 12:50:49</updated_at>
        <status_code>200</status_code>
        <query_id>6381119358524982273</query_id>
        <content>
            <!doctype html>
              <html itemscope="" itemtype="http://schema.org/SearchResultsPage" lang="en">
                <head><meta content="/images/branding.jpg">
      <body>
      PAGE CONTENT
    </body>
   </html>
  </content>
 </results>
</tracking-data>


Example of saved HTML results viewed in a web browser 

Callback HTML


Parsed Results Request Example

 
Parsed results can be requested manually in the following format using the query_id received via the search_api_query request, plus the parse_results and se_id parameters.

https://www.rankranger.com/api/v2/?search_api_query_results&key=YOUR-API-KEY&query_id=QUERY-ID&output=json&parse_results=true&se_id=XXX&parse_serp_features=true

Example of Search Query API Parsed Results including SERP Features
In this example viewed in a JSON editor, are
  • organic search results with rank, URL, title, description, and any page extras that display in the SERP (e.g., HTTP, sitelinks, etc.)
  • plus Google SERP Features such as knowledge panel, answer boxes, (e.g., related questions, featured snippets, people also search for, etc.), top stories, videos,  related search, and Google Ads

Search Query API Parsed JSON Results


Results for Mobile Data

 
As previously mentioned the query results for mobile search engine by default retrieves data for Android with the following results example:

Search Query API Android Results

However, if the IOS data is required then &useragent=ios should be added to the request and a different query id should be used. The results will be as follows:

Search Query API IOS Results

Results Not Available

 
Depending upon the queue results may be returned in a matter of seconds to a minute or slightly more for the query to process, so your results request should be set to repeat until results are returned.

When results are not ready, this Not available error is the response:
 
<tracking-data provider="rankranger" date="03/18/2018" time="12:50:12" status="error" code="505">
    <error-details>Not available</error-details>
</tracking-data>


How to Identify Featured Snippet Rank in Search Intelligence APIs

More

How to Obtain API Access

More

How to Generate New API Keys

More

API Console: Construct & Test API Requests

More

API Query Limits

More

Developer API Methods

More

API Error Codes

More

Get the ultimate SEO tools with the Rank Ranger Software
Learn More About Rank Ranger