Beispiel #1
0
def add_activiy(how):
    url = 'https://companydomain.pipedrive.com/v1/activities?api_token=' + apiToken
    client = Client(domain=url)
    client.set_api_token(apiToken)
    count = 0
    users = []
    while count < how:
        users.append(get_user(count + 1))

        print(users)
        data = {
            'subject': 'Call to the president',
            'type': 'Call',
            'org_id': get_organization(),  # add Call activity
            'done': 1,  # 0 means than activity is done.
            'person_id': users[count]
        }
        data2 = {
            'subject': 'Call to the minister',
            'type': 'Meeting',  # add meeting activity
            'org_id': get_organization(),
            'done': 1,
            'person_id': users[count]
        }
        count += 1
        client = Client(domain=url)
        client.set_api_token(apiToken)
        response = client.activities.create_activity(data)
        response = client.activities.create_activity(data2)
Beispiel #2
0
    def create_pipedrive_organization(domain: str, api_token: str, **kwargs):
        from pipedrive.client import Client

        client = Client(domain=domain)
        client.set_api_token(api_token)
        payload = {'name': kwargs.get('org_name')}
        return client.organizations.create_organization(payload)
Beispiel #3
0
 def cron_pipedrive_person_exec(self):
     _logger.info('cron_pipedrive_person_exec')
     # params
     pipedrive_domain = str(
         self.env['ir.config_parameter'].sudo().get_param(
             'pipedrive_domain'))
     pipedrive_api_token = str(
         self.env['ir.config_parameter'].sudo().get_param(
             'pipedrive_api_token'))
     # api client
     client = Client(domain=pipedrive_domain)
     client.set_api_token(pipedrive_api_token)
     # get_info
     response = client.persons.get_all_persons()
     if 'success' in response:
         if response['success']:
             for data_item in response['data']:
                 data_item['owner_id'] = data_item['owner_id']['id']
                 # org_id
                 if data_item['org_id'] is not None:
                     if 'id' in data_item['org_id']:
                         data_item['org_id'] = data_item['org_id']['id']
                     else:
                         data_item['org_id'] = None
                 else:
                     data_item['org_id'] = None
                 # action_item
                 self.action_item({
                     'current': data_item,
                     'meta': {
                         'action': 'updated'
                     }
                 })
Beispiel #4
0
    def create_pipedrive_note(domain: str, api_token: str, conversation: str,
                              **kwargs):
        from pipedrive.client import Client

        client = Client(domain=domain)
        client.set_api_token(api_token)
        payload = {'content': conversation, 'lead_id': kwargs.get('lead_id')}
        return client.notes.create_note(payload)
Beispiel #5
0
def create_organization():
    url = 'https://companydomain.pipedrive.com/v1/organizations?api_token=' + apiToken
    client = Client(domain=url)  # autoryzation
    client.set_api_token(apiToken)

    data = {
        "name": getData.orgName,  # name of the organization
    }
    response = client.organizations.create_organization(data)
Beispiel #6
0
    def validate_pipedrive_credentials(domain: str, api_token: str):
        from pipedrive.client import Client
        from pipedrive.exceptions import UnauthorizedError

        try:
            client = Client(domain=domain)
            client.set_api_token(api_token)
            client.leads.get_all_leads()
        except UnauthorizedError as e:
            raise ActionFailure(e)
Beispiel #7
0
def get_organization():
    url = 'https://companydomain.pipedrive.com/v1/organizations?api_token=' + apiToken
    client = Client(domain=url)
    client.set_api_token(apiToken)

    helper = client.organizations.get_all_organizations()
    helper2 = (helper['data'])
    orgID = helper2[0]
    orgID = (orgID['id'])  # ID of company!!!!!!!!!!!!!
    return orgID
Beispiel #8
0
    def create_pipedrive_person(domain: str, api_token: str, **kwargs):
        from pipedrive.client import Client

        client = Client(domain=domain)
        client.set_api_token(api_token)
        email = [kwargs['email']] if kwargs.get('email') else None
        phone = [kwargs['phone']] if kwargs.get('phone') else None
        payload = {
            'name': kwargs.get('name'),
            'org_id': kwargs.get('org_id'),
            'email': email,
            'phone': phone
        }
        return client.persons.create_person(payload)
Beispiel #9
0
def get_user(howMany):
    url = 'https://api.pipedrive.com/v1/persons?start=0&api_token=' + apiToken
    client = Client(domain=url)
    response = client.set_api_token(apiToken)
    count = 0
    personID = []
    while count < howMany:
        helper = client.persons.get_all_persons()
        helper2 = helper['data']
        personID = helper2[count]
        personID = personID['id']  # ID persons, all persons !!!!!!!!!!!!!
        count += 1

    return personID
Beispiel #10
0
def add_users(how):
    # url = 'https://' + companyDomain + '.pipedrive.com/v1/persons/' + '?api_token=' + apiToken
    url = 'https://api.pipedrive.com/v1/persons?start=0&api_token=' + apiToken

    client = Client(domain=url)
    response = client.set_api_token(apiToken)
    count = 0
    orgID = get_organization()
    while count < how:
        data = {
            'name': getData.employees[count],  # add person with organization
            'org_id': orgID
        }

        response = client.persons.create_person(data)
        count += 1
Beispiel #11
0
 def cron_pipedrive_pipeline_exec(self):
     _logger.info('cron_pipedrive_pipeline_exec')
     # params
     pipedrive_domain = str(
         self.env['ir.config_parameter'].sudo().get_param(
             'pipedrive_domain'))
     pipedrive_api_token = str(
         self.env['ir.config_parameter'].sudo().get_param(
             'pipedrive_api_token'))
     # api client
     client = Client(domain=pipedrive_domain)
     client.set_api_token(pipedrive_api_token)
     # get_info
     response = client.pipelines.get_all_pipelines()
     if 'success' in response:
         if response['success']:
             for data_item in response['data']:
                 self.action_item(data_item)
Beispiel #12
0
    def create_pipedrive_lead(domain: str, api_token: str, title: str,
                              conversation: str, **kwargs):
        from pipedrive.client import Client

        client = Client(domain=domain)
        client.set_api_token(api_token)
        if kwargs.get('org_name'):
            organization = ActionUtility.create_pipedrive_organization(
                domain, api_token, **kwargs)
            kwargs['org_id'] = organization['id']
        person = ActionUtility.create_pipedrive_person(domain, api_token,
                                                       **kwargs)
        payload = {
            'title': title,
            'person_id': person['data']['id'],
            'organization_id': kwargs.get('org_id')
        }
        lead = client.leads.create_lead(payload)
        kwargs['lead_id'] = lead['data']['id']
        ActionUtility.create_pipedrive_note(domain, api_token, conversation,
                                            **kwargs)
Beispiel #13
0
 def cron_pipedrive_activity_exec(self):
     _logger.info('cron_pipedrive_activity_exec')
     # params
     pipedrive_domain = str(
         self.env['ir.config_parameter'].sudo().get_param(
             'pipedrive_domain'))
     pipedrive_api_token = str(
         self.env['ir.config_parameter'].sudo().get_param(
             'pipedrive_api_token'))
     # api client
     client = Client(domain=pipedrive_domain)
     client.set_api_token(pipedrive_api_token)
     # get_info
     response = client.activities.get_all_activities()
     if 'success' in response:
         if response['success']:
             for data_item in response['data']:
                 # keys_need_check
                 keys_need_check = ['owner_id']
                 for key_need_check in keys_need_check:
                     if key_need_check in data_item:
                         if data_item[key_need_check] is not None:
                             if 'id' in data_item[key_need_check]:
                                 data_item[key_need_check] = \
                                     data_item[key_need_check]['id']
                             else:
                                 data_item[key_need_check] = None
                         else:
                             data_item[key_need_check] = None
                 # action_item
                 self.action_item({
                     'current': data_item,
                     'meta': {
                         'action': 'updated'
                     }
                 })
    (table['amount_charged'] >= 50000) & (table['amount_charged'] < 100000),
    (table['amount_charged'] < 50000)
]
choices = [
    'above 2k', 'between 1k and 2k', 'between 500 and 1000', 'below 500'
]
table['Group'] = np.select(conditions, choices, default='null')

#Here I show some examples of some Pipedrive library that I use sometimes
from pipedrive.client import Client
#Here you can get data from your filters, probably you will need to paginate because this get only 100 deals so use the start to decide where you want to begin
filtered_deals = client.get_deals(filter_id=id_number, start=pagination)

#Here I show some examples of the Close.io api
from closeio_api import Client
api = Client('api_key')
data_lead = api.get(
    'lead',
    params={
        'query':
        'your query(you can test it at close io) or you can call a smartview'
    })
data_opportunity = api.get(
    'opportunity',
    params={
        'lead_query':
        'your query(you can test it at close io) or you can call a smartview'
    })

#Crawler
#Remember to use a webdriver
from flask import jsonify,request
import requests
import json
from pipedrive.client import Client
from flask_restful import Resource
from model.abc import db
from model import User
#from client import superhero
from util import parse_params
#import mysql.connector
#conn = mysql.connector.connect(host='localhost', database='mysql', user='******', password='******')
from .test import Analysis 

api_token="137f09ef7c288dedc165c51bce0a0cffe571e1d5"
domain_url="https://api.pipedrive.com/"
client = Client(api_base_url=domain_url)
client.set_token(api_token)

class UserListAPI(Resource):
    def get(self):

        # status = ""
        # url = domain_url+"/deals"
        # querystring = {"status":status,"api_token":api_token}
        # response = requests.request("GET", url, params=querystring)

        get_deals = client.get_deals()
        #return Analysis.callingDeals(get_deals)
        #Analysis.topTenDeals(get_deals)
        #print(get_deals)
        # json_data = json.loads(response.text)
Beispiel #16
0
from pipedrive.client import Client

client = Client(api_base_url="https://companydomain.pipedrive.com/")
Beispiel #17
0
def client():
    c = Client(
        api_base_url=os.environ['PIPEDRIVE_BASE_URL'],
        token=os.environ['PIPEDRIVE_API_KEY'],
    )
    return c