Skip to content

Commit 45647ce

Browse files
add script to fetch and delete organizations from Clerk API
1 parent a4ad681 commit 45647ce

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/fetch-from-clerk.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import requests
2+
3+
CLERK_API_URL = "https://api.clerk.com/v1/organizations"
4+
CLERK_API_KEY = "sk_test_8ivpgZWhlSm0CurLJeiqDQtprNsm2YbK8O0IyvXGNu" # Ensure you have this environment variable set
5+
6+
def fetch_organizations(query):
7+
response = requests.get(f"{CLERK_API_URL}?query={query}", headers={
8+
"Content-Type": "application/json",
9+
"Authorization": f"Bearer {CLERK_API_KEY}",
10+
})
11+
12+
if response.status_code != 200:
13+
raise Exception(f"Failed to fetch organizations: {response.text}")
14+
15+
data = response.json()
16+
return data.get('data', []) # Access the 'data' key
17+
18+
def delete_organization(clerk_org_id):
19+
response = requests.delete(f"{CLERK_API_URL}/{clerk_org_id}", headers={
20+
"Content-Type": "application/json",
21+
"Authorization": f"Bearer {CLERK_API_KEY}",
22+
})
23+
24+
if response.status_code != 200:
25+
raise Exception(f"Failed to delete organization {clerk_org_id}: {response.text}")
26+
27+
print(f"Deleted organization: {clerk_org_id}")
28+
29+
def delete_playwright_organizations():
30+
try:
31+
organizations = fetch_organizations("playwrightTest")
32+
33+
if len(organizations) == 0:
34+
print("No organizations found with the query playwritesttest1234")
35+
return
36+
37+
for organization in organizations:
38+
delete_organization(organization['id'])
39+
40+
print(f"Deleted {len(organizations)} organizations with the query 'playwright'")
41+
except Exception as error:
42+
print(f"Error deleting organizations: {error}")
43+
44+
if __name__ == "__main__":
45+
delete_playwright_organizations()

0 commit comments

Comments
 (0)