Skip to content

Commit c4d1953

Browse files
committed
removing deprecated 'CREATE_OR_UPDATE' sync_mode
1 parent 2f6563d commit c4d1953

File tree

6 files changed

+222
-8
lines changed

6 files changed

+222
-8
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,17 @@ instance = j1.create_integration_instance(
357357

358358
```python
359359
# Start sync job for an integration instance
360-
sync_job = j1.start_sync_job(instance_id='<id-of-integration-instance>')
361-
print(f"Started sync job: {sync_job['job']['_id']}")
360+
sync_job = j1.start_sync_job(
361+
instance_id=instance_id,
362+
sync_mode="PATCH",
363+
source="integration-external"
364+
)
365+
366+
sync_job_id = sync_job['job'].get('id')
367+
print(f"Started sync job: {sync_job_id}")
362368

363369
# The returned job ID is used for subsequent operations
364-
job_id = sync_job['job']['_id']
370+
job_id = sync_job_id
365371
```
366372

367373
##### Upload Batch of Entities
@@ -514,7 +520,7 @@ print(f"Uploaded {len(combined_payload['entities'])} entities and {len(combined_
514520
```python
515521
# Finalize the sync job
516522
result = j1.finalize_sync_job(instance_job_id='<id-of-integration-sync-job>')
517-
print(f"Finalized sync job: {result['job']['_id']}")
523+
print(f"Finalized sync job: {result['job'].get('id')}")
518524

519525
# Check job status
520526
if result['job']['status'] == 'COMPLETED':

examples/04_integration_management.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def sync_job_examples(j1, instance_id):
149149
try:
150150
sync_job = j1.start_sync_job(
151151
instance_id=instance_id,
152-
sync_mode="CREATE_OR_UPDATE",
152+
sync_mode="PATCH",
153153
source="api"
154154
)
155155
job_id = sync_job['job']['_id']

examples/bulk_upload.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
from jupiterone.client import JupiterOneClient
2+
import random
3+
import time
4+
import os
5+
import json
6+
7+
account = os.environ.get("JUPITERONE_ACCOUNT")
8+
token = os.environ.get("JUPITERONE_TOKEN")
9+
url = "https://graphql.us.jupiterone.io"
10+
11+
j1 = JupiterOneClient(account=account, token=token, url=url)
12+
13+
instance_id = "e7113c37-1ea8-4d00-9b82-c24952e70916"
14+
15+
sync_job = j1.start_sync_job(
16+
instance_id=instance_id,
17+
sync_mode="PATCH",
18+
source="integration-external"
19+
)
20+
21+
print(sync_job)
22+
sync_job_id = sync_job['job'].get('id')
23+
24+
# Prepare entities payload
25+
entities_payload = [
26+
{
27+
"_key": "server-001",
28+
"_type": "aws_ec2_instance",
29+
"_class": "Host",
30+
"displayName": "web-server-001",
31+
"instanceId": "i-1234567890abcdef0",
32+
"instanceType": "t3.micro",
33+
"state": "running",
34+
"tag.Environment": "production",
35+
"tag.Team": "engineering"
36+
},
37+
{
38+
"_key": "server-002",
39+
"_type": "aws_ec2_instance",
40+
"_class": "Host",
41+
"displayName": "web-server-002",
42+
"instanceId": "i-0987654321fedcba0",
43+
"instanceType": "t3.small",
44+
"state": "running",
45+
"tag.Environment": "staging",
46+
"tag.Team": "engineering"
47+
},
48+
{
49+
"_key": "database-001",
50+
"_type": "aws_rds_instance",
51+
"_class": "Database",
52+
"displayName": "prod-database",
53+
"dbInstanceIdentifier": "prod-db",
54+
"engine": "postgres",
55+
"dbInstanceClass": "db.t3.micro",
56+
"tag.Environment": "production",
57+
"tag.Team": "data"
58+
}
59+
]
60+
61+
# Upload entities batch
62+
result = j1.upload_entities_batch_json(
63+
instance_job_id=sync_job_id,
64+
entities_list=entities_payload
65+
)
66+
print(f"Uploaded {len(entities_payload)} entities")
67+
print(result)
68+
69+
# Finalize the sync job
70+
result = j1.finalize_sync_job(instance_job_id=sync_job_id)
71+
print(f"Finalized sync job: {result['job']['id']}")
72+

examples/examples.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@
124124
integration_instance_id = "<GUID>"
125125

126126
# start_sync_job
127-
# sync_mode can be "DIFF", "CREATE_OR_UPDATE", or "PATCH"
127+
# sync_mode can be "DIFF" or "PATCH"
128128
start_sync_job_r = j1.start_sync_job(instance_id=integration_instance_id,
129-
sync_mode='CREATE_OR_UPDATE',
129+
sync_mode='PATCH',
130130
source='integration-external')
131131
print("start_sync_job()")
132132
print(start_sync_job_r)

examples/sync_job_workflow.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#!/usr/bin/env python3
2+
"""
3+
JupiterOne Sync Job Workflow Example
4+
5+
This example demonstrates the core synchronization job workflow:
6+
1. Start a sync job
7+
2. Upload entities batch
8+
3. Finalize the sync job
9+
10+
This is a standalone script that can be run independently to test
11+
the sync job functionality.
12+
"""
13+
14+
import os
15+
import sys
16+
from jupiterone.client import JupiterOneClient
17+
18+
def main():
19+
"""Main function to demonstrate sync job workflow."""
20+
21+
# Initialize JupiterOne client
22+
# You can set these as environment variables or replace with your values
23+
api_token = os.getenv('JUPITERONE_API_TOKEN')
24+
account_id = os.getenv('JUPITERONE_ACCOUNT_ID')
25+
26+
if not api_token or not account_id:
27+
print("Error: Please set JUPITERONE_API_TOKEN and JUPITERONE_ACCOUNT_ID environment variables")
28+
print("Example:")
29+
print(" export JUPITERONE_API_TOKEN='your-api-token'")
30+
print(" export JUPITERONE_ACCOUNT_ID='your-account-id'")
31+
sys.exit(1)
32+
33+
# Create JupiterOne client
34+
j1 = JupiterOneClient(api_token=api_token, account_id=account_id)
35+
36+
print("=== JupiterOne Sync Job Workflow Example ===\n")
37+
38+
# You'll need to replace this with an actual integration instance ID
39+
instance_id = os.getenv('JUPITERONE_INSTANCE_ID')
40+
if not instance_id:
41+
print("Error: Please set JUPITERONE_INSTANCE_ID environment variable")
42+
print("Example:")
43+
print(" export JUPITERONE_INSTANCE_ID='your-integration-instance-id'")
44+
sys.exit(1)
45+
46+
try:
47+
# Step 1: Start sync job
48+
print("1. Starting synchronization job...")
49+
sync_job = j1.start_sync_job(
50+
instance_id=instance_id,
51+
sync_mode="PATCH",
52+
source="integration-external"
53+
)
54+
55+
sync_job_id = sync_job['job'].get('id')
56+
print(f"✓ Started sync job: {sync_job_id}")
57+
print(f" Status: {sync_job['job']['status']}")
58+
print()
59+
60+
# Step 2: Upload entities batch
61+
print("2. Uploading entities batch...")
62+
63+
# Sample entities payload
64+
entities_payload = [
65+
{
66+
"_key": "example-server-001",
67+
"_type": "example_server",
68+
"_class": "Host",
69+
"displayName": "Example Server 001",
70+
"hostname": "server-001.example.com",
71+
"ipAddress": "192.168.1.100",
72+
"operatingSystem": "Linux",
73+
"tag.Environment": "development",
74+
"tag.Team": "engineering",
75+
"tag.Purpose": "web_server"
76+
},
77+
{
78+
"_key": "example-server-002",
79+
"_type": "example_server",
80+
"_class": "Host",
81+
"displayName": "Example Server 002",
82+
"hostname": "server-002.example.com",
83+
"ipAddress": "192.168.1.101",
84+
"operatingSystem": "Linux",
85+
"tag.Environment": "staging",
86+
"tag.Team": "engineering",
87+
"tag.Purpose": "database_server"
88+
},
89+
{
90+
"_key": "example-database-001",
91+
"_type": "example_database",
92+
"_class": "Database",
93+
"displayName": "Example Database 001",
94+
"databaseName": "app_db",
95+
"engine": "postgresql",
96+
"version": "13.4",
97+
"tag.Environment": "development",
98+
"tag.Team": "data"
99+
}
100+
]
101+
102+
# Upload entities
103+
upload_result = j1.upload_entities_batch_json(
104+
instance_job_id=sync_job_id,
105+
entities_list=entities_payload
106+
)
107+
print(f"✓ Uploaded {len(entities_payload)} entities successfully")
108+
print(f" Upload result: {upload_result}")
109+
print()
110+
111+
# Step 3: Finalize sync job
112+
print("3. Finalizing synchronization job...")
113+
finalize_result = j1.finalize_sync_job(instance_job_id=sync_job_id)
114+
115+
finalize_job_id = finalize_result['job'].get('id')
116+
print(f"✓ Finalized sync job: {finalize_job_id}")
117+
print(f" Status: {finalize_result['job']['status']}")
118+
119+
# Check final status
120+
if finalize_result['job']['status'] == 'COMPLETED':
121+
print("✓ Sync job completed successfully!")
122+
elif finalize_result['job']['status'] == 'FAILED':
123+
error_msg = finalize_result['job'].get('error', 'Unknown error')
124+
print(f"✗ Sync job failed: {error_msg}")
125+
else:
126+
print(f"ℹ Sync job status: {finalize_result['job']['status']}")
127+
128+
print("\n=== Sync Job Workflow Complete ===")
129+
130+
except Exception as e:
131+
print(f"✗ Error during sync job workflow: {e}")
132+
sys.exit(1)
133+
134+
if __name__ == "__main__":
135+
main()
136+

jupiterone/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ def start_sync_job(
662662
663663
args:
664664
instance_id (str): The "integrationInstanceId" request param for synchronization job
665-
sync_mode (str): The "syncMode" request body property for synchronization job. "DIFF", "CREATE_OR_UPDATE", or "PATCH"
665+
sync_mode (str): The "syncMode" request body property for synchronization job. "DIFF" or "PATCH"
666666
source (str): The "source" request body property for synchronization job. "api" or "integration-external"
667667
"""
668668
endpoint = "/persister/synchronization/jobs"

0 commit comments

Comments
 (0)