Skip to content

Commit 1dbe051

Browse files
committed
Request randomly generated ID when creating item with no set ID
1 parent 6811c1a commit 1dbe051

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/datalab_api/__init__.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
import warnings
23
from collections.abc import Iterable
34
from pathlib import Path
@@ -102,15 +103,15 @@ def search_items(
102103

103104
def create_item(
104105
self,
105-
item_id: str,
106-
item_type: str,
107-
item_data: Optional[dict[str, Any]] = None,
108-
collection_id: Optional[str] = None,
106+
item_id: str | None = None,
107+
item_type: str = "samples",
108+
item_data: dict[str, Any] | None = None,
109+
collection_id: str | None = None,
109110
) -> dict[str, Any]:
110111
"""Create an item with a given ID and item data.
111112
112113
Parameters:
113-
item_id: The ID of the item to create.
114+
item_id: The ID of the item to create, if set to `None`, the server will generate one.
114115
item_type: The type of item to create, e.g., 'samples', 'cells'.
115116
item_data: The data for the item.
116117
collection_id: The ID of the collection to add the item to (optional).
@@ -133,7 +134,7 @@ def create_item(
133134
create_item_url = f"{self.datalab_api_url}/new-sample/"
134135
create_item_resp = self.session.post(
135136
create_item_url,
136-
json=new_item,
137+
json={"new_sample_data": new_item, "generate_id_automatically": item_id is None},
137138
follow_redirects=True,
138139
)
139140
try:

0 commit comments

Comments
 (0)