Skip to content

Instantly share code, notes, and snippets.

@twoblokeswithapostie
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twoblokeswithapostie/ba738b283134ad91d664 to your computer and use it in GitHub Desktop.
Save twoblokeswithapostie/ba738b283134ad91d664 to your computer and use it in GitHub Desktop.
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