If you're building an SEO platform, a keyword rank tracker, a competitor research tool, or an AI application that needs real-time web data, Google search results can be a valuable data source.
The challenge is collecting that data reliably.
Writing your own scraper means dealing with changing HTML structures, proxy management, CAPTCHA challenges, retries, and data normalization. These tasks can quickly become more complicated than the application you're actually trying to build.
A Google Search API offers a simpler approach: send an HTTP request with your search query and receive structured JSON that your application can process.
In this tutorial, we'll explore how to retrieve Google SERP data, configure country and language parameters, paginate search results, and integrate a search API into PHP and Laravel applications using SerpScraper.dev.
1. What Is a Google Search API?
A Google Search API provides programmatic access to search result data through an HTTP interface.
Instead of downloading raw HTML and writing custom parsers, your application sends a query and receives structured data containing fields such as:
- Result titles and URLs
- Organic ranking positions
- Search snippets
- Related keywords and questions, where available
- Additional SERP features supported by the endpoint
This data can power many applications:
- SEO dashboards and keyword rank trackers
- Competitor analysis platforms
- Search monitoring and market research tools
- Content research automation
- AI agents and retrieval-augmented generation (RAG) pipelines
- Data enrichment and search intelligence services
It's important to distinguish a third-party SERP data API from Google's official Programmable Search products. Their coverage, response formats, and use cases can differ significantly.
For applications that need organic search results rather than a search experience restricted to configured websites, evaluate the available endpoints and their actual response data before choosing a provider.
2. Getting Started with SerpScraper.dev
SerpScraper.dev provides a REST API for retrieving structured search data from Google and other supported search sources.
The API handles the search data collection process, so you can focus on building your application instead of maintaining scraping infrastructure.
Getting started is straightforward:
- Create an account at SerpScraper.dev.
- Obtain your API token from the dashboard.
- Review the API documentation.
- Send your first search request.
- Process the returned JSON in your application.
New accounts receive 5,000 free credits at signup, with no credit card required. Check the current pricing plans for credit usage and plan limits.
3. Make Your First Google Search API Request
The Web Search API endpoint is:
GET https://serpscraper.dev/api/v1/webs-search
Let's start with a simple cURL request.
curl -G "https://serpscraper.dev/api/v1/webs-search" \
--data-urlencode "keyword=laravel seo" \
--data-urlencode "gl=US" \
--data-urlencode "hl=en" \
--data-urlencode "page=1" \
--data-urlencode "size=10" \
--data-urlencode "token=YOUR_API_KEY"
Replace YOUR_API_KEY with your actual API token.
The request uses several parameters:
| Parameter | Description | Example |
|---|---|---|
keyword |
Search query | laravel seo |
gl |
Target country | US |
hl |
Preferred result language | en |
page |
Results page | 1 |
size |
Requested results per page | 10 |
token |
API authentication token | Your API key |
The country and language parameters are useful when your application monitors keywords across multiple markets.
For example, the same query may return different websites when targeting the United States, the United Kingdom, or Vietnam.
For the complete parameter list and supported response fields, see the SerpScraper.dev documentation.
4. Working with JSON Search Results
The API returns a structured response with a request summary, endpoint-specific data, and timing information.
A simplified example of the response structure looks like this:
{
"request": {
"keyword": "laravel seo",
"page": 1,
"size": 10,
"gl": "US",
"hl": "en"
},
"data": {
"items": [
{
"position": 1,
"title": "Example SEO Guide",
"link": "https://example.com/seo-guide",
"description": "An example search result description."
}
]
},
"in_seconds": 0.31
}
This is an illustrative response, not a live API result. The exact fields depend on the endpoint and returned data.
Once the JSON is available, your application can save the results to a database, calculate ranking changes, generate reports, or pass selected fields to an AI model.
For a rank tracker, for example, you might store the keyword, search date, country, domain, URL, and ranking position. Comparing snapshots over time lets you identify changes that a single search cannot reveal.
5. Retrieving More Than 10 Search Results
One common challenge in SERP data collection is pagination.
Suppose you're building a rank-tracking tool and need to collect up to 100 organic search results for a keyword.
The size parameter controls how many results you request per page. SerpScraper.dev's documented Web Search API supports a size range of 1 to 100, while page determines which results page to retrieve.
For example, you can request 100 results using:
keyword=laravel seo
page=1
size=100
However, requesting 100 results doesn't guarantee that every query will return 100 organic results. The number actually returned depends on the available search data and endpoint behavior.
If you choose to retrieve 10 results per request, you can paginate through successive pages:
Page 1: Results 1–10
Page 2: Results 11–20
Page 3: Results 21–30
...
Page 10: Results 91–100
If every page returns 10 results, this approach requires approximately 10 requests to collect 100 results.
The API documentation specifies pagination and a maximum retrieval depth of 500 results per keyword. Check the current documentation for endpoint-specific details before designing a large-scale collection pipeline.
A Practical Pagination Strategy
Rather than assuming every request returns the requested number of results, build your pagination loop around the actual response:
- Request the first page.
- Extract the returned organic results.
- Store or process the results.
- Continue to the next page while more results are needed.
- Stop when the target is reached, the response contains no more results, or a configured limit is reached.
Also consider deduplicating results by URL. Search results can overlap or change between requests, particularly when collection takes place over an extended period.
6. Integrating Google Search API with Laravel
If you're developing with Laravel, its HTTP client provides a convenient way to call external APIs.
First, add your token to the .env file:
SERPSCRAPER_TOKEN=your_api_token
Then expose the value through config/services.php:
'serpscraper' => [
'token' => env('SERPSCRAPER_TOKEN'),
],
You can now make a request from your Laravel service:
use Illuminate\Support\Facades\Http;
$response = Http::timeout(15)
->get('https://serpscraper.dev/api/v1/webs-search', [
'keyword' => 'laravel seo',
'gl' => 'US',
'hl' => 'en',
'page' => 1,
'size' => 10,
'token' => config('services.serpscraper.token'),
]);
$response->throw();
$payload = $response->json();
$items = data_get($payload, 'data.items', []);
foreach ($items as $item) {
$position = data_get($item, 'position');
$title = data_get($item, 'title');
$url = data_get($item, 'link');
// Save or process the result.
}
This example demonstrates the integration pattern using the documented response structure. Verify the returned fields against the endpoint response when implementing your application.
A few production considerations are worth keeping in mind:
- Store API credentials in environment configuration or a secret manager.
- Never expose your API token in public frontend code.
- Set reasonable HTTP timeouts.
- Handle non-success HTTP responses.
- Retry transient failures with exponential backoff.
- Log request metadata without logging secret tokens.
- Respect your account's quota and rate limits.
If you prefer a client library, SerpScraper.dev also documents a PHP SDK.
Install it with Composer:
composer require tienphat/serpapi-php
The library provides a PHP-oriented interface for making search requests. Refer to the official documentation for the current SDK usage examples.
7. Estimating API Usage and Costs
Before launching a rank tracker or a large search data pipeline, estimate your expected request volume.
Consider an application that tracks 1,000 keywords daily.
If you request one page per keyword, that means 1,000 API requests per day. If you collect 10 pages for every keyword, the volume increases to 10,000 requests per day.
Your actual credit consumption also depends on how many results each request returns and the applicable credit rules.
According to the current Web Search API documentation, standard web search consumes one credit per 10 results returned, rounded up. For example:
| Results returned | Credit usage |
|---|---|
| 10 | 1 credit |
| 50 | 5 credits |
| 100 | 10 credits |
Empty pages do not consume credits under the documented rules. Review the pricing page for current plan allowances and any endpoint-specific differences.
For production workloads, monitor:
- Total credits consumed
- Successful and failed requests
- Results returned per query
- Average response time
- Retry frequency
- Cost per keyword or collection batch
These metrics help you estimate the actual cost of your application instead of relying on request counts alone.
8. Beyond Google Web Search
Organic search results are only one part of the search data ecosystem.
Depending on your application, you may also need:
- Image Search API for image discovery and metadata
- News Search API for news monitoring
- Shopping Search API for product research
- Scholar Search API for academic research workflows
- Maps Search API for local business data
- Autocomplete for keyword suggestions
- Google Trends data for trend monitoring
- Webpage extraction for structured page content
SerpScraper.dev provides multiple search and data intelligence endpoints through its API platform.
Explore the available APIs to see which endpoints match your application's requirements.
9. Final Thoughts
Building a search-powered application is much easier when data collection is separated from your core business logic.
Instead of maintaining a custom scraper, managing proxies, and parsing raw HTML yourself, you can use a SERP API to retrieve structured search data and focus on the features that matter to your users.
For PHP and Laravel developers, the integration can be as simple as an HTTP request, a JSON response, and a service class that handles pagination, errors, and storage.
If you're building an SEO tool, rank tracker, market research platform, or AI application, you can explore the Google Search API on SerpScraper.dev, review the API documentation, and start testing with the available free credits.
What are you building with search data? If you're working on a rank tracker, an SEO automation workflow, or an AI-powered research tool, share your use case and the challenges you're trying to solve.
Top comments (0)