Enhance Travel Experiences with the Comprehensive Flight And Travel API

8 Jun 2025
Enhance Travel Experiences with the Comprehensive Flight And Travel API

The Comprehensive Flight And Travel API provides a robust set of tools that empower developers to create seamless travel experiences for users. With real-time data from various travel platforms, including flight information, hotel bookings, and location services, this API simplifies the complexities of travel planning. By integrating these Cognitive Actions, developers can enhance their applications with features like flight searches, booking autocompletes, and nearby hotel searches, ultimately improving user satisfaction and engagement.

Use Cases

Imagine building a travel booking application that allows users to easily search for flights, find hotels nearby, and receive real-time updates on flight prices. Whether it's for a vacation, business trip, or an impromptu getaway, the Comprehensive Flight And Travel API can streamline the entire travel planning process, making it more efficient and user-friendly.

Fetch Supported Languages

This action retrieves a list of supported languages for various services, ensuring that users can interact with the travel services in their preferred language. This is crucial for enhancing user experience and accessibility.

  • Input Requirements: No specific input is required for this action.
  • Expected Output: A list of supported languages along with their codes.

Use Cases for this action: Use this action when you need to provide users with language options in your application, especially when dealing with international travelers who may prefer different languages.


```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 = "1f7ce008-be92-415c-b623-a744f28ed7f4" # Action ID for: Fetch Supported Languages

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {}

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("------------------------------------------------")


## Perform Booking Autocomplete
This action enables autocomplete functionality for flight, hotel, and car rental searches, using real-time data from Booking.com and other platforms. This feature significantly enhances search efficiency by predicting user input.

- **Input Requirements:** 
  - `query`: The search term or location query (e.g., "New York").
  - `languageCode`: The code representing the language for the query.

- **Expected Output:** A list of suggested locations matching the user's query, including details such as city names and types.

**Use Cases for this action:** Ideal for applications that require quick and efficient search functionalities, allowing users to find what they are looking for without typing out the full names.

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 = "64766707-8893-4749-92d9-485dc57360b5" # Action ID for: Perform Booking Autocomplete

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "query": "New York"
}

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("------------------------------------------------")


## Retrieve Flight Price Calendar
This action fetches flight prices for a specified return journey, drawing data from multiple airlines. It assists users in finding the best deals by comparing prices over a set period.

- **Input Requirements:**
  - `originEntityId`: Identifier for the origin location.
  - `destinationEntityId`: Identifier for the destination location.
  - `departureDate`: The set departure date.
  - `returnDate`: The set return date.

- **Expected Output:** A calendar view of flight prices, allowing users to see price fluctuations and choose the best times to travel.

**Use Cases for this action:** Perfect for travel applications that assist users in planning their trips based on budget constraints, enabling them to select the most cost-effective travel dates.

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 = "752891eb-5b27-46aa-82ba-b19ccb264262" # Action ID for: Retrieve Flight Price Calendar

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "returnDate": "2025-08",
  "departureDate": "2025-07",
  "originEntityId": "YUL",
  "destinationEntityId": "ABJ"
}

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("------------------------------------------------")


## Search One-Way Flights
This action allows users to search for one-way flights with flexible options for departure dates and destinations using real-time data from multiple airlines.

- **Input Requirements:**
  - `originEntityId`: Identifier for the origin location.
  - `departDate`: The intended departure date.

- **Expected Output:** A list of available one-way flights along with pricing and airline information.

**Use Cases for this action:** Useful for applications targeting users who prefer one-way travel, enabling them to find the best options quickly.

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 = "753d3b77-0b2d-430c-919c-56a7ada69cee" # Action ID for: Search One-Way Flights

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "originEntityId": "PARI"
}

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("------------------------------------------------")


## Search Google Flights Locations
This action retrieves location information using Google's unofficial flights API, allowing users to compare international flight options, hotel deals, and car rentals.

- **Input Requirements:** No specific input is required for this action.
- **Expected Output:** A list of locations with their corresponding codes.

**Use Cases for this action:** Beneficial for travel applications that need to provide users with a comprehensive list of destinations to choose from, enhancing the booking experience.

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 = "a91d08a4-8949-4bfe-aea8-0f620bff986c" # Action ID for: Search Google Flights Locations

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {}

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("------------------------------------------------")


## Find Nearby Hotels on Map
This action searches for and displays nearby hotels based on latitude and longitude coordinates, supporting real-time data retrieval for hotels.

- **Input Requirements:**
  - `latitude`: Latitude coordinate for the location.
  - `longitude`: Longitude coordinate for the location.
  - `entityIdentifier`: Identifier for the specific entity related to the query.

- **Expected Output:** A map displaying nearby hotels along with their details.

**Use Cases for this action:** Ideal for travel applications that want to provide users with real-time hotel options based on their current location, enhancing the convenience of booking accommodations.

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 = "bab0adca-5020-4588-b1f4-afcff8d904f7" # Action ID for: Find Nearby Hotels on Map

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "latitude": "40.7591608",
  "longitude": "-73.9954657",
  "entityIdentifier": "27537542"
}

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
Integrating the Comprehensive Flight And Travel API into your applications can significantly enhance the travel experience for users by simplifying the search and booking processes. With features for language support, autocomplete options, price comparisons, and real-time hotel searches, developers can create intuitive and efficient travel applications. Start exploring these actions to elevate your travel solutions today!