Google custom search JSON API is a RESTFUL API that lets you develop applications to get and show search results (web search, images) from Google custom search programmatically. With this API, you can use RESTful requests to get either web search or image search results in JSON format.

The existing documentation on creating a google custom search using the API method is confusing and we will try to simplify the process here. If you are not a big fan of google custom search, you can try out other expertrec’s custom search engine.

In this article, we will see how we can create a custom search engine using the Google custom search API. We will also see what are the limitations of google custom search API and how we can overcome them.

Create your custom search engine using expertrec

Create a custom search engine at https://www.google.com/cse

This is the first step to obtain a google custom search API. Go to cse.google.com, enter your website URL and click on create google custom search.

Google custom search JSON API parameters

The usual API call is

https://www.googleapis.com/customsearch/v1?parameters

Here parameters could be –

  1. q– query string
  2. cx– Custom search engine ID.
  3. fileType– bmp, gif, jpg, png, pdf etc
  4. num-number of search results to display
  5. searchType- search type.
  6. sort-Sort by functionality to use.

For a list of all query parameters, go to this link.

Google custom search JSON API simplified

A sample API call would be like this-

https://www.googleapis.com/customsearch/v1?key={YOUR_API_KEY}&cx={CUSTOM_SEARCH_ENGINE_ID}&q={KEYWORD}
https://www.googleapis.com/customsearch/v1?key=AIzaSyDOvbipdULbUpVm3HLjoX7bEEfDUKHELh4&cx=012278024424817052234:cimrvj4h4uk&q=jeff

The response of this API will be in JSON format for you to consume to build your search application.

{
   "kind": "customsearch#result",
   "title": "Jeff Pedowitz - President and CEO - The Pedowitz Group | LinkedIn",
   "htmlTitle": "\u003cb\u003eJeff\u003c/b\u003e Pedowitz - President and CEO - The Pedowitz Group | LinkedIn",
   "link": "https://www.linkedin.com/in/jeffpedowitz",
   "displayLink": "www.linkedin.com",
   "snippet": "View Jeff Pedowitz's full profile. It's free! Your colleagues, classmates, and 500 \nmillion other professionals are on LinkedIn. View Jeff's Full Profile ...",
   "htmlSnippet": "View \u003cb\u003eJeff\u003c/b\u003e Pedowitz's full profile. It's free! Your colleagues, classmates, and 500 \u003cbr\u003e\nmillion other professionals are on LinkedIn. View \u003cb\u003eJeff's\u003c/b\u003e Full Profile ...",
   "formattedUrl": "https://www.linkedin.com/in/jeffpedowitz",
   "htmlFormattedUrl": "https://www.linkedin.com/in/\u003cb\u003ejeff\u003c/b\u003epedowitz",
   "pagemap": {
    "cse_thumbnail": [
     {
      "width": "276",
      "height": "183",
      "src": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcT00CLj3qk3NDZp35KPvo4A2kaXF-FrhY7DwtGru9ikLSV2LDmaKneWJT2Z"
     }
    ],

 

Getting your google custom search API Key

  1. Go to https://developers.google.com/custom-search/json-api/v1/overview
  2. Click on get a key.Google custom search JSON API simplified
  3. Click create new project.Google custom search JSON API simplified
  4. This will generate your new API key.Google custom search JSON API simplified
  5. You can restrict the usage of this API key in your Google API console https://console.developers.google.com/apis
Google custom search JSON API simplified

Getting your CX / Search engine ID:

Go to your custom search / site search control panel-> edit search engine->Basics->Details->Search engine ID.

This is your search engine ID.

Google custom search JSON API

Testing your google custom search JSON API-

You can test your google custom search API using the Google API explorer 

google custom search apiYou could try out ExpertRec’s site search API, which is easier to implement with no coding needed at all. Expertrec’s site search API is also available if in case you want to go through the API route.

Limitations of Google custom search API-

  1. You can only retrieve a maximum of 10 search results at a time.
  2. Query limit of 100 per day.

ExpertRec’s Google custom search replacement API to overcome limitations of Google custom search JSON API

Go to https://cse.expertrec.com?platform=cse  and enter your website and sitemap URLs to get your crawl done. Go and click on your demo link.

Get your expertrec site search API

Go to https://cse.expertrec.com/csedashboard/home/Status to get your API keygoogle custom search api

 

The API will be of this format-

https://searchv7.expertrec.com/v6/search/{org_id}/?q={keyword}&page={pagination}&size={number_of_search_results}
https://searchv7.expertrec.com/v6/search/ccdb9cb6-5380-11e8-a8e3-12b6486824f4/?q=a&page=0&size=16

Expertrec site search API parameters-

  1. org_id- Your unique ID that identifies your website/ websites.
  2. q- Keyword.
  3. page- pagination
  4. size- number of search results to be displayed.

The results will be in JSON format-

{  
   "0len":1,
   "1query":"a",
   "facet_interval":{  

   },
   "facets":{  
      "type":{  
         "webpage":160
      }
   },
   "fq":{  

   },
   "nf":{  

   },
   "numeric":{  

   },
   "res":{  
      "count":160,
      "st":0,
      "time":3
   },
   "results":[  
      {  
         "date":"2018-05-09T12:35:47.110Z",
         "host":"blog.expertrec.com",
         "id":"https://blog.expertrec.com/wordpress-custom-search/",
         "image":[  
            "https://blog.expertrec.com/wp-content/uploads/2018/04/6.png"
         ],
         "popularity_score":1.0,
         "score":1.25,
         "snippet":{  
            "content":[  
               "How to <span class=highlight>create</span> <span class=highlight>a</span> wordpress custom <span class=highlight>search</span> - 2018 Expertrec
 
Support
<span class=highlight>magento</span>
<span class=highlight>search</span> engine
Google site <span class=highlight>search</span> <span class=highlight>replacement</span>
Expertec
Toggle <span class=highlight>Navigation</span>
How to <span class=highlight>create</span> <span class=highlight>a</span> wordpress custom <span class=highlight>search</span>
Published by <span class=highlight>muthali</span> <span class=highlight>ganesh</span> on <span class=highlight>April</span> 8, 2018
<span class=highlight>Creating</span> wordpress custom <span class=highlight>search</span> using expertrec is <span class=highlight>as</span> <span class=highlight>easy</span> <span class=highlight>and</span> <span class=highlight>can</span> be <span class=highlight>taken</span> live in 5 minutes. "
            ],
            "metatag.description":[  

            ],
            "title":[  
               "How to <span class=highlight>create</span> <span class=highlight>a</span> wordpress custom <span class=highlight>search</span> - 2018 Expertrec"
            ]
         },
         "title":"How to create a wordpress custom search - 2018 Expertrec",
         "type":"webpage",
         "url":"https://blog.expertrec.com/wordpress-custom-search/"
      }
   ],
   "sfacets":{  
      "type":[  
         {  
            "count":160,
            "name":"webpage"
         }
      ]
   }
}

 

Create your expertrec custom search engine

muthali ganesh

Muthali loves writing about emerging technologies and easy solutions for complex tech issues. You can reach out to him through chat or by raising a support ticket on the left hand side of the page.

You may also like