# Accessing deals via API

**URL:** <https://community.hubspot.com/t/accessing-deals-via-api/41480>\
**Category:** APIs & Integrations\
**Tags:** python\
**Created:** [July 29, 2021, 11:15am UTC](https://community.hubspot.com/t/accessing-deals-via-api/41480 "2021-07-29T11:15:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![VDrigin](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/vdrigin/32/78108_2.png) [@VDrigin](https://community.hubspot.com/u/VDrigin)\
**Post date:** [July 29, 2021, 11:15am UTC](https://community.hubspot.com/t/accessing-deals-via-api/41480/1 "2021-07-29T11:15:52Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [July 29, 2021, 6:56pm UTC](https://community.hubspot.com/t/accessing-deals-via-api/41480/2 "2021-07-29T18:56:06Z")

</div>

First, want to make sure you saw @BJacobson 's [resource](https://community.hubspot.com/t5/Share-Your-Work/Using-the-HubSpot-API-with-Python/td-p/465332) that he shared. It is contacts specific, but is good info.

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

---

<div class="post-metadata">

**Author:** ![JBeatty](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jbeatty/32/52252_2.png) [@JBeatty](https://community.hubspot.com/u/JBeatty)\
**Post date:** [July 29, 2021, 7:24pm UTC](https://community.hubspot.com/t/accessing-deals-via-api/41480/3 "2021-07-29T19:24:50Z")

</div>

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:

```lia-code-sample
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.

---

<div class="post-metadata">

**Author:** ![VDrigin](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/vdrigin/32/78108_2.png) [@VDrigin](https://community.hubspot.com/u/VDrigin)\
**Post date:** [July 30, 2021, 12:02pm UTC](https://community.hubspot.com/t/accessing-deals-via-api/41480/4 "2021-07-30T12:02:40Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![JBeatty](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jbeatty/32/52252_2.png) [@JBeatty](https://community.hubspot.com/u/JBeatty)\
**Post date:** [July 30, 2021, 2:23pm UTC](https://community.hubspot.com/t/accessing-deals-via-api/41480/5 "2021-07-30T14:23:43Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![VDrigin](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/vdrigin/32/78108_2.png) [@VDrigin](https://community.hubspot.com/u/VDrigin)\
**Post date:** [August 5, 2021, 8:16am UTC](https://community.hubspot.com/t/accessing-deals-via-api/41480/6 "2021-08-05T08:16:32Z")

</div>

Thank you!

Updating the library worked!

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [August 2, 2021, 1:44pm UTC](https://community.hubspot.com/t/accessing-deals-via-api/41480/7 "2021-08-02T13:44:37Z")

</div>

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=dealname](https://api.hubapi.com/deals/v1/deal/paged?hapikey=demo&includeAssociations=true&limit=2&properties=dealname)’;  
$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 : [Accounts Dashboard | HubSpot](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.
