Skip to content

Commit 2de5860

Browse files
author
Matt Carey
committed
feat: working upload tool
1 parent f3ec5ab commit 2de5860

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

examples/file_upload_example.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""
2+
Example demonstrating file upload functionality with StackOne.
3+
Shows how to upload an employee document using the HRIS integration.
4+
5+
This example is runnable with the following command:
6+
```bash
7+
uv run examples/file_upload_example.py
8+
```
9+
"""
10+
11+
import base64
12+
import tempfile
13+
from pathlib import Path
14+
15+
from dotenv import load_dotenv
16+
from stackone_ai import StackOneToolSet
17+
18+
load_dotenv()
19+
20+
account_id = "45072196112816593343"
21+
employee_id = "c28xIQaWQ6MzM5MzczMDA2NzMzMzkwNzIwNA"
22+
23+
24+
def upload_employee_document() -> None:
25+
"""Demonstrate uploading an employee document using StackOne."""
26+
with tempfile.TemporaryDirectory() as temp_dir:
27+
resume_content = """
28+
JOHN DOE
29+
Software Engineer
30+
31+
EXPERIENCE
32+
Senior Developer - Tech Corp
33+
2020-Present
34+
- Led development of core features
35+
- Managed team of 5 engineers
36+
37+
EDUCATION
38+
BS Computer Science
39+
University of Technology
40+
2016-2020
41+
"""
42+
43+
resume_file = Path(temp_dir) / "resume.pdf"
44+
resume_file.write_text(resume_content)
45+
46+
# Initialize StackOne
47+
toolset = StackOneToolSet()
48+
tools = toolset.get_tools(vertical="hris", account_id=account_id)
49+
50+
# Get the upload document tool
51+
upload_tool = tools.get_tool("hris_upload_employee_document")
52+
if not upload_tool:
53+
print("Upload tool not available")
54+
return
55+
56+
with open(resume_file, "rb") as f:
57+
file_content = base64.b64encode(f.read()).decode()
58+
59+
upload_params = {
60+
"x-account-id": account_id,
61+
"id": employee_id,
62+
"name": "resume",
63+
"content": file_content,
64+
"category": {"value": "shared"},
65+
"file_format": {"value": "txt"},
66+
}
67+
68+
try:
69+
upload_tool.execute(upload_params)
70+
except Exception as e:
71+
print(f"Error uploading document: {e}")
72+
73+
74+
if __name__ == "__main__":
75+
upload_employee_document()

0 commit comments

Comments
 (0)