APIs & Integrations

VDrigin
Participant

Accessing deals via API

SOLVE

The update version of a code to access deals via API does not work for me.

 

import hubspot
from pprint import pprint
from hubspot.crm.deals import

client = hubspot.Client.create(api_key="YOUR_HUBSPOT_API_KEY");

try:
api_response = client.crm.deals.basic_api.get_page(limit=10, archived=False)
pprint(api_response)
except ApiException as e:
print("Exception when calling basic_api->get_page: %s\n" % e)

 

However, the old version worked just fine. 

What is the problem?

Thank you!

0 Upvotes
1 Accepted solution
JBeatty
Solution
Guide | Diamond Partner
Guide | Diamond Partner

Accessing deals via API

SOLVE

Hi @VDrigin,

 

What line of the code is giving the error? Also what version of python are you running? Also, try to update the package using:

pip install --upgrade hubspot-api-client

✔️ Was I able to help answer your question? Help the community by marking it as a solution.

Joshua Beatty
Software Developer with Pearagon

Still have questions? Let's Talk

View solution in original post

6 Replies 6
webdew
Guide | Diamond Partner
Guide | Diamond Partner

Accessing deals via API

SOLVE

Hi @VDrigin ,

Please try with below code and get deals.

<?php
$url = 'https://api.hubapi.com/deals/v1/deal/paged?hapikey=demo&includeAssociations=true&limit=2&properties=...';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');

$headers = array();
$headers[] = 'Content-Type: application/json';

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);

if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$result = json_decode($result);
return $result;
?>

Documentation Link : https://legacydocs.hubspot.com/docs/methods/deals/get-all-deals


Hope this helps!


If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards. 

0 Upvotes
JBeatty
Guide | Diamond Partner
Guide | Diamond Partner

Accessing deals via API

SOLVE

Hi @VDrigin,

 

I am not super familiar with the python API for HubSpot, but after copying your code and modifying it slightly I got this to work:

from hubspot import HubSpot
from pprint import pprint

client = HubSpot(api_key="YOUR_API_KEY")

try:
    api_response = client.crm.deals.basic_api.get_page(limit=10, archived=False)
    pprint(api_response)
except Exception as e:
    print("Exception when calling basic_api->get_page: %s\n" % e)

I believe the issue with your original code was how you were creating your client, and with how you were importing the HubSpot library. 

✔️ Was I able to help answer your question? Help the community by marking it as a solution.

Joshua Beatty
Software Developer with Pearagon

Still have questions? Let's Talk

VDrigin
Participant

Accessing deals via API

SOLVE

Hi, 

Now I am getting the following error:

 

SyntaxError: You must include a hapi_key or access_token attribute when initalizing the API

 

Thank you!

0 Upvotes
JBeatty
Solution
Guide | Diamond Partner
Guide | Diamond Partner

Accessing deals via API

SOLVE

Hi @VDrigin,

 

What line of the code is giving the error? Also what version of python are you running? Also, try to update the package using:

pip install --upgrade hubspot-api-client

✔️ Was I able to help answer your question? Help the community by marking it as a solution.

Joshua Beatty
Software Developer with Pearagon

Still have questions? Let's Talk

VDrigin
Participant

Accessing deals via API

SOLVE

Thank you!

Updating the library worked!

 

0 Upvotes
dennisedson
HubSpot Product Team
HubSpot Product Team

Accessing deals via API

SOLVE

First, want to make sure you saw @BJacobson 's resource that he shared.  It is contacts specific, but is good info.

Secondly, going to also throw @JBeatty into the mix here for some help 😉


Join us on March 27th at 12 PM for the Digital Essentials Lab, an interactive session designed to redefine your digital strategy!
Engage with expert Jourdan Guyton to gain actionable insights, participate in live Q&A, and learn strategies to boost your business success.
Don't miss this opportunity to connect and grow—reserve your spot today!