APIs & Integrations

VDrigin
Participant

Accessing deals via API

Résolue

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 Votes
1 Solution acceptée
JBeatty
Solution
Guide | Partenaire solutions Diamond
Guide | Partenaire solutions Diamond

Accessing deals via API

Résolue

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

Voir la solution dans l'envoi d'origine

6 Réponses
webdew
Guide | Partenaire solutions Diamond
Guide | Partenaire solutions Diamond

Accessing deals via API

Résolue

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 Votes
JBeatty
Guide | Partenaire solutions Diamond
Guide | Partenaire solutions Diamond

Accessing deals via API

Résolue

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

Résolue

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 Votes
JBeatty
Solution
Guide | Partenaire solutions Diamond
Guide | Partenaire solutions Diamond

Accessing deals via API

Résolue

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

Résolue

Thank you!

Updating the library worked!

 

0 Votes
dennisedson
Équipe de développement de HubSpot
Équipe de développement de HubSpot

Accessing deals via API

Résolue

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 😉