Enhance Your Applications with Real-Time Web Search Capabilities

6 Aug 2025
Enhance Your Applications with Real-Time Web Search Capabilities

The Real Time Web Search API offers developers a robust solution for integrating real-time search functionalities into their applications. By harnessing the power of Google's advanced search capabilities, this API enables users to retrieve structured, relevant information quickly and efficiently. With ultra-fast response times and scalable performance, it simplifies the process of gathering data from the web, making it a valuable tool for a variety of use cases.

Imagine a scenario where users can effortlessly find the latest information on a topic, whether it's for research, news aggregation, or content creation. The Real Time Web Search API allows developers to build applications that provide users with immediate access to the most relevant search results, enhancing user experience and engagement. This API is perfect for chatbots, virtual assistants, content management systems, and any application requiring up-to-date information from the web.

Before diving into the implementation, ensure you have your Cognitive Actions API key and a basic understanding of making API calls.

Conduct Google AI Query

The "Conduct Google AI Query" action allows developers to send a prompt or question to receive structured results and reference links using Google's AI Mode. This action excels in delivering ultra-fast and scalable web search results, making it ideal for applications that require semantic search capabilities.

Input Requirements

To use this action, you need to provide:

  • Prompt: The main question or input text for the search (e.g., "How to make a pizza step by step?").
  • Language: The language code for the response, following ISO 639-1 format (default is "en").
  • GeoLocation: The geographical location code influencing the response (default is "us").
  • Session Token: A token for maintaining session state across requests (default is an empty string).

Expected Output

The output will include a structured response with:

  • A detailed reply broken down into parts (headings, paragraphs, lists).
  • Reference links for additional context and information.
  • A session token for continuity in interaction.

Use Cases for this Specific Action

This action is particularly useful for:

  • Educational Platforms: Providing step-by-step guides or explanations on various topics.
  • Customer Support Bots: Answering frequently asked questions with comprehensive responses.
  • Content Creation Tools: Assisting writers by generating ideas or outlines based on user prompts.

```python
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "3fee2acf-ae96-4583-bba2-5253e620847d" # Action ID for: Conduct Google AI Query

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "prompt": "How to make a pizza step by step?",
  "language": "en",
  "geoLocation": "us"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body (non-JSON): {e.response.text}")
    print("------------------------------------------------")


## Execute Real-Time Web Search

The "Execute Real-Time Web Search" action enables developers to fetch real-time organic search results from across the web using Google Search features and advanced operators. This action supports geo-targeting and customizable search parameters, including the ability to fetch AI-generated overviews.

### Input Requirements
To utilize this action, you need to specify:
- **Query**: The main search query string (e.g., "how to build a website").
- **Device**: Specify the type of device (either "desktop" or "mobile").
- **Language**: The language code for the query (default is "en").
- **Geolocation**: The geographical area for the search (default is "us").
- **Number of Results**: The quantity of results to return (default is 10).

### Expected Output
The output will consist of:
- A list of search results, each containing a URL, title, domain, and a brief snippet.
- An indication of the request status.

### Use Cases for this Specific Action
This action can be effectively used in:
- **Market Research Tools**: Quickly gathering competitive analysis data from various sources.
- **News Aggregators**: Curating the latest articles or blog posts on trending topics.
- **SEO Tools**: Analyzing search results to optimize content strategies based on real-time data.

import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "623b09b1-961b-4b87-9845-c75e6109d7ea" # Action ID for: Execute Real-Time Web Search

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "query": "how to build a website",
  "device": "desktop",
  "language": "en",
  "geolocation": "us",
  "numberOfResults": 10,
  "noFamilyPlanResult": "0"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body (non-JSON): {e.response.text}")
    print("------------------------------------------------")


## Conclusion

The Real Time Web Search API empowers developers to integrate powerful search functionalities into their applications, enhancing user experience by providing fast and relevant information. With actions like "Conduct Google AI Query" and "Execute Real-Time Web Search," you can create dynamic applications that meet the needs of users in various contexts, from education to market research. 

Next steps include exploring how to implement these actions in your projects, testing different input parameters, and evaluating the results to maximize the API's potential. Embrace the power of real-time data and elevate your applications to new heights!