Hey folks,
I wanted to share my process for handling Company record deletes. Our internal processes mean that on a regular basis we have Accounts in Gainsight that are flagged for review; the Account no longer exists in the CRM and a decision has to be made on whether data exists on the Account record and so the Company/Relationship records require to be merged in CS, or whether a straight up delete can be actioned. I’m not a fan of deleting either in Data Management, or Customer Data > Company - I personally find the process a little clunky, and additionally a manual decision is required as to which records require to be deleted. I have a KPI widget powered by a DD dataset on an Admin dashboard that monitors records that exist in CS but not in the CRM. The drilldown includes:
- Company Name
- GSID
- Company Status
- Number of Relationships
- Number of Active Relationships
- Number of Active + Paid Relationships
- Count of Timeline Activities
Generally, I find this information is sufficient to determine whether a record needs to be deleted or merged. In terms of processing the deletion, I leverage the Company API. I have two tabs open in Visual Studio Code; one is a csv with one column (column name = gsid) and the other is a python script. On one desktop I review the company records to be deleted, and have VSC open on another to add the gsids of the company records to be deleted (third monitor for reviewing individual company C360s). Save the csv and run the file directly from the terminal in VSC. The code will print in terminal whether the call has been successful or if it failed for each GSID.This works for me; I may be the exception on this, and note I’m not dealing with 100s or 1000s of records through this process. But, I’m sharing the python script I use in case it’s something anyone else wants to try. For people like me who are starting to code a little bit more and better understanding APIs, I think it’s a small piece of code, and helps to dip the toes in the water for running local code to leverage APIs (and also takes a csv and converts to JSON, which is pretty neat). Code (you will need to edit csv_file
, api_url
and Accesskey
)
import csv
import requests
# Path to your CSV file
csv_file = 'yourlocalcsvfile.csv' # Replace with your actual file path
# API endpoint
api_url = 'https://yourinstancedomain.gainsightcloud.com/v1/data/objects/Company/'
# Headers to include in the DELETE request
headers = {
'Content-Type': 'application/json', # Ensure this is the correct content type
'Accesskey': 'youraccesskey' # Replace with your actual access key
}
# Read the CSV file and iterate through each GSID
with open(csv_file, mode='r') as file:
reader = csv.DictReader(file)
# Print the field names (headers) from the CSV
print(reader.fieldnames)
for row in reader:
gsid = row>'gsid']
# Construct the full URL with the GSID
delete_url = f"{api_url}{gsid}"
try:
# Make the DELETE request with headers
response = requests.delete(delete_url, headers=headers)
# Check the response status
if response.status_code == 200:
print(f"Successfully deleted record with GSID: {gsid}")
print(response.status_code)
print(response.text)
else:
print(f"Failed to delete record with GSID: {gsid}. Status code: {response.status_code}")
except requests.exceptions.RequestException as e:
print(f"Error deleting record with GSID: {gsid}. Error: {e}")
Hopefully other Admins may find this useful!
Stuart