Skip to content

Commit

Permalink
feat(document status): support external id and instance id
Browse files Browse the repository at this point in the history
  • Loading branch information
andersfylling committed Nov 24, 2024
1 parent 829f051 commit e533c89
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cognite/client/_api/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from cognite.client._constants import DEFAULT_LIMIT_READ
from cognite.client.data_classes import filters
from cognite.client.data_classes.aggregations import AggregationFilter, UniqueResultList
from cognite.client.data_classes.data_modeling.ids import NodeId
from cognite.client.data_classes.documents import (
Document,
DocumentHighlightList,
Expand All @@ -19,6 +20,7 @@
TemporaryLink,
)
from cognite.client.data_classes.filters import _BASIC_FILTERS, Filter, _validate_filter
from cognite.client.utils._identifier import IdentifierSequence

if TYPE_CHECKING:
from cognite.client import ClientConfig, CogniteClient
Expand Down Expand Up @@ -475,7 +477,12 @@ def aggregate_unique_properties(
limit=limit,
)

def retrieve_content(self, id: int) -> bytes:
def retrieve_content(
self,
id: int | None = None,
external_id: str | None = None,
instance_id: NodeId | None = None,
) -> bytes:
"""`Retrieve document content <https://developer.cognite.com/api#tag/Documents/operation/documentsContent>`_
Returns extracted textual information for the given document.
Expand All @@ -487,7 +494,9 @@ def retrieve_content(self, id: int) -> bytes:
Args:
id (int): The server-generated ID for the document you want to retrieve the content of.
id (int | None): The server-generated ID for the document you want to retrieve the content of.
external_id (str | None): External ID
instance_id (NodeId | None): Instance ID
Returns:
bytes: The content of the document.
Expand All @@ -500,7 +509,9 @@ def retrieve_content(self, id: int) -> bytes:
>>> client = CogniteClient()
>>> content = client.documents.retrieve_content(id=123)
"""
response = self._do_request("POST", f"{self._RESOURCE_PATH}/content", accept="text/plain", json={"id": id})
identifiers = IdentifierSequence.load(ids=id, external_ids=external_id, instance_ids=instance_id).as_singleton()
identifier = identifiers.as_dicts()[0]
response = self._do_request("POST", f"{self._RESOURCE_PATH}/content", accept="text/plain", json=identifier)
return response.content

def retrieve_content_buffer(self, id: int, buffer: BinaryIO) -> None:
Expand Down

0 comments on commit e533c89

Please sign in to comment.