I’ve been trying to write a code to autofill the CVR number of a company when it is created. I have a code which I think should work but it isn’t at the moment. Can anyone help me on this? Below is the code I have so far:
import requests
from bs4 import BeautifulSoup
YOUR_HUBSPOT_ACCESS_TOKEN = “For my eyes only”
# Function to get the CVR of the company
def get_company_cvr(domain![]()
url = 'https://' + domain
try:
response = requests.get(url,verify=False)
except requests.exceptions.SSLError as e:
print(f"SSL error: {e}")
return 'CVR not found'
soup = BeautifulSoup(response.text, 'html.parser')
cvr\_tag = soup.find('span', class\_='cvr-number')
if cvr\_tag:
return cvr\_tag.text
else:
return 'CVR not found'
# Function to get the recently created companies
def get_recent_companies():
headers = {
'Authorization': 'Bearer YOUR\_HUBSPOT\_ACCESS\_TOKEN'
}
url = "https://api.hubapi.com/companies/v2/companies/recent/created"
response = requests.get(url, headers=headers)
return response.json()
# Function to update the CVR of a company
def update_company_cvr(company_id, cvr![]()
url = f"https://api.hubapi.com/companies/v2/companies/{company\_id}?access\_token={YOUR\_HUBSPOT\_ACCESS\_TOKEN}"
data = {
"properties": \[
{
"name": "cvr",
"value": cvr
}
]
}
headers = {'content-type': 'application/json'}
requests.patch(url, json=data, headers=headers)
# Main function
def main():
# Get the recent companies
recent\_companies = get\_recent\_companies()
# Update the CVR of each recently created company
for company in recent\_companies\['results']:
domain = company\["properties"]\["domain"]\["value"]
cvr = get\_company\_cvr(domain)
update\_company\_cvr(company\["companyId"], cvr)