APIs & Integrations

A_mirKhan37
Member

How can I pass a method as an argument to a function?

I'm trying to download data from Hubspot with the Python helper library from several tables

from hubspot import HubSpot

api_client = HubSpot()
api_client.access_token = 'TOKEN'

contacts = api_client.crm.contacts.get_all()
tickets = api_client.crm.tickets.get_all()
deals = api_client.crm.deals.get_all()
and so on...

Instead of calling every table in a separate way, I was thiniking about looping over a list like this: Website

def getting_tables (table, api_client):
    return api_client.crm.table.get_all()

api_client = HubSpot()
api_client.access_token = 'TOKEN'

tables = ['contacts', 'tickets', 'deals', 'owners' ]

for table in tables:
    table = getting_tables(table,api_client)

but when I call api_client.crm.table.get_all() it doesnt take "table" as a place holder for what it comes when I call the function. How could I do that? Is that possible?

I know I could just call them all separately, but this is for learning purposes mostly.

0 Upvotes
1 Reply 1
dennisedson
HubSpot Product Team
HubSpot Product Team

How can I pass a method as an argument to a function?

@HOrdonez , @akaiser 

Can either of you help out here 😀

0 Upvotes