Enhance Your App with Real-Time Events Search Cognitive Actions

22 Apr 2025
Enhance Your App with Real-Time Events Search Cognitive Actions

Introduction

In today's fast-paced world, providing users with real-time information about events can significantly enhance their experience. The Real-Time Events Search API offers a set of powerful Cognitive Actions designed to help developers seamlessly integrate event search functionalities into their applications. These pre-built actions allow for quick retrieval of event details and the ability to find local events, making it easier than ever to keep users informed about concerts, sports, workshops, and festivals.

Prerequisites

Before diving into the integration of Cognitive Actions, ensure you have the following prerequisites:

  • API Key: You will need an API key for authenticating your requests. This key should be included in the headers of your API calls.
  • Basic Understanding of JSON: Familiarity with JSON will be helpful for constructing input payloads and handling outputs.

Authentication typically involves passing your API key in the request headers, allowing you to securely access the functionalities offered by the API.

Cognitive Actions Overview

Retrieve Event Details

The Retrieve Event Details action allows developers to fetch detailed information about a specific event using its unique Event ID, enabling real-time access to local and online events.

  • Category: Search Operations

Input

The input schema requires a single field:

  • eventId (required): A string that uniquely identifies the event.

Example Input:

{
  "eventId": "L2F1dGhvcml0eS9ob3Jpem9uL2NsdXN0ZXJlZF9ldmVudC8yMDI0LTExLTIyfDE2OTA0Nzc5MjUwNzQwODY5OTc4"
}

Output

The action typically returns a status along with parameters that include the event ID.

Example Output:

{
  "status": "OK",
  "parameters": {
    "event_id": "L2F1dGhvcml0eS9ob3Jpem9uL2NsdXN0ZXJlZF9ldmVudC8yMDI0LTExLTIyfDE2OTA0Nzc5MjUwNzQwODY5OTc4"
  },
  "request_id": "3812831b-8fbf-4c30-b70b-7d4f6e653d65"
}

Conceptual Usage Example (Python)

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "a5d42300-8f65-4b4b-896c-e255ec6789bf" # Action ID for Retrieve Event Details

# Construct the input payload based on the action's requirements
payload = {
    "eventId": "L2F1dGhvcml0eS9ob3Jpem9uL2NsdXN0ZXJlZF9ldmVudC8yMDI0LTExLTIyfDE2OTA0Nzc5MjUwNzQwODY5OTc4"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload} # Hypothetical structure
    )
    response.raise_for_status()

    result = response.json()
    print("Action executed successfully:")
    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: {e.response.text}")

In this example, replace the action ID and the input payload according to the requirements of the action.


Find Local Events

The Find Local Events action allows developers to search for local public events in real-time, with support for various filters and options.

  • Category: Events

Input

The input schema includes several fields:

  • query (required): The search term to find relevant events.
  • date (optional): A date filter for the query with options such as "today", "weekend", etc.
  • isVirtual (optional): A boolean to filter for virtual events only.
  • startIndex (optional): Starting index for paginated results.

Example Input:

{
  "date": "any",
  "query": "Concerts in San-Francisco",
  "isVirtual": false,
  "startIndex": 0
}

Output

The output typically returns a list of events that match the search criteria.

Example Output:

{
  "status": "OK",
  "data": [
    {
      "link": "https://www.unation.com/event/yefim-bronfman-56536134/",
      "name": "Yefim Bronfman",
      ...
    }
    ...
  ],
  "request_id": "0fd5d6f5-ee2a-43c5-9d5c-4198e649a750"
}

Conceptual Usage Example (Python)

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "ca4ce980-933b-42ca-96ba-d17cffecfa22" # Action ID for Find Local Events

# Construct the input payload based on the action's requirements
payload = {
    "date": "any",
    "query": "Concerts in San-Francisco",
    "isVirtual": False,
    "startIndex": 0
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload} # Hypothetical structure
    )
    response.raise_for_status()

    result = response.json()
    print("Action executed successfully:")
    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: {e.response.text}")

In this conceptual example, adjust the action ID and input payload to fit the specific action requirements.

Conclusion

Integrating the Real-Time Events Search Cognitive Actions into your applications can significantly enhance user engagement by providing immediate access to event information. Whether you're retrieving detailed event information or finding local events, these actions simplify the process, making it easier for developers to enrich their applications with real-time data. Explore the possibilities and start creating dynamic event-driven experiences for your users today!