Esempio n. 1
0
def get_list_of_users(api_key):

    closeio_api = Client(api_key)

    has_more = True
    offset = 0
    limit = 100

    list_of_users = []

    while has_more:

        response = closeio_api.get('user',
                                   params={
                                       '_skip': offset,
                                       '_limit': limit
                                   })

        users = response['data']

        for user in users:
            list_of_users.append(user)

        has_more = response['has_more']
        offset += limit

    return list_of_users
Esempio n. 2
0
def generate_user_activity_report(api_key, org_id, date_start, date_end,
                                  user_id):

    closeio_api = Client(api_key)

    user_activity_report = closeio_api.get('report/activity/{}'.format(org_id),
                                           params={
                                               'date_start': date_start,
                                               'date_end': date_end,
                                               'user_id': user_id,
                                           })

    return user_activity_report
Esempio n. 3
0
def get_list_of_leads_via_search_query(api_key, search_query):

    closeio_api = Client(api_key)

    has_more = True
    offset = 0
    limit = 100

    list_of_leads = []

    while has_more:

        response = closeio_api.get('lead',
                                   params={
                                       '_skip': offset,
                                       '_limit': limit,
                                       'query': search_query
                                   })

        leads = response['data']

        for lead in leads:
            list_of_leads.append(lead)

        has_more = response['has_more']
        offset += limit

    return list_of_leads


# # Retrieve lead data from Lead ID
# def get_lead_data(api_key, lead_id):

#     closeio_api = Client(api_key)
#     api_url = 'lead/{}'.format(lead_id)
#     lead_data = closeio_api.get(api_url)

#     return lead_data
Esempio n. 4
0
def api_client():
    """Return the Close API client fixture."""
    return Client('fake-api-key')
Esempio n. 5
0
from datetime import datetime
import os
import csv
import requests
from lxml import etree
import json
import logging
import pdb
import time
import random
from closeio_api import Client

api = Client('api_5ivDk55sUEI1C3YPxl0Agy.0SigTV6fgVIRLXXEkJyQ95')


def validate(item):
    if item == None:
        item = ''
    if type(item) == bool:
        return item
    if type(item) == int or type(item) == float:
        item = str(item)
    if type(item) == list:
        item = ' '.join(item)
    return item.encode('ascii',
                       'ignore').decode("utf-8").replace('~~', ',').replace(
                           '~', ',').strip()


def format(item):
    if item == '':
Esempio n. 6
0
def get_query_results(query):
    """
    Get the data with common fields from the Close using the provided query.

    :param query: Any Close search query eg. 'lead_status:Potential has:emails'
    :return: 2D array with a header and results
    """
    api = Client(CLOSE_API_KEY)
    leads = api.get('lead', params={'query': query})

    values = [[
        'id', 'display_name', 'lead_name', 'description', 'url', 'status_id',
        'status_label', 'primary_contact_name', 'primary_contact_first_name',
        'primary_contact_last_name', 'primary_contact_title',
        'primary_contact_primary_phone', 'primary_contact_primary_phone_type',
        'primary_contact_other_phones', 'primary_contact_primary_email',
        'primary_contact_primary_email_type', 'primary_contact_other_emails',
        'primary_contact_primary_url', 'primary_contact_other_urls',
        'created_by', 'created_by_name', 'updated_by', 'updated_by_name',
        'date_created', 'date_updated', 'html_url'
    ]]

    for lead in leads['data']:
        primary_contact = lead['contacts'][0] if lead['contacts'] else None

        id = lead['id']
        display_name = lead['display_name']
        lead_name = lead['name']
        description = lead['description']
        url = lead['url']
        status_id = lead['status_id']
        status_label = lead['status_label']
        created_by = lead['created_by']
        created_by_name = lead['created_by_name']
        updated_by = lead['updated_by']
        updated_by_name = lead['updated_by_name']
        date_created = lead['date_created']
        date_updated = lead['date_updated']
        html_url = lead['html_url']

        primary_contact_name = None
        primary_contact_first_name = None
        primary_contact_last_name = None
        primary_contact_title = None
        primary_contact_primary_phone = None
        primary_contact_primary_phone_type = None
        primary_contact_other_phones = None
        primary_contact_email = None
        primary_contact_email_type = None
        primary_contact_other_emails = None
        primary_contact_primary_url = None
        primary_contact_other_urls = None

        if primary_contact:
            primary_contact_name = primary_contact[
                'name'] if primary_contact else None
            primary_contact_title = primary_contact[
                'title'] if primary_contact else None

            if 'name' in primary_contact:
                primary_contact_first_name = primary_contact['name'].split(
                    ' ')[0]
                if len(primary_contact['name'].split(' ')) > 1:
                    primary_contact_last_name = primary_contact['name'].split(
                        ' ')[1]

            if primary_contact['phones']:
                primary_contact_primary_phone = primary_contact['phones'][0][
                    'phone']
                primary_contact_primary_phone_type = primary_contact['phones'][
                    0]['type']
                if len(primary_contact['phones']) > 1:
                    primary_contact_other_phones = ", ".join(
                        o['phone'] for o in primary_contact['phones'][1:])

            if primary_contact['emails']:
                primary_contact_email = primary_contact['emails'][0]['email']
                primary_contact_email_type = primary_contact['emails'][0][
                    'type']
                if len(primary_contact['emails']) > 1:
                    primary_contact_other_emails = ", ".join(
                        o['email'] for o in primary_contact['emails'][1:])

            if primary_contact['urls']:
                primary_contact_primary_url = primary_contact['urls'][0]['url']
                if len(primary_contact['urls']) > 1:
                    primary_contact_other_urls = ", ".join(
                        o['url'] for o in primary_contact['urls'][1:])

        values.append([
            id, display_name, lead_name, description, url, status_id,
            status_label, primary_contact_name, primary_contact_first_name,
            primary_contact_last_name, primary_contact_title,
            primary_contact_primary_phone, primary_contact_primary_phone_type,
            primary_contact_other_phones, primary_contact_email,
            primary_contact_email_type, primary_contact_other_emails,
            primary_contact_primary_url, primary_contact_other_urls,
            created_by, created_by_name, updated_by, updated_by_name,
            date_created, date_updated, html_url
        ])

    return values