<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Trouble connecting with OAuth with Python client in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Trouble-connecting-with-OAuth-with-Python-client/m-p/724039#M59103</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently trying to simply connect to my app with the python client using OAuth, so I've read &lt;A href="https://developers.hubspot.com/docs/api/oauth-quickstart-guide" target="_blank" rel="noopener"&gt;the doc&lt;/A&gt; and &lt;A href="https://github.com/HubSpot/hubspot-api-python" target="_blank" rel="noopener"&gt;the GitHub repo&lt;/A&gt; but cannot figure out how to authenticate and get an access token.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from hubspot.auth.oauth import ApiException

try:
    tokens = api_client.auth.oauth.tokens_api.create_token(
        grant_type="authorization_code",
        redirect_uri='http://localhost',
        client_id='client_id',
        client_secret='client_secret',
        code='code'
    )
except ApiException as e:
    print("Exception when calling create_token method: %s\n" % e)&lt;/LI-CODE&gt;&lt;P&gt;With this sample, you get the access token, but to do that you need the code passed as parameter that according to the doc, you need to call the authorize url first to get a code.&lt;/P&gt;&lt;P&gt;To my understanding you need to call the URL, then get the code after being redirected, but I don't see a way to do that with the python client.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After that, I am trying to push a contact using this&lt;/P&gt;&lt;LI-CODE lang="python"&gt;new_contact = SimplePublicObjectInput(properties=data)
  try:
      res = hubspot_client.crm.contacts.basic_api.create(simple_public_object_input=new_contact)
  except ApiException as e:
      logger.error(f'Failed to create contact in HubSpot: {e}')&lt;/LI-CODE&gt;&lt;P&gt;Is this also a good way to do things ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I feel like either I am missing something obvious or the doc is misleading.&lt;/P&gt;&lt;P&gt;Can anyone help me figure this out ?&lt;/P&gt;&lt;P&gt;I would really appreciate the help,&lt;/P&gt;&lt;P&gt;Matthieu&lt;/P&gt;</description>
    <pubDate>Tue, 29 Nov 2022 10:58:23 GMT</pubDate>
    <dc:creator>AMeilleurecop</dc:creator>
    <dc:date>2022-11-29T10:58:23Z</dc:date>
    <item>
      <title>Trouble connecting with OAuth with Python client</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Trouble-connecting-with-OAuth-with-Python-client/m-p/724039#M59103</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am currently trying to simply connect to my app with the python client using OAuth, so I've read &lt;A href="https://developers.hubspot.com/docs/api/oauth-quickstart-guide" target="_blank" rel="noopener"&gt;the doc&lt;/A&gt; and &lt;A href="https://github.com/HubSpot/hubspot-api-python" target="_blank" rel="noopener"&gt;the GitHub repo&lt;/A&gt; but cannot figure out how to authenticate and get an access token.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from hubspot.auth.oauth import ApiException

try:
    tokens = api_client.auth.oauth.tokens_api.create_token(
        grant_type="authorization_code",
        redirect_uri='http://localhost',
        client_id='client_id',
        client_secret='client_secret',
        code='code'
    )
except ApiException as e:
    print("Exception when calling create_token method: %s\n" % e)&lt;/LI-CODE&gt;&lt;P&gt;With this sample, you get the access token, but to do that you need the code passed as parameter that according to the doc, you need to call the authorize url first to get a code.&lt;/P&gt;&lt;P&gt;To my understanding you need to call the URL, then get the code after being redirected, but I don't see a way to do that with the python client.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After that, I am trying to push a contact using this&lt;/P&gt;&lt;LI-CODE lang="python"&gt;new_contact = SimplePublicObjectInput(properties=data)
  try:
      res = hubspot_client.crm.contacts.basic_api.create(simple_public_object_input=new_contact)
  except ApiException as e:
      logger.error(f'Failed to create contact in HubSpot: {e}')&lt;/LI-CODE&gt;&lt;P&gt;Is this also a good way to do things ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I feel like either I am missing something obvious or the doc is misleading.&lt;/P&gt;&lt;P&gt;Can anyone help me figure this out ?&lt;/P&gt;&lt;P&gt;I would really appreciate the help,&lt;/P&gt;&lt;P&gt;Matthieu&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 10:58:23 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Trouble-connecting-with-OAuth-with-Python-client/m-p/724039#M59103</guid>
      <dc:creator>AMeilleurecop</dc:creator>
      <dc:date>2022-11-29T10:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble connecting with OAuth with Python client</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Trouble-connecting-with-OAuth-with-Python-client/m-p/724951#M59195</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/483873"&gt;@AMeilleurecop&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":waving_hand:"&gt;👋&lt;/span&gt; Thanks for reaching out. Hey,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/153634"&gt;@tominal&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/193060"&gt;@JBeatty&lt;/a&gt;&amp;nbsp;do yhou have any tips you can share with&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/483873"&gt;@AMeilleurecop&lt;/a&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;Jaycee&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 19:23:37 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Trouble-connecting-with-OAuth-with-Python-client/m-p/724951#M59195</guid>
      <dc:creator>Jaycee_Lewis</dc:creator>
      <dc:date>2022-11-30T19:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble connecting with OAuth with Python client</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Trouble-connecting-with-OAuth-with-Python-client/m-p/725181#M59228</link>
      <description>&lt;P&gt;Hi and thanks for your response,&lt;/P&gt;&lt;P&gt;I managed to do it by simply not using the python library to get the temporary code. I'm just getting it manually through a browser and using the refresh token generated to get the token when I need to.&lt;/P&gt;&lt;P&gt;I honestly find it not optimal as I would have prefered to do it programmatically through and through, but seeing as the doc does not help in that regard, it will have to do &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 08:00:07 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Trouble-connecting-with-OAuth-with-Python-client/m-p/725181#M59228</guid>
      <dc:creator>AMeilleurecop</dc:creator>
      <dc:date>2022-12-01T08:00:07Z</dc:date>
    </item>
  </channel>
</rss>

