Accessing deals via API

SOLVE
VDrigin
Participant

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

Accepted Solutions
JBeatty
Solution
Top Contributor | Platinum Partner

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
dennisedson
Community Manager

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 😉

Thanks,

Dennis




Check out our Community Developer Blog
where we feature our Community driven developer podcast and how to content
JBeatty
Top Contributor | Platinum Partner

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

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
Top Contributor | Platinum Partner

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

VDrigin
Participant

Thank you!

Updating the library worked!

 

0 Upvotes
webdew
Top Contributor | Diamond Partner

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