Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Delete a list of CRM records from BC by reading a CSV file
from suds import WebFault
from suds.client import Client
from bc_api.models.crm import *
import csv
def delete_from_bc(site, entityId):
url = str(site.secure_site_url + 'catalystwebservice/catalystcrmwebservice.asmx?WSDL')
client = Client(url)
try:
response = client.service.Contact_DeleteByEntityID(
str(site.admin_username),
str(site.admin_password),
int(site.site_id),
int(entityId))
except Exception as e:
print e
else:
return response
def open_file_and_delete():
bcsite = BCSite.objects.get(id=12)
import_file_path = '/Users/mariogudelj/Downloads/Marked-for-deletion.csv'
with open(import_file_path, 'rU') as inputcsvfile:
csvreader = csv.reader(inputcsvfile, delimiter=",")
for row in csvreader:
ent_id = row[0].decode('utf-8')
r = delete_from_bc(bcsite, ent_id)
print r
# run everything by calling open_file_and_delete().
# this is very rough but it will do the job.
open_file_and_delete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment