From fddbe2379aa229b1105ce4cadf97e4d2751a5c6f Mon Sep 17 00:00:00 2001 From: Hagen Fritz Date: Tue, 13 May 2025 12:51:38 -0500 Subject: [PATCH 1/2] feat: bump to v0.6.3 --- CHANGELOG.md | 7 ++++++- ProPyCore/__init__.py | 2 +- setup.py | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 969fc88..5171771 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,14 @@ # Changelog -## [0.6.2] - 2025-05-13 +## [0.6.3] - 2025-05-13 ### Added * `documents.files`: add `view` parameter to `get()` and `search()` methods +* `documents.files`: add `file_types` parameter to `get()` and `search()` methods +* `documents.files`: add `private` parameter to `get()` method + +### Changed +* `base`: remove debug print statements ## [0.6.1] - 2025-05-07 diff --git a/ProPyCore/__init__.py b/ProPyCore/__init__.py index b0c6774..ca21a6c 100644 --- a/ProPyCore/__init__.py +++ b/ProPyCore/__init__.py @@ -3,4 +3,4 @@ from .exceptions import * from .procore import Procore -__version__ = "0.6.2" \ No newline at end of file +__version__ = "0.6.3" \ No newline at end of file diff --git a/setup.py b/setup.py index a919f8b..f23844a 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name="ProPyCore", - version="0.6.2", + version="0.6.3", author="Hagen E. Fritz", author_email="hfritz@r-o.com", description="Interact with Procore through Python for data connection applications", From 6448f4a7a913fa28d89c7bc678485cab5df8f993 Mon Sep 17 00:00:00 2001 From: Hagen Fritz Date: Tue, 13 May 2025 12:52:03 -0500 Subject: [PATCH 2/2] feat: add more filter params --- ProPyCore/access/base.py | 7 +- ProPyCore/access/documents/files.py | 12 +- snippets/documents.ipynb | 208 +++++++++++++++++++--------- 3 files changed, 157 insertions(+), 70 deletions(-) diff --git a/ProPyCore/access/base.py b/ProPyCore/access/base.py index fce146f..9ae0504 100644 --- a/ProPyCore/access/base.py +++ b/ProPyCore/access/base.py @@ -43,7 +43,7 @@ def get_request(self, api_url, additional_headers=None, params=None): if params is None: url = self.__server_url + api_url else: - url = self.__server_url + api_url + "?" + urllib.parse.urlencode(params) + url = self.__server_url + api_url + "?" + urllib.parse.urlencode(params, doseq=True) headers = {"Authorization": f"Bearer {self.__access_token}"} if additional_headers is not None: @@ -51,11 +51,6 @@ def get_request(self, api_url, additional_headers=None, params=None): headers[key] = value response = requests.get(url, headers=headers) - ''' - print(f"Request URL: {response.request.url}") - print(f"Request Headers: {response.request.headers}") - print(f"Request Response: {response.json()}") - ''' if response.ok: return response.json() diff --git a/ProPyCore/access/documents/files.py b/ProPyCore/access/documents/files.py index a1ce1dd..9a8aa96 100644 --- a/ProPyCore/access/documents/files.py +++ b/ProPyCore/access/documents/files.py @@ -225,7 +225,7 @@ def remove(self, company_id, project_id, doc_id): return doc_info - def get(self, company_id, project_id, folder_id=None, view="normal"): + def get(self, company_id, project_id, folder_id=None, view="normal", file_types=None): """ Gets all documents in a project. @@ -239,6 +239,8 @@ def get(self, company_id, project_id, folder_id=None, view="normal"): ID of parent folder. view : str, default "normal" View to use for the request: "normal" or "extended" + file_types : list of str, default None + List of file type extensions to filter by. Returns ------- @@ -258,9 +260,12 @@ def get(self, company_id, project_id, folder_id=None, view="normal"): "per_page": 10000, "filters[document_type]": doc_type, "filters[is_in_recycle_bin]": False, + "filters[private]": False, } if folder_id is not None: params["filters[folder_id]"] = folder_id + if file_types is not None: + params["filters[file_type]"] = file_types headers = { "Procore-Company-Id": f"{company_id}", @@ -288,7 +293,7 @@ def get(self, company_id, project_id, folder_id=None, view="normal"): f"from Parent ID {folder_id if folder_id is not None else 'Root'}", ) - def search(self, company_id, project_id, value, folder_id=None, view="normal"): + def search(self, company_id, project_id, value, folder_id=None, view="normal", file_types=[]): """ Searches through all available files to find the closest match to the given value. @@ -302,6 +307,8 @@ def search(self, company_id, project_id, value, folder_id=None, view="normal"): Search criteria. folder_id : int, default None ID of parent folder. + file_types : list of str, default [] + List of file type extensions to filter by. Returns ------- @@ -313,6 +320,7 @@ def search(self, company_id, project_id, value, folder_id=None, view="normal"): project_id=project_id, folder_id=folder_id, view=view, + file_types=file_types, ) doc_type = self.endpoint.split("/")[-1][:-1] diff --git a/snippets/documents.ipynb b/snippets/documents.ipynb index b01b313..95625b5 100644 --- a/snippets/documents.ipynb +++ b/snippets/documents.ipynb @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -39,7 +39,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -63,7 +63,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -79,7 +79,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -115,9 +115,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 1\n", + "[{'id': 816142268, 'created_at': '2024-07-17T20:56:14Z', 'created_by': {'id': 6036589, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'sthompson@r-o.com', 'name': 'Scott Thompson'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': '03-Concrete', 'name_with_path': 'Sandbox Test Project/C-Field Use Documents/03-Concrete', 'parent_id': 771257695, 'private': False, 'read_only': False, 'updated_at': '2024-07-17T20:56:14Z'}, {'id': 845915608, 'created_at': '2024-10-02T15:48:01Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': '1-PreTask Planning', 'name_with_path': 'Sandbox Test Project/G-Safety and Environmental/1-PreTask Planning', 'parent_id': 771257651, 'private': False, 'read_only': False, 'updated_at': '2024-10-02T15:48:01Z'}, {'id': 900849253, 'created_at': '2025-02-26T21:22:55Z', 'created_by': {'id': 8780450, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': '', 'login': 'hfritz@r-o.com', 'name': 'Hagen Fritz'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': '1-Prime Contract', 'name_with_path': 'Sandbox Test Project/I-Contracts and PayApps/1-Prime Contract', 'parent_id': 771257573, 'private': False, 'read_only': False, 'updated_at': '2025-02-26T21:22:55Z'}, {'id': 845915794, 'created_at': '2024-10-02T15:48:25Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': '10-Sign In Sheets', 'name_with_path': 'Sandbox Test Project/G-Safety and Environmental/10-Sign In Sheets', 'parent_id': 771257651, 'private': False, 'read_only': False, 'updated_at': '2024-10-02T15:48:25Z'}, {'id': 845915709, 'created_at': '2024-10-02T15:48:14Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': '3-Orientations and Training', 'name_with_path': 'Sandbox Test Project/G-Safety and Environmental/3-Orientations and Training', 'parent_id': 771257651, 'private': False, 'read_only': False, 'updated_at': '2024-10-02T15:48:14Z'}, {'id': 771257697, 'created_at': '2024-03-20T20:39:58Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': 'A-Drawings and Specs', 'name_with_path': 'Sandbox Test Project/A-Drawings and Specs', 'parent_id': 771257538, 'private': True, 'read_only': False, 'updated_at': '2024-03-20T20:39:58Z'}, {'id': 771257698, 'created_at': '2024-03-20T20:39:58Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': 'B-Preconstruction', 'name_with_path': 'Sandbox Test Project/B-Preconstruction', 'parent_id': 771257538, 'private': True, 'read_only': False, 'updated_at': '2024-03-20T20:39:58Z'}, {'id': 771257695, 'created_at': '2024-03-20T20:39:58Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': 'C-Field Use Documents', 'name_with_path': 'Sandbox Test Project/C-Field Use Documents', 'parent_id': 771257538, 'private': False, 'read_only': False, 'updated_at': '2024-03-20T20:39:58Z'}, {'id': 771257692, 'created_at': '2024-03-20T20:39:58Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': 'D-Schedule', 'name_with_path': 'Sandbox Test Project/D-Schedule', 'parent_id': 771257538, 'private': True, 'read_only': False, 'updated_at': '2024-03-20T20:39:58Z'}, {'id': 771257691, 'created_at': '2024-03-20T20:39:58Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': 'E-QC, Reports and Logs', 'name_with_path': 'Sandbox Test Project/E-QC, Reports and Logs', 'parent_id': 771257538, 'private': True, 'read_only': False, 'updated_at': '2024-03-20T20:39:58Z'}, {'id': 771257689, 'created_at': '2024-03-20T20:39:58Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': 'F-Meeting Minutes', 'name_with_path': 'Sandbox Test Project/F-Meeting Minutes', 'parent_id': 771257538, 'private': True, 'read_only': False, 'updated_at': '2024-03-20T20:39:58Z'}, {'id': 771257651, 'created_at': '2024-03-20T20:39:55Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': 'G-Safety and Environmental', 'name_with_path': 'Sandbox Test Project/G-Safety and Environmental', 'parent_id': 771257538, 'private': True, 'read_only': False, 'updated_at': '2024-03-20T20:39:55Z'}, {'id': 771257574, 'created_at': '2024-03-20T20:39:46Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': 'H-VDC', 'name_with_path': 'Sandbox Test Project/H-VDC', 'parent_id': 771257538, 'private': False, 'read_only': False, 'updated_at': '2024-03-20T20:39:46Z'}, {'id': 771257573, 'created_at': '2024-03-20T20:39:46Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': 'I-Contracts and PayApps', 'name_with_path': 'Sandbox Test Project/I-Contracts and PayApps', 'parent_id': 771257538, 'private': True, 'read_only': False, 'updated_at': '2024-03-20T20:39:46Z'}, {'id': 771257572, 'created_at': '2024-03-20T20:39:46Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': 'J-LEED', 'name_with_path': 'Sandbox Test Project/J-LEED', 'parent_id': 771257538, 'private': True, 'read_only': False, 'updated_at': '2024-03-20T20:39:46Z'}, {'id': 771257571, 'created_at': '2024-03-20T20:39:46Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': 'K-Correspondence', 'name_with_path': 'Sandbox Test Project/K-Correspondence', 'parent_id': 771257538, 'private': True, 'read_only': False, 'updated_at': '2024-03-20T20:39:46Z'}, {'id': 771257569, 'created_at': '2024-03-20T20:39:46Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': 'L-Close Out', 'name_with_path': 'Sandbox Test Project/L-Close Out', 'parent_id': 771257538, 'private': True, 'read_only': False, 'updated_at': '2024-03-20T20:39:46Z'}, {'id': 771257566, 'created_at': '2024-03-20T20:39:46Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': 'M-Project Performance Plan', 'name_with_path': 'Sandbox Test Project/M-Project Performance Plan', 'parent_id': 771257538, 'private': True, 'read_only': False, 'updated_at': '2024-03-20T20:39:46Z'}, {'id': 771257567, 'created_at': '2024-03-20T20:39:46Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': 'N-Project Status Summary', 'name_with_path': 'Sandbox Test Project/N-Project Status Summary', 'parent_id': 771257538, 'private': True, 'read_only': False, 'updated_at': '2024-03-20T20:39:46Z'}, {'id': 772736983, 'created_at': '2024-03-25T16:49:00Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': 'Nick Vargo Test Files', 'name_with_path': 'Sandbox Test Project/Z-Temp Items/Nick Vargo Test Files', 'parent_id': 771257568, 'private': False, 'read_only': False, 'updated_at': '2024-03-25T16:49:00Z'}, {'id': 771257538, 'created_at': '2024-03-20T20:39:40Z', 'created_by': {'id': 1, 'company_name': None, 'locale': '', 'login': None, 'name': 'Customer Support'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': 'Sandbox Test Project', 'name_with_path': 'Sandbox Test Project', 'parent_id': None, 'private': False, 'read_only': False, 'updated_at': '2024-03-20T20:39:40Z'}, {'id': 929510260, 'created_at': '2025-05-13T17:48:59Z', 'created_by': {'id': 9486187, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': None, 'login': 'ro-data-connection-0a813c91@procore.com', 'name': 'R&D Data Connection'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': 'Z-Research and Development', 'name_with_path': 'Sandbox Test Project/Z-Research and Development', 'parent_id': 771257538, 'private': False, 'read_only': False, 'updated_at': '2025-05-13T17:48:59Z'}, {'id': 771257568, 'created_at': '2024-03-20T20:39:46Z', 'created_by': {'id': 3238394, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'nvargo@r-o.com', 'name': 'Nick Vargo'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': 'Z-Temp Items', 'name_with_path': 'Sandbox Test Project/Z-Temp Items', 'parent_id': 771257538, 'private': True, 'read_only': False, 'updated_at': '2024-03-20T20:39:46Z'}]\n" + ] + } + ], "source": [ "# Example 1: Get all folders\n", "# ---------\n", @@ -131,9 +140,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Example 3\n", + "[{'id': 816142268, 'created_at': '2024-07-17T20:56:14Z', 'created_by': {'id': 6036589, 'company_name': \"Rogers-O'Brien Construction Company\", 'locale': 'en', 'login': 'sthompson@r-o.com', 'name': 'Scott Thompson'}, 'custom_fields': {}, 'document_type': 'folder', 'is_deleted': False, 'is_recycle_bin': False, 'name': '03-Concrete', 'name_with_path': 'Sandbox Test Project/C-Field Use Documents/03-Concrete', 'parent_id': 771257695, 'private': False, 'read_only': False, 'updated_at': '2024-07-17T20:56:14Z'}]\n" + ] + } + ], "source": [ "# Example 3: Get all children folders from parent\n", "# ---------\n", @@ -141,7 +160,7 @@ "subfolders = connection.folders.get(\n", " company_id=company[\"id\"],\n", " project_id=project[\"id\"],\n", - " folder_id=607848046\n", + " folder_id=816142268\n", ")\n", "print(subfolders)\n" ] @@ -155,29 +174,16 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Example 1\n" - ] - }, - { - "ename": "NameError", - "evalue": "name 'WrongParamsError' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[1;32mIn[12], line 5\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m----> 5\u001b[0m root_folder \u001b[38;5;241m=\u001b[39m \u001b[43mconnection\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdocuments\u001b[49m\u001b[38;5;241m.\u001b[39mfolders\u001b[38;5;241m.\u001b[39mcreate(\n\u001b[0;32m 6\u001b[0m company_id\u001b[38;5;241m=\u001b[39mcompany[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mid\u001b[39m\u001b[38;5;124m\"\u001b[39m],\n\u001b[0;32m 7\u001b[0m project_id\u001b[38;5;241m=\u001b[39mproject[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mid\u001b[39m\u001b[38;5;124m\"\u001b[39m],\n\u001b[0;32m 8\u001b[0m folder_name\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mZ-Research and Development\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 9\u001b[0m )\n\u001b[0;32m 10\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mroot_folder[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mid\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mroot_folder[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n", - "\u001b[1;31mAttributeError\u001b[0m: 'Procore' object has no attribute 'documents'", - "\nDuring handling of the above exception, another exception occurred:\n", - "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[1;32mIn[12], line 11\u001b[0m\n\u001b[0;32m 5\u001b[0m root_folder \u001b[38;5;241m=\u001b[39m connection\u001b[38;5;241m.\u001b[39mdocuments\u001b[38;5;241m.\u001b[39mfolders\u001b[38;5;241m.\u001b[39mcreate(\n\u001b[0;32m 6\u001b[0m company_id\u001b[38;5;241m=\u001b[39mcompany[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mid\u001b[39m\u001b[38;5;124m\"\u001b[39m],\n\u001b[0;32m 7\u001b[0m project_id\u001b[38;5;241m=\u001b[39mproject[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mid\u001b[39m\u001b[38;5;124m\"\u001b[39m],\n\u001b[0;32m 8\u001b[0m folder_name\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mZ-Research and Development\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 9\u001b[0m )\n\u001b[0;32m 10\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mroot_folder[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mid\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mroot_folder[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m---> 11\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[43mWrongParamsError\u001b[49m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m 12\u001b[0m \u001b[38;5;28mprint\u001b[39m(e)\n\u001b[0;32m 13\u001b[0m \u001b[38;5;66;03m# 607848046: Z-Research and Development\u001b[39;00m\n", - "\u001b[1;31mNameError\u001b[0m: name 'WrongParamsError' is not defined" + "Example 1\n", + "'Error: 400'\n", + "cannot access local variable 'doc_info' where it is not associated with a value\n" ] } ], @@ -199,7 +205,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -207,19 +213,8 @@ "output_type": "stream", "text": [ "\n", - "Example 2\n" - ] - }, - { - "ename": "NotFoundItemError", - "evalue": "'Could not find document Z-Research and Development'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mNotFoundItemError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[1;32mIn[15], line 4\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# Example 2: Create folder in specified location\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m# ---------\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mExample 2\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m----> 4\u001b[0m folder \u001b[38;5;241m=\u001b[39m \u001b[43mconnection\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfolders\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfind\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 5\u001b[0m \u001b[43m \u001b[49m\u001b[43mcompany_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcompany\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mid\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 6\u001b[0m \u001b[43m \u001b[49m\u001b[43mproject_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mproject\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mid\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 7\u001b[0m \u001b[43m \u001b[49m\u001b[43midentifier\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mZ-Research and Development\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# this needs to be a path in your procore project\u001b[39;49;00m\n\u001b[0;32m 8\u001b[0m \u001b[43m)\u001b[49m\n\u001b[0;32m 9\u001b[0m \u001b[38;5;66;03m# 607848083: A-Team\u001b[39;00m\n\u001b[0;32m 11\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n", - "File \u001b[1;32mc:\\Users\\hfritz\\OneDrive - RO\\Documents\\packages\\ProPyCore\\snippets\\.venv_doc\\Lib\\site-packages\\ProPyCore\\access\\documents\\folders.py:377\u001b[0m, in \u001b[0;36mFolders.find\u001b[1;34m(self, company_id, project_id, identifier, folder_id)\u001b[0m\n\u001b[0;32m 370\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m folder[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m==\u001b[39m identifier:\n\u001b[0;32m 371\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mshow(\n\u001b[0;32m 372\u001b[0m company_id\u001b[38;5;241m=\u001b[39mcompany_id,\n\u001b[0;32m 373\u001b[0m project_id\u001b[38;5;241m=\u001b[39mproject_id,\n\u001b[0;32m 374\u001b[0m doc_id\u001b[38;5;241m=\u001b[39mfolder[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mid\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[0;32m 375\u001b[0m )\n\u001b[1;32m--> 377\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m NotFoundItemError(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCould not find document \u001b[39m\u001b[38;5;132;01m{\u001b[39;00midentifier\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n", - "\u001b[1;31mNotFoundItemError\u001b[0m: 'Could not find document Z-Research and Development'" + "Example 2\n", + "929510338: A-Team\n" ] } ], @@ -248,9 +243,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Example 3\n", + "929510340: I-Safety and Environmental\n" + ] + } + ], "source": [ "# Example 3: Folder already exists\n", "# ---------\n", @@ -277,9 +282,57 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 1\n", + "929510260: Z-Research and Development\n", + "{\n", + " \"id\": 929510260,\n", + " \"custom_fields\": {},\n", + " \"name\": \"Z-Research and Development\",\n", + " \"name_with_path\": \"Sandbox Test Project/Z-Research and Development\",\n", + " \"parent_id\": 771257538,\n", + " \"updated_at\": \"2025-05-13T17:48:59Z\",\n", + " \"is_deleted\": false,\n", + " \"is_recycle_bin\": false,\n", + " \"is_tracked\": false,\n", + " \"tracked_folder\": null,\n", + " \"has_children\": true,\n", + " \"has_children_files\": false,\n", + " \"has_children_folders\": true,\n", + " \"folders\": [\n", + " {\n", + " \"id\": 929510338,\n", + " \"custom_fields\": {},\n", + " \"name\": \"A-Team\",\n", + " \"name_with_path\": \"Sandbox Test Project/Z-Research and Development/A-Team\",\n", + " \"parent_id\": 929510260,\n", + " \"updated_at\": \"2025-05-13T17:49:08Z\",\n", + " \"is_deleted\": false,\n", + " \"is_recycle_bin\": false,\n", + " \"is_tracked\": false,\n", + " \"tracked_folder\": null,\n", + " \"has_children\": false,\n", + " \"has_children_files\": false,\n", + " \"has_children_folders\": false,\n", + " \"folders\": [],\n", + " \"files\": [],\n", + " \"private\": false,\n", + " \"read_only\": false\n", + " }\n", + " ],\n", + " \"files\": [],\n", + " \"private\": false,\n", + " \"read_only\": false\n", + "}\n" + ] + } + ], "source": [ "# Example 1: Find folder in root\n", "# ---------\n", @@ -296,9 +349,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Example 2\n" + ] + }, + { + "ename": "NotFoundItemError", + "evalue": "'Could not find document Subcontractors Orientation'", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mNotFoundItemError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[11]\u001b[39m\u001b[32m, line 4\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m# Example 2: Find subfolder\u001b[39;00m\n\u001b[32m 2\u001b[39m \u001b[38;5;66;03m# ----------\u001b[39;00m\n\u001b[32m 3\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[33mExample 2\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m----> \u001b[39m\u001b[32m4\u001b[39m folder2 = \u001b[43mconnection\u001b[49m\u001b[43m.\u001b[49m\u001b[43mfolders\u001b[49m\u001b[43m.\u001b[49m\u001b[43mfind\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 5\u001b[39m \u001b[43m \u001b[49m\u001b[43mcompany_id\u001b[49m\u001b[43m=\u001b[49m\u001b[43mcompany\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mid\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 6\u001b[39m \u001b[43m \u001b[49m\u001b[43mproject_id\u001b[49m\u001b[43m=\u001b[49m\u001b[43mproject\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mid\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 7\u001b[39m \u001b[43m \u001b[49m\u001b[43midentifier\u001b[49m\u001b[43m=\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mSubcontractors Orientation\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\n\u001b[32m 8\u001b[39m \u001b[43m)\u001b[49m\n\u001b[32m 9\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mfolder2[\u001b[33m'\u001b[39m\u001b[33mid\u001b[39m\u001b[33m'\u001b[39m]\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mfolder2[\u001b[33m'\u001b[39m\u001b[33mname\u001b[39m\u001b[33m'\u001b[39m]\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m)\n\u001b[32m 10\u001b[39m \u001b[38;5;66;03m# 607846791: Subcontractors Orientation\u001b[39;00m\n", + "\u001b[36mFile \u001b[39m\u001b[32m~/Projects/ProPyCore/ProPyCore/access/documents/folders.py:377\u001b[39m, in \u001b[36mFolders.find\u001b[39m\u001b[34m(self, company_id, project_id, identifier, folder_id)\u001b[39m\n\u001b[32m 370\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m folder[\u001b[33m\"\u001b[39m\u001b[33mname\u001b[39m\u001b[33m\"\u001b[39m] == identifier:\n\u001b[32m 371\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m.show(\n\u001b[32m 372\u001b[39m company_id=company_id,\n\u001b[32m 373\u001b[39m project_id=project_id,\n\u001b[32m 374\u001b[39m doc_id=folder[\u001b[33m\"\u001b[39m\u001b[33mid\u001b[39m\u001b[33m\"\u001b[39m]\n\u001b[32m 375\u001b[39m )\n\u001b[32m--> \u001b[39m\u001b[32m377\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m NotFoundItemError(\u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mCould not find document \u001b[39m\u001b[38;5;132;01m{\u001b[39;00midentifier\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m)\n", + "\u001b[31mNotFoundItemError\u001b[39m: 'Could not find document Subcontractors Orientation'" + ] + } + ], "source": [ "# Example 2: Find subfolder\n", "# ----------\n", @@ -445,20 +519,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Example 2\n", + "Number of files: 7068\n" + ] + } + ], "source": [ "# Example 2: Get all files\n", "# ---------\n", "print(\"\\nExample 2\")\n", "files = connection.files.get(\n", " company_id=company[\"id\"],\n", - " project_id=project[\"id\"]\n", + " project_id=2289314,\n", + " view=\"extended\",\n", + " file_types=[\"pdf\"]\n", ")\n", - "print(files)\n", "\n", - "print(\"Number of folders:\", len(folders))\n", "print(\"Number of files:\", len(files))" ] }, @@ -666,15 +750,15 @@ "outputs": [], "source": [ "# Example 3: Find folder \n", - " # ---------\n", - " print(\"\\nExample 3\")\n", - " doc3 = connection.folders.search(\n", - " company_id=company[\"id\"],\n", - " project_id=project[\"id\"],\n", - " value=\"training\"\n", - " )\n", - " print(f\"{doc3['id']}: {doc3['name']}\")\n", - " # 607846718: 3-Orientations and Training" + "# ---------\n", + "print(\"\\nExample 3\")\n", + "doc3 = connection.folders.search(\n", + " company_id=company[\"id\"],\n", + " project_id=project[\"id\"],\n", + " value=\"training\"\n", + ")\n", + "print(f\"{doc3['id']}: {doc3['name']}\")\n", + "# 607846718: 3-Orientations and Training" ] }, { @@ -888,7 +972,7 @@ ], "metadata": { "kernelspec": { - "display_name": ".venv_doc", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -902,7 +986,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.13.3" } }, "nbformat": 4,