Last active
August 29, 2015 14:23
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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