Exemplo n.º 1
0
def create():
    property_create = PropertyCreate(**request.form)
    hubspot = create_client()
    property = hubspot.crm.properties.core_api.create(
        ObjectType.CONTACTS, property_create=property_create)
    session[SessionKey.ACTION_PERFORMED] = "created"
    return redirect(url_for("properties.show", name=property.name), code=302)
Exemplo n.º 2
0
def create():
    properties = SimplePublicObjectInput(request.form)
    hubspot = create_client()
    contact = hubspot.crm.contacts.basic_api.create(
        simple_public_object_input=properties)
    session[SessionKey.ACTION_PERFORMED] = "created"
    return redirect(url_for("contacts.show", contact_id=contact.id))
Exemplo n.º 3
0
def show(contact_id):
    hubspot = create_client()
    all_properties = hubspot.crm().properties().core_api().get_all(
        ObjectType.CONTACTS)
    editable_properties = []
    for prop in all_properties.results:
        if prop.type == 'string' and prop.modification_metadata.read_only_value is False:
            editable_properties.append(prop)
    editable_properties_names = [p.name for p in editable_properties]
    editable_properties_names.append('hubspot_owner_id')
    contact = hubspot.crm().contacts().basic_api().get_by_id(
        contact_id,
        properties=editable_properties_names,
    )
    editable_properties_dict = {p.name: p for p in editable_properties}
    editable_properties_dict['hubspot_owner_id'] = {'label': 'Contact Owner'}

    contact.properties = {
        name: prop
        for name, prop in contact.properties.items()
        if name in editable_properties_dict
    }

    return render_template(
        'contacts/show.html',
        contact=contact,
        properties_dict=editable_properties_dict,
        owners=hubspot.crm().owners().get_all(),
        action_performed=session.pop(SessionKey.ACTION_PERFORMED, None),
    )
Exemplo n.º 4
0
def pipelines_list(board_id):
    hubspot = create_client()
    pipelines = hubspot.crm.pipelines.pipelines_api.get_all("deals")

    return render_template("mappings/pipelines.html",
                           board_id=board_id,
                           pipelines=pipelines.results)
Exemplo n.º 5
0
def new(company_id):
    hubspot = create_client()

    company = hubspot.crm().companies().basic_api().get_by_id(company_id)

    search_request = PublicObjectSearchRequest(
        sorts=[{
            'propertyName': 'createdate',
            'direction': 'DESCENDING',
        }])

    search = request.args.get('search')
    if search:
        filter = Filter(
            property_name='email',
            operator='EQ',
            value=search,
        )
        search_request.filter_groups = [FilterGroup(filters=[filter])]

    contacts_page = hubspot.crm().contacts().search_api().do_search(
        public_object_search_request=search_request)

    return render_template('associations/new.html',
                           search=search,
                           company=company,
                           contacts=contacts_page.results)
Exemplo n.º 6
0
def list(company_id):
    hubspot = create_client()
    company = hubspot.crm.companies.basic_api.get_by_id(company_id)

    associations = hubspot.crm.associations.batch_api.read(
        ObjectType.COMPANIES,
        ObjectType.CONTACTS,
        batch_input_public_object_id=BatchInputPublicObjectId(inputs=[company_id]),
    )
    inputs = []
    if associations.results:
        inputs = [
            SimplePublicObjectId(id=contact.id)
            for contact in associations.results[0].to
        ]
    associated_contacts = hubspot.crm.contacts.batch_api.read(
        batch_read_input_simple_public_object_id=BatchReadInputSimplePublicObjectId(
            inputs=inputs
        )
    )

    return render_template(
        "associations/list.html",
        company=company,
        associated_contacts=associated_contacts.results,
        action_performed=session.pop(SessionKey.ACTION_PERFORMED, None),
    )
Exemplo n.º 7
0
def new(company_id):
    hubspot = create_client()

    company = hubspot.crm.companies.basic_api.get_by_id(company_id)

    search_request = PublicObjectSearchRequest(
        sorts=[
            {
                "propertyName": "createdate",
                "direction": "DESCENDING",
            }
        ]
    )

    search = request.args.get("search")
    if search:
        filter = Filter(
            property_name="email",
            operator="EQ",
            value=search,
        )
        search_request.filter_groups = [FilterGroup(filters=[filter])]

    contacts_page = hubspot.crm.contacts.search_api.do_search(
        public_object_search_request=search_request
    )

    return render_template(
        "associations/new.html",
        search=search,
        company=company,
        contacts=contacts_page.results,
    )
Exemplo n.º 8
0
def handle():
    data = json.loads(request.data)
    # handle only "list" change event
    if "listAfter" in data["action"]["data"]:
        board_list_id = data["action"]["data"]["listAfter"]["id"]
        card_id = data["model"]["id"]
        associations = AssociationsRepository.find_by_card_id(card_id)
        hubspot = create_client()
        for association in associations:
            deal_id = association.deal_id
            deal = hubspot.crm.deals.basic_api.get_by_id(deal_id)
            mapping = (session.query(Mapping).filter_by(
                board_list_id=board_list_id,
                pipeline_id=deal.properties["pipeline"],
            ).first())
            session.commit()
            if mapping is not None:
                simple_public_object_input = SimplePublicObjectInput(
                    properties={"dealstage": mapping.pipeline_stage_id}, )
                hubspot.crm.deals.basic_api.update(
                    deal_id=deal_id,
                    simple_public_object_input=simple_public_object_input,
                )

    return "", HTTPStatus.OK
Exemplo n.º 9
0
def update(contact_id):
    properties = SimplePublicObject(properties=request.form)
    hubspot = create_client()
    hubspot.crm.contacts.basic_api.update(
        contact_id, simple_public_object_input=properties)
    session[SessionKey.ACTION_PERFORMED] = "updated"
    return redirect(request.url)
Exemplo n.º 10
0
def list():
    events = session.query(Event).order_by(
        Event.occurred_at.desc()).limit(50).all()
    session.commit()
    hubspot = create_client()

    inputs = [SimplePublicObjectId(id=e.object_id) for e in events]
    batch_read_input_simple_public_object_id = BatchReadInputSimplePublicObjectId(
        inputs=inputs, )
    contacts = hubspot.crm.contacts.batch_api.read(
        batch_read_input_simple_public_object_id=
        batch_read_input_simple_public_object_id, ).results
    contacts_dict = {
        int(contact.id): {
            "fullname": (contact.properties["firstname"] or "") + " " +
            (contact.properties["lastname"] or "")
        }
        for contact in contacts
    }

    return render_template(
        "events/list.html",
        events=events,
        contacts_dict=contacts_dict,
        now=datetime.datetime.now(),
    )
Exemplo n.º 11
0
def show(contact_id):
    hubspot = create_client()
    all_properties = hubspot.crm.properties.core_api.get_all(
        ObjectType.CONTACTS)
    editable_properties = []
    for prop in all_properties.results:
        if (prop.type == "string"
                and prop.modification_metadata.read_only_value is False):
            editable_properties.append(prop)
    editable_properties_names = [p.name for p in editable_properties]
    editable_properties_names.append("hubspot_owner_id")
    contact = hubspot.crm.contacts.basic_api.get_by_id(
        contact_id,
        properties=editable_properties_names,
    )
    editable_properties_dict = {p.name: p for p in editable_properties}
    editable_properties_dict["hubspot_owner_id"] = {"label": "Contact Owner"}

    contact.properties = {
        name: prop
        for name, prop in contact.properties.items()
        if name in editable_properties_dict
    }

    return render_template(
        "contacts/show.html",
        contact=contact,
        properties_dict=editable_properties_dict,
        owners=hubspot.crm.owners.get_all(),
        action_performed=session.pop(SessionKey.ACTION_PERFORMED, None),
    )
Exemplo n.º 12
0
def call_api():
    hubspot = create_client()
    try:
        hubspot.crm.contacts.basic_api.get_page()
        logger.info("Requesting get_page: success")
    except ApiException as e:
        logger.error("Exception occurred, status code: ".format(e.status))
Exemplo n.º 13
0
def list(board_id, pipeline_id):
    trello = get_client()
    board = trello.get_board(board_id)
    board_lists = board.list_lists()

    hubspot = create_client()
    pipeline = hubspot.crm.pipelines.pipelines_api.get_by_id(
        "deals", pipeline_id)

    mappings = MappingsRepository.find_by(
        board_id=board_id,
        pipeline_id=pipeline_id,
    )
    mappings.append({
        "id": None,
        "board_list_id": None,
        "pipeline_stage_id": None,
    })

    return render_template(
        "mappings/list.html",
        mappings=mappings,
        board=board,
        board_lists=board_lists,
        pipeline=pipeline,
        JOIN_SEPARATOR=JOIN_SEPARATOR,
    )
Exemplo n.º 14
0
def update(company_id):
    properties = SimplePublicObjectInput(properties=request.form)
    hubspot = create_client()
    company = hubspot.crm.companies.basic_api.update(
        company_id, simple_public_object_input=properties)
    session[SessionKey.ACTION_PERFORMED] = "updated"
    return redirect(url_for("companies.show", company_id=company.id))
Exemplo n.º 15
0
def update(name):
    property_update = PropertyUpdate(**request.form)
    hubspot = create_client()
    hubspot.crm.properties.core_api.update(ObjectType.CONTACTS,
                                           name,
                                           property_update=property_update)
    session[SessionKey.ACTION_PERFORMED] = "updated"
    return redirect(request.url, code=302)
Exemplo n.º 16
0
def show(name):
    hubspot = create_client()
    property = hubspot.crm().properties().core_api().get_by_name(ObjectType.CONTACTS, name)

    return render_template(
        'properties/show.html',
        property=property,
        action_performed=session.pop(SessionKey.ACTION_PERFORMED, None),
    )
Exemplo n.º 17
0
def list():
    hubspot = create_client()
    properties = hubspot.crm().properties().core_api().get_all(ObjectType.CONTACTS)

    return render_template(
        'properties/list.html',
        properties=properties.results,
        action_performed=session.pop(SessionKey.ACTION_PERFORMED, None),
    )
Exemplo n.º 18
0
def show(company_id):
    hubspot = create_client()
    company = hubspot.crm.companies.basic_api.get_by_id(company_id)

    return render_template(
        "companies/show.html",
        company=company,
        action_performed=session.pop(SessionKey.ACTION_PERFORMED, None),
    )
Exemplo n.º 19
0
def call_api():
    # Pay attention on create_client.
    # It generates a client with reties middlewares.
    hubspot = create_client()
    try:
        page = hubspot.crm.contacts.basic_api.get_page()
        if os.getppid() == 0:
            logger.info("Requesting get_page: success")
    except ApiException as e:
        logger.error("Exception occurred, status code: ".format(e.status))
Exemplo n.º 20
0
def callback():
    hubspot = create_client()
    tokens_response = hubspot.auth.oauth.default_api.create_token(
        grant_type="authorization_code",
        code=request.args.get("code"),
        redirect_uri=get_redirect_uri(),
        client_id=os.environ.get("HUBSPOT_CLIENT_ID"),
        client_secret=os.environ.get("HUBSPOT_CLIENT_SECRET"),
    )
    save_tokens_response(tokens_response)

    return redirect(url_for("home"))
Exemplo n.º 21
0
def callback():
    hubspot = create_client()
    tokens_response = hubspot.auth.oauth.default_api.create_token(
        grant_type='authorization_code',
        code=request.args.get('code'),
        redirect_uri=get_redirect_uri(),
        client_id=os.environ.get('HUBSPOT_CLIENT_ID'),
        client_secret=os.environ.get('HUBSPOT_CLIENT_SECRET'),
    )
    save_tokens(tokens_response)

    return redirect('/')
Exemplo n.º 22
0
def list():
    hubspot = create_client()
    search_request = PublicObjectSearchRequest(sorts=[{
        'propertyName': 'createdate',
        'direction': 'DESCENDING',
    }])
    companies_page = hubspot.crm().companies().search_api().do_search(public_object_search_request=search_request)

    return render_template(
        'companies/list.html',
        companies=companies_page.results,
        action_performed=session.pop(SessionKey.ACTION_PERFORMED, None),
    )
Exemplo n.º 23
0
def list():
    hubspot = create_client()
    search_request = PublicObjectSearchRequest(
        sorts=[{
            "propertyName": "createdate",
            "direction": "DESCENDING",
        }])
    contacts_page = hubspot.crm.contacts.search_api.do_search(
        public_object_search_request=search_request)

    return render_template(
        "contacts/list.html",
        contacts=contacts_page.results,
        action_performed=session.pop(SessionKey.ACTION_PERFORMED, None),
    )
Exemplo n.º 24
0
def create(company_id, contact_id):
    hubspot = create_client()
    association = PublicAssociation(
        _from=PublicObjectId(id=company_id),
        to=PublicObjectId(id=contact_id),
        type=AssociationType.COMPANY_TO_CONTACT,
    )
    batch_input_public_association = BatchInputPublicAssociation(inputs=[association])
    hubspot.crm.associations.batch_api.create(
        ObjectType.COMPANIES,
        ObjectType.CONTACTS,
        batch_input_public_association=batch_input_public_association,
    )
    session[SessionKey.ACTION_PERFORMED] = "created"

    return redirect(url_for("associations.list", company_id=company_id))
Exemplo n.º 25
0
def export():
    si = io.StringIO()
    writer = csv.writer(si)
    writer.writerow(["Email", "Firstname", "Lastname"])

    hubspot = create_client()
    contacts = hubspot.crm.contacts.get_all()
    for contact in contacts:
        writer.writerow([
            contact.properties["email"],
            contact.properties["firstname"],
            contact.properties["lastname"],
        ])

    output = make_response(si.getvalue())
    output.headers["Content-Disposition"] = "attachment; filename=contacts.csv"
    output.headers["Content-type"] = "text/csv"
    return output
Exemplo n.º 26
0
def search():
    hubspot = create_client()
    search = request.args.get("search")

    filter = Filter(
        property_name="email",
        operator="EQ",
        value=search,
    )
    filter_group = FilterGroup(filters=[filter])
    public_object_search_request = PublicObjectSearchRequest(
        filter_groups=[filter_group], )
    contacts_page = hubspot.crm.contacts.search_api.do_search(
        public_object_search_request=public_object_search_request)

    return render_template("contacts/list.html",
                           contacts=contacts_page.results,
                           search=search)
Exemplo n.º 27
0
def search():
    hubspot = create_client()
    search = request.args.get('search')

    filter = Filter(
        property_name='domain',
        operator='EQ',
        value=search,
    )
    filter_group = FilterGroup(filters=[filter])
    public_object_search_request = PublicObjectSearchRequest(
        filter_groups=[filter_group], )
    companies_page = hubspot.crm.companies.search_api.do_search(
        public_object_search_request=public_object_search_request)

    return render_template('companies/list.html',
                           companies=companies_page.results,
                           search=search)
Exemplo n.º 28
0
def start():
    file = request.files["file"]

    handle, filepath = tempfile.mkstemp(suffix=".csv")
    os.close(handle)
    file.save(filepath)

    import_request = {
        "name":
        "Import '{}'".format(file.filename),
        "files": [{
            "fileName": os.path.basename(filepath),
            "fileImportPage": {
                "hasHeader":
                True,
                "columnMappings": [
                    {
                        "columnName": "First Name",
                        "propertyName": "firstname",
                        "columnObjectType": "CONTACT",
                    },
                    {
                        "columnName": "Email",
                        "propertyName": "email",
                        "columnObjectType": "CONTACT",
                    },
                ],
            },
        }],
    }
    hubspot = create_client()
    import_data = hubspot.crm.imports.core_api.create(
        files=filepath, import_request=json.dumps(import_request))

    os.unlink(filepath)

    return redirect(url_for("imports.show", import_id=import_data.id))
Exemplo n.º 29
0
def list():
    hubspot = create_client()
    contacts_page = hubspot.crm.contacts.basic_api.get_page()

    return render_template("contacts/list.html", contacts=contacts_page.results)
Exemplo n.º 30
0
def delete(contact_id):
    hubspot = create_client()
    hubspot.crm.contacts.basic_api.archive(contact_id)
    session[SessionKey.ACTION_PERFORMED] = "deleted"
    return redirect(url_for("contacts.list"))