Skip to main content

Views

Overview​

The Views module provides methods to interact with views in the BuiltAPI platform. This module allows you to list, retrieve, create, update, and remove views.

Methods​

list​

List views with optional search and ordering.

Parameters​

  • entity_id (str): The ID of the entity.
  • skip (Optional[int]): Number of views to skip. Default is 0.
  • take (Optional[int]): Number of views to take. Default is 100.
  • search (Optional[Dict[str, Any]]): Search criteria.
  • orderBy (Optional[List[Dict[str, str]]]): Ordering criteria.

Returns​

  • ViewsList: A list of views.

Example​

from builtapi import BuiltAPI

client = BuiltAPI()
views = client.views.list(
entity_id='entity_id',
skip=0,
take=50,
search={'name': 'example'},
orderBy=[{'name': 'asc'}, {'createdAt': 'desc'}]
)
print(views)

list_by_workspace​

List views by workspace with optional search and ordering.

Parameters​

  • skip (Optional[int]): Number of views to skip. Default is 0.
  • take (Optional[int]): Number of views to take. Default is 100.
  • search (Optional[Dict[str, Any]]): Search criteria.
  • orderBy (Optional[List[Dict[str, str]]]): Ordering criteria.

Returns​

  • ViewsList: A list of views in the workspace.

Example​

from builtapi import BuiltAPI

client = BuiltAPI()
views = client.views.list_by_workspace(
skip=0,
take=50,
search={'name': 'example'},
orderBy=[{'name': 'asc'}, {'createdAt': 'desc'}]
)
print(views)

get_one_by_id​

Retrieve a single view by its ID.

Parameters​

  • view_id (str): The ID of the view to retrieve.

Returns​

  • View: The view with the specified ID.

Example​

from builtapi import BuiltAPI

client = BuiltAPI()
view = client.views.get_one_by_id(view_id='view_id')
print(view)

get_schema​

Retrieve the schema of a view.

Parameters​

  • view_id (str): The ID of the view.

Returns​

  • ViewSchema: The schema of the view.

Example​

from builtapi import BuiltAPI

client = BuiltAPI()
view_schema = client.views.get_schema(view_id='view_id')
print(view_schema)

create​

Create a new view.

Parameters​

  • entity_id (str): The ID of the entity.
  • name (str): The name of the view.
  • pipeline (List[Dict]): The pipeline for the view.

Returns​

  • View: The newly created view.

Example​

from builtapi import BuiltAPI

client = BuiltAPI()
new_view = client.views.create(
entity_id='entity_id',
name='New View',
pipeline=[{'$match': {'field1': 'value1'}}]
)
print(new_view)

update​

Update an existing view.

Parameters​

  • view_id (str): The ID of the view to update.
  • name (str): The new name of the view.
  • pipeline (List[Dict]): The new pipeline for the view.

Returns​

  • views_schemas.View: The updated view.

Example​

from builtapi import BuiltAPI

client = BuiltAPI()
updated_view = client.views.update(
view_id='view_id',
name='Updated View',
pipeline=[{'$match': {'field1': 'new_value1'}}]
)
print(updated_view)

remove​

Remove a view by its ID.

Parameters​

  • view_id (str): The ID of the view to remove.

Returns​

  • View: The removed view.

Example​

from builtapi import BuiltAPI

client = BuiltAPI()
removed_view = client.views.remove(view_id='view_id')
print(removed_view)

get_records​

List records with optional search and ordering.

Parameters​

  • view_id (str): The ID of the entity.
  • filter (Optional[Dict[str, Any]]): Filter object.
  • take (int): Number of records to take. Default is 100.
  • skip (int): Number of records to skip. Default is 0.
  • sort (Optional[Dict[str, str]]): Sorting object.
  • projection (Optional[Dict[str, bool]]): Fields to include or exclude.

Returns​

  • ViewRecordsList: A list of records.

Example​

from builtapi import BuiltAPI

client = BuiltAPI()
records = client.views.get_records(
view_id='view_id',
filter={'field1': 'value'},
take=50,
skip=0,
sort={'field1': 'asc'},
projection={'field1': True, 'field2': False}
)
print(records)

get_records_total​

Return total number of records.

Parameters​

  • view_id (str): The ID of the entity.
  • filter (Optional[Dict[str, Any]]): Filter object.
  • projection (Optional[Dict[str, bool]]): Fields to include or exclude.

Returns​

  • int: Total number of records.

Example​

from builtapi import BuiltAPI

client = BuiltAPI()
records_total = client.views.get_records_total(
view_id='view_id',
filter={'field1': 'value'}
)
print(records_total)

Schemas​

View​

{ id: str createdAt: str updatedAt: str name: str pipeline: List[Dict] entityId: str }

ViewList​

{ skip: int take: int count: int total: int items: List[View] }

ViewSchema​

{ count: Optional[Union[int, None]] = None fields: [ { name: str path: List[str] count: int type: str probability: int has_duplicates: bool types: List[Dict] } ] }