@@ -1264,6 +1264,99 @@ async def main():
12641264 yield child
12651265
12661266
1267+ async def get_child (
1268+ entity_name : str ,
1269+ parent_id : Optional [str ] = None ,
1270+ * ,
1271+ synapse_client : Optional ["Synapse" ] = None ,
1272+ ) -> Optional [str ]:
1273+ """
1274+ Retrieve an entityId for a given parent ID and entity name.
1275+
1276+ This service can also be used to lookup projectId by setting the parentId to None.
1277+
1278+ This calls to the REST API found here: <https://rest-docs.synapse.org/rest/POST/entity/child.html>
1279+
1280+ Arguments:
1281+ entity_name: The name of the entity to find
1282+ parent_id: The parent ID. Set to None when looking up a project by name.
1283+ synapse_client: If not passed in and caching was not disabled by
1284+ `Synapse.allow_client_caching(False)` this will use the last created
1285+ instance from the Synapse class constructor.
1286+
1287+ Returns:
1288+ The entity ID if found, None if not found.
1289+
1290+ Raises:
1291+ SynapseHTTPError: If there's an error other than "not found" (404).
1292+
1293+ Example: Getting a child entity ID
1294+ Find a file by name within a folder:
1295+
1296+ ```python
1297+ import asyncio
1298+ from synapseclient import Synapse
1299+ from synapseclient.api import get_child
1300+
1301+ syn = Synapse()
1302+ syn.login()
1303+
1304+ async def main():
1305+ entity_id = await get_child(
1306+ entity_name="my_file.txt",
1307+ parent_id="syn123456"
1308+ )
1309+ if entity_id:
1310+ print(f"Found entity: {entity_id}")
1311+ else:
1312+ print("Entity not found")
1313+
1314+ asyncio.run(main())
1315+ ```
1316+
1317+ Example: Getting a project by name
1318+ Find a project by name:
1319+
1320+ ```python
1321+ import asyncio
1322+ from synapseclient import Synapse
1323+ from synapseclient.api import get_child
1324+
1325+ syn = Synapse()
1326+ syn.login()
1327+
1328+ async def main():
1329+ project_id = await get_child(
1330+ entity_name="My Project",
1331+ parent_id=None # None for projects
1332+ )
1333+ if project_id:
1334+ print(f"Found project: {project_id}")
1335+
1336+ asyncio.run(main())
1337+ ```
1338+ """
1339+ from synapseclient import Synapse
1340+
1341+ client = Synapse .get_client (synapse_client = synapse_client )
1342+
1343+ entity_lookup_request = {
1344+ "parentId" : parent_id ,
1345+ "entityName" : entity_name ,
1346+ }
1347+
1348+ try :
1349+ response = await client .rest_post_async (
1350+ uri = "/entity/child" , body = json .dumps (entity_lookup_request )
1351+ )
1352+ return response .get ("id" )
1353+ except SynapseHTTPError as e :
1354+ if e .response .status_code == 404 :
1355+ # Entity not found
1356+ return None
1357+ raise
1358+
1359+
12671360async def set_entity_permissions (
12681361 entity_id : str ,
12691362 principal_id : Optional [str ] = None ,
0 commit comments