Skip to content

Instantly share code, notes, and snippets.

@anemitz
Created November 20, 2013 07:11
Show Gist options
  • Save anemitz/7558979 to your computer and use it in GitHub Desktop.
Save anemitz/7558979 to your computer and use it in GitHub Desktop.
Deletes the 'owner' custom field for a given search query
#!/usr/bin/env python
import argparse
from closeio_api import Client as CloseIO_API
parser = argparse.ArgumentParser(description='Search and update some leads')
parser.add_argument('--api_key', '-k', required=True, help='API Key')
args = parser.parse_args()
api = CloseIO_API(args.api_key)
# get the org id necessary for search
org_id = api.get('api_key')['data'][0]['organization_id']
# get all the search results for given lead name
search_results = []
filters = {
'organization_id': org_id,
'query': 'emails:0 status:potential has:email_addresses has:custom.owner' # CHANGE THIS QUERY
}
skip = 0
limit = 100
while True:
filters['_skip'] = skip
filters['_limit'] = limit
results = [res['id'] for res in api.get('lead', data=filters)['data']]
search_results.extend(results)
if len(results) < limit:
break
skip += limit
print "NUMBER", len(search_results)
for result in search_results:
lead = api.get('lead/' + result)
if lead['custom'].get('owner'):
custom = lead['custom']
del custom['owner']
print api.put('lead/' + result, data={'custom': custom})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment