HubSpot Deals data to MySQL Database

In this article, we're following the below steps for copying the data to MySQL.


  • Python Environment

  • MySQL, either in a Local or Server Environment

  • HubSpot account admin access and Private App token

Once you logged into HubSpot, create the Private app located under Settings -> Integration -> Private App in your HubSpot(HS) account.

Get the Access token and have it securely.

Now the code Part coming into the blog,

Install the required packages below in Python Shell using the terminal,

pip3 install hubspot-api-client
pip3 install hubspot
pip3 install mysql-connector-python

Next, let's create a Credentials file named `` and add the below code.

user = USER_NAME
password = PASSWORD
host = "localhost"
database = DATABASE_NAME

Let's explore the developer documentation from HubSpot here.

As we are fetching the Deals data from HS, Below is the class for getting the Deal info,,after=after, archived=False, properties = {})

The above line returns the Json response. Hence we're looping all the desired properties every single record using for loop as below.

for deal_dict in deal_json["results"]:
    amount = deal_dict['properties']['amount']

And here's the full source code of how it's solved.

import hubspot
from hubspot.crm.pipelines import ApiException
import mysql.connector
import config.MySQLCredentials as mc

client = hubspot.Client.create(access_token="ACCESS_TOKEN")

mydb = mysql.connector.connect(,
mycursor = mydb.cursor()

after = 0
counter = 1
    while after or after == 0:
            api_response =,after=after, archived=False, properties=["amount", "amount_in_home_currency", "city"])

            deal_json = api_response.to_dict()
            for deal_dict in deal_json["results"]:
                amount = deal_dict['properties']['amount']
                amount_in_home_currency = deal_dict['properties']['amount_in_home_currency']
                city = str(deal_dict['properties']['city'])

### Database section Start ###
                values = (amount, amount_in_home_currency, city)
                query = "INSERT INTO Deals (`Amount`, `Amount in company currency`, `City`) VALUES (%s, %s, %s)"
                cur.execute(query, values)
            except Exception as e:
### Database section END ###

            after = deal_json["paging"]["next"]["after"] if "paging" in deal_json else ''
            counter = counter + 1
            if after is None:
                after = False
        except Exception as e:
            print("Exception : ",e)

except ApiException as e:
    print("Exception when calling basic_api->get_page: %s\n" % e)

Finally, you got all the Deals Info in SQL table.