-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompany-lookup.py
More file actions
116 lines (96 loc) · 3.45 KB
/
Copy pathcompany-lookup.py
File metadata and controls
116 lines (96 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python3
"""
Company Name Lookup - READ-ONLY
Lookup a company name by GsCompanyId using the Company query endpoint.
"""
import os
import sys
import json
import argparse
import requests
def lookup_company_by_id(domain, access_key, company_id):
"""Lookup company name by GsCompanyId using Company query endpoint"""
url = f"{domain.rstrip('/')}/v1/data/objects/query/Company"
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"accesskey": access_key,
}
query = {
"select": ["Gsid", "Name", "Industry", "ModifiedDate"],
"where": {
"conditions": [
{
"name": "Gsid",
"alias": "A",
"value": [company_id],
"operator": "EQ"
}
],
"expression": "A"
},
"limit": 1,
"offset": 0
}
try:
print(f"🔍 Looking up company with ID: {company_id}")
resp = requests.post(url, headers=headers, data=json.dumps(query), timeout=15)
if resp.status_code == 200:
return resp.json()
else:
print(f" ❌ HTTP {resp.status_code}: {resp.text[:300]}")
return None
except requests.RequestException as e:
print(f" ❌ Request error: {e}")
return None
def format_company_data(data):
"""Format company data for display"""
if not data or not data.get('result'):
return " No company data available"
data_section = data.get('data', {})
companies = data_section.get('records', [])
if not companies:
return " No company found with that ID"
company = companies[0]
name = company.get('Name', 'Unknown Company')
industry = company.get('Industry', 'No industry')
gsid = company.get('Gsid', 'Unknown ID')
return f""" ✅ Company found:
📊 Name: {name}
🏭 Industry: {industry}
🆔 Gsid: {gsid}"""
def main():
parser = argparse.ArgumentParser(description="Lookup company name by GSID (read-only).")
parser.add_argument("--company-id", dest="company_id", help="GsCompanyId to lookup")
args = parser.parse_args()
domain = os.environ.get("GAINSIGHT_DOMAIN")
access_key = os.environ.get("GAINSIGHT_ACCESS_KEY")
company_id = args.company_id or os.environ.get("GAINSIGHT_COMPANY_ID")
if not domain or not access_key:
print("❌ Missing env vars. Set GAINSIGHT_DOMAIN and GAINSIGHT_ACCESS_KEY.")
sys.exit(1)
if not company_id:
print("❌ Missing company ID. Provide --company-id or set GAINSIGHT_COMPANY_ID.")
sys.exit(1)
print("🏢 Company Name Lookup (READ-ONLY)")
print(f"🌐 Domain: {domain}")
print(f"🆔 Target Company ID: {company_id}")
print("📖 Endpoint: v1/data/objects/query/Company")
print("=" * 60)
data = lookup_company_by_id(domain, access_key, company_id)
if data:
print("🎯 Result:")
formatted = format_company_data(data)
print(formatted)
print("-" * 40)
print("✅ Company lookup completed!")
else:
print("❌ Company lookup failed")
print("💡 Possible reasons:")
print(" • Company ID doesn't exist")
print(" • API key lacks Company read permissions")
print(" • Company object not accessible")
print("
🛡️ 100% READ-ONLY: No data was modified, only viewed")
if __name__ == "__main__":
main()