Пример #1
0
def form(request):
    if request.method == 'POST':
        form = TransferForm(request.POST)
        if form.is_valid():

            # Instantiate Infusionsoft apps
            source = Infusionsoft(form['src_app_name'].value(),
                                  form['src_api_key'].value())
            destination = Infusionsoft(form['dest_app_name'].value(),
                                       form['dest_api_key'].value())

            # Run transfer
            # Catch Infusionsoft API errors and add to messages
            results = {}
            try:
                results = begin(source, destination)
            except InfusionsoftAPIError as e:
                messages.error(request, e)

            # Add result string to django messages
            else:
                results['source'] = form['src_app_name'].value()
                results['destination'] = form['dest_app_name'].value()
                result_string = json.dumps(results)
                messages.info(request, result_string)
                return HttpResponseRedirect('complete')
    else:
        form = TransferForm()
    return render(request, 'freetrialtransfer/form.html', {'form': form})
Пример #2
0
def query(request):
    if request.method == 'POST':
        form = QueryForm(request.POST)
        if form.is_valid():
            app_name = form['app_name'].value()
            api_key = form['api_key'].value()
            tablename = form['tablename'].value()
            ifs = Infusionsoft(app_name, api_key)
            results = {}
            try:
                results = get_table(ifs, tablename)
            except InfusionsoftAPIError as e:
                messages.error(e.message)
            else:
                df = pd.DataFrame(results)
                if 'csv_export' in request.POST:
                    file = NamedTemporaryFile(suffix='.csv')
                    df.to_csv(file.name, index=False)
                    wrapper = FileWrapper(file)
                    response = HttpResponse(wrapper, content_type='text/csv')
                    now = timezone.now()
                    now_str = now.strftime('%Y%m%dT%H%MZ')
                    filename = f'{app_name}_{tablename}_{now_str}.csv'
                    disp = f'attachment; filename={filename}'
                    response['Content-Disposition'] = disp
                    return response
                df_html = df.to_html(index=False, na_rep='')
    else:
        form = QueryForm()
        df_html = None
    return render(request, 'tablequery/query.html', {
        'form': form,
        'df': df_html
    })
import datetime
from infusionsoft.library import Infusionsoft, InfusionsoftOAuth
import pandas as pd

from constants import FIELDS
from infusionsoft_actions import get_table

APPNAME = 'hk477'
API_KEY = '7e3e6381bcf8bf37a65191e2ad0257b37bf04cc974444c98e52712a1afdd3e4e'
# ACCESS_TOKEN = 'z3sfk68fqrynjr33dwbewghq'

ifs = Infusionsoft(APPNAME, API_KEY)
# ifs = InfusionsoftOAuth(ACCESS_TOKEN)

df = pd.read_csv('duplicate_companies (exact).csv')
df = df.dropna()

company_fields = FIELDS['Company'][:]
company_cfs = get_table(ifs, 'DataFormField', {'FormId': -6}, ['Name'])
company_fields += list(map(lambda x: "_" + x.get('Name'), company_cfs))

deleted_companies = []

start = datetime.datetime.now()

for index, row in df.iterrows():
    orig_id = int(row.orig_id)
    dupe_id = int(row.dupe_id)
    print("\nMerging {} with {}".format(orig_id, dupe_id))
    orig_comp = ifs.DataService('load', 'Company', orig_id, company_fields)
    dupe_comp = ifs.DataService('load', 'Company', dupe_id, company_fields)
Пример #4
0
import os
import zipfile

from infusionsoft.library import Infusionsoft

import config
from constants import FIELDS, DATATYPES
from infusionsoft_actions import get_table, create_custom_field
from tools import convert_dict_dates_to_string


dir_path = "output/{} -- {}/".format(config.SOURCE_APPNAME,
                                     config.DESTINATION_APPNAME)
os.makedirs(dir_path, exist_ok=True)

src_infusionsoft = Infusionsoft(config.SOURCE_APPNAME, config.SOURCE_API_KEY)
dest_infusionsoft = Infusionsoft(config.DESTINATION_APPNAME,
                                 config.DESTINATION_API_KEY)

# ESTABLISH EXISTING RELATIONSHIPS
# =============================================================================
src_contact_id = create_custom_field(dest_infusionsoft,
                                     'Source App Contact ID')['Name']

contact_relationship = {}
for contact in get_table(dest_infusionsoft,
                         'Contact',
                         {src_contact_id: "_%"},
                         ['Id', src_contact_id]):
    contact_relationship[int(contact[src_contact_id])] = contact['Id']
Пример #5
0
from infusionsoft.library import Infusionsoft

infusionsoft = Infusionsoft('Infusionsoft Account Name', 'API Key Goes Here')

# Example 1: Add Contact
#----------------------------------------------------------------------------------------
contact = {'FirstName' : 'John', 'LastName' : 'Doe', 'Email' : '*****@*****.**'}
print infusionsoft.ContactService('add', contact)

# Example 2: Merge two duplicate contacts
#----------------------------------------------------------------------------------------
contactId = 56
duplicateContactId = 57
print infusionsoft.ContactService('merge', contactId, duplicateContactId)

# Example 3: Query a contact using data service
#----------------------------------------------------------------------------------------
table = 'Contact'
returnFields = ['Id', 'FirstName']
query = {'FirstName' : 'John'}
limit = 10
page = 0
print infusionsoft.DataService('query', table, limit, page, query, returnFields)

# Example 4: Return a products inventory using product service
#----------------------------------------------------------------------------------------
productId = 1
print infusionsoft.ProductService('getInventory', productId)

# Example 5: Charge an invoice using the invoice service
#----------------------------------------------------------------------------------------
Пример #6
0
from infusionsoft.library import Infusionsoft
infusionsoft = Infusionsoft('Infusionsoft Account Name', 'API Key Goes Here')
# Example 1: Add Contact#----------------------------------------------------------------------------------------contact = {'FirstName' : 'John', 'LastName' : 'Doe', 'Email' : '*****@*****.**'}print infusionsoft.ContactService('add', contact)
# Example 2: Merge two duplicate contacts#----------------------------------------------------------------------------------------contactId = 56duplicateContactId = 57print infusionsoft.ContactService('merge', contactId, duplicateContactId)
# Example 3: Query a contact using data service#----------------------------------------------------------------------------------------table = 'Contact'returnFields = ['Id', 'FirstName']query = {'FirstName' : 'John'}limit = 10page = 0print infusionsoft.DataService('query', table, limit, page, query, returnFields)
# Example 4: Return a products inventory using product service#----------------------------------------------------------------------------------------productId = 1print infusionsoft.ProductService('getInventory', productId)
# Example 5: Charge an invoice using the invoice service#----------------------------------------------------------------------------------------invoiceId = 16notes = 'API Upsell Payment'creditCardId = 2merchantAccountId = 1bypassCommissions = Falseprint infusionsoft.InvoiceService('chargeInvoice', invoiceId, notes, creditCardId, merchantAccountId, bypassCommissions)
# Example 6: Send an email using the email service#----------------------------------------------------------------------------------------contactList = [123, 456, 789]fromAddress = '*****@*****.**'toAddress = '~Contact.Email~'ccAddress = ''bccAddress = ''contentType = 'Text'subject = 'This is just a test email, relax!'htmlBody = ''textBody = 'This is the contant for the email'print infusionsoft.APIEmailService('sendEmail', contactList, fromAddress, toAddress, ccAddress, bccAddress, contentType, subject, htmlBody, textBody)
# Example 7: Get all report columns using the search service#----------------------------------------------------------------------------------------savedSearchId = 3userId = 1print infusionsoft.SearchService('getAllReportColumns', savedSearchId, userId)
# Example 8: Get all shipping options with the shipping service#----------------------------------------------------------------------------------------print infusionsoft.ShippingService('getAllShippingOptions')
# Example 9: Get affiliate payouts info using filter with the affiliate service#----------------------------------------------------------------------------------------from datetime import datetimeaffiliateId = 2filterStartDate = datetime(2012, 10, 18)filterEndDate = datetime(2012, 10, 23)print infusionsoft.APIAffiliateService('affPayouts', affiliateId, filterStartDate, filterEndDate)
# Example 10: Get the download URL of a particular file#----------------------------------------------------------------------------------------fileId = 23print infusionsoft.FileService('getDownloadUrl', fileId)
# Example 11: Using the library server method to access the API : Create a contact#----------------------------------------------------------------------------------------contact = {'FirstName' : 'John', 'LastName' : 'Doe', 'Email' : '*****@*****.**'}print infusionsoft.server().ContactService.add(infusionsoft.key, contact)
import os
import re
import zipfile

from infusionsoft.library import Infusionsoft

import config
from constants import FIELDS, DATATYPES, OPT_OUT_STATUSES
from tools import convert_dict_dates_to_string
from infusionsoft_actions import get_table, create_custom_field

dir_path = "output/{} -- {}/".format(config.SOURCE_APPNAME,
                                     config.DESTINATION_APPNAME)
os.makedirs(dir_path, exist_ok=True)

src_infusionsoft = Infusionsoft(config.SOURCE_APPNAME, config.SOURCE_API_KEY)
dest_infusionsoft = Infusionsoft(config.DESTINATION_APPNAME,
                                 config.DESTINATION_API_KEY)

# CONTACTS
# =============================================================================
if config.CONTACTS:
    # Create Source App Contact ID custom field
    src_contact_id = create_custom_field(dest_infusionsoft,
                                         'Source App Contact ID')['Name']
    if config.COMPANIES:
        src_company_id = create_custom_field(dest_infusionsoft,
                                             'Source App Company ID')['Name']

    # Generates full list of contact fields, including custom fields
    contact_fields = FIELDS['Contact'][:]
Пример #8
0
    if not header:
        raise ValueError(
            f'InfusionsoftAPIError: {tablename} custom '
            f'field header does not exist')
    header_id = header[0]['Id']
    return header_id

if __name__ == "__main__":
    with open('apistuff.csv', newline='') as f:
        reader = csv.DictReader(f)
        for row in reader:
            appname = row['appname']
            apikey = row['apikey']
            filename = row['filename']
            # Initialize
            ifs = Infusionsoft(appname, apikey)
            df = pd.read_csv(filename)
            df = df.where(pd.notnull(df), '')
            APIMAPPING['Account Type'] = create_custom_field(
                ifs,
                'Account Type',
                fieldtype='Select',
                values=','.join(df['Account Type'].dropna().unique())
            )['Name']
            APIMAPPING['Customer Type'] = create_custom_field(
                ifs,
                'Customer Type',
                fieldtype='Select',
                values=','.join(df['Customer Type'].dropna().unique())
            )['Name']
            APIMAPPING['Employees'] = create_custom_field(
Пример #9
0
import zipfile
import glob
import base64
import os
import shutil
import pathlib
import re

import time

# Initiation
appname = ''
api_key = ''

infusionsoft = Infusionsoft(appname, api_key)


def main():
    file_path = "output/{}_emails/".format(appname)

    os.makedirs(file_path, exist_ok=True)

    count = 0
    exportlist = []

    # Get how many are going to export
    amt = len(FILE_IDS)
    file = pathlib.Path("output/{}_emails/exported.log".format(appname))

    # Check to see if any emails have been exported
Пример #10
0
 def __init__(self, name, api_key):
     Infusionsoft.__init__(self, name, api_key)
     self.client = ServerProxy("https://" + name +
                               ".infusionsoft.com/api/xmlrpc",
                               use_datetime=True)
import glob
import json
import os
import zipfile

from infusionsoft.library import Infusionsoft

import config
from infusionsoft_actions import create_custom_field, get_table
from tools import convert_dict_dates_to_string

dir_path = "output/{} -- {}/".format(config.SOURCE_APPNAME,
                                     config.DESTINATION_APPNAME)
os.makedirs(dir_path, exist_ok=True)

src_infusionsoft = Infusionsoft(config.SOURCE_APPNAME, config.SOURCE_API_KEY)
dest_infusionsoft = Infusionsoft(config.DESTINATION_APPNAME,
                                 config.DESTINATION_API_KEY)

# RELATIONSHIPS
# =============================================================================

product_relationship = {}
if os.path.isfile("{}product_relationship.json".format(dir_path)):
    with open("{}product_relationship.json".format(dir_path), 'r') as fp:
        product_relationship = json.load(fp)
product_relationship = {
    int(k): int(v)
    for k, v in product_relationship.items()
}