<?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 Re: api calls from local env in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/api-calls-from-local-env/m-p/546498#M49679</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/300751"&gt;@KToo&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A few things here,&amp;nbsp; first the reason it is being blocked is becuase browsers these days block most post requests from the client unless the endpoint specifically enables &lt;A href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS" target="_blank" rel="noopener"&gt;Cross-Origin Resource Sharing (CORS)&lt;/A&gt;. Which the hubspot endpoints do not. To get around this you'll need to set up another endpoint on a seperate server. I would recommend using AWS serverless functions, which are free for most users' small loads, and you can enable CORS on your endpoints.&lt;BR /&gt;&lt;BR /&gt;Secondly &lt;STRONG&gt;do not put this code in the browser ever&lt;/STRONG&gt;. You had the api key in the browser, if for some reason HubSpot did enable CORS, any person could go into the wordpress code and grab your api key, and grab all of your contact data, and then delete all of your contact for example.&lt;STRONG&gt; Never use your api key client side&lt;/STRONG&gt;. Even if somehow you encrypt it, the request will still be unencrypted and they grab the api key by intercepting the request. This can also be fixed by setting up an endpoint soemwhere like AWS, where the call to this endpoint does not include the api key, but the code in AWS does have it.&lt;BR /&gt;&lt;BR /&gt;Lastly, it looks like you are using a form to create leads, this can be completely avoided if you &lt;A href="https://knowledge.hubspot.com/forms/create-forms" target="_blank" rel="noopener"&gt;create a hubspot form&lt;/A&gt; which you can embed in your website. Then you do not have to mess with any code, or wory about your API key at all, and leads just get created when they fill out the form.&lt;BR /&gt;&lt;BR /&gt;If you are just trying to test your API calls, then I would recomend a REST client, like &lt;A href="https://hoppscotch.io/" target="_blank" rel="noopener"&gt;Hopscotch&lt;/A&gt; or &lt;A href="https://www.postman.com/" target="_blank" rel="noopener"&gt;Postman&lt;/A&gt;. Neither of which have this CORS restriction. Another solution would be to test your API calls form the command line using a tool like curL, or running a Node app from the commandline, where you could still use axios.&lt;/P&gt;</description>
    <pubDate>Thu, 23 Dec 2021 15:33:03 GMT</pubDate>
    <dc:creator>JBeatty</dc:creator>
    <dc:date>2021-12-23T15:33:03Z</dc:date>
    <item>
      <title>api calls from local env</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/api-calls-from-local-env/m-p/546479#M49678</link>
      <description>&lt;P&gt;I have a very simple form I created in wordpress and I used axios to post an email address using your CreateOrUpdate api endpoint like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt;&lt;SPAN&gt; newLead &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;{&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;properties&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;SPAN&gt; [&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &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gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;const&lt;/SPAN&gt; &lt;SPAN&gt;email&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;this&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;email&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;value&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;const&lt;/SPAN&gt; &lt;SPAN&gt;apiCall&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;`&lt;/SPAN&gt;&lt;SPAN&gt;&lt;A href="https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/" target="_blank"&gt;https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN&gt;${&lt;/SPAN&gt;&lt;SPAN&gt;email&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;/?hapikeys=&lt;/SPAN&gt;&lt;SPAN&gt;${&lt;/SPAN&gt;&lt;SPAN&gt;this&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;apiKey&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;`&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;try&lt;/SPAN&gt; &lt;SPAN&gt;{&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;const&lt;/SPAN&gt; &lt;SPAN&gt;response&lt;/SPAN&gt; &lt;SPAN&gt;=&lt;/SPAN&gt; &lt;SPAN&gt;await&lt;/SPAN&gt;&lt;SPAN&gt; axios&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;post&lt;/SPAN&gt;&lt;SPAN&gt;(apiCall&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt; newLead)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt; &lt;SPAN&gt;catch&lt;/SPAN&gt;&lt;SPAN&gt; (e) &lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; console&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;log&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;Sorry, couldn't add lead&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I am running into this problem:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Access to XMLHttpRequest at '&lt;A href="https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/a@b.com/?hapikeys=myApiKey" target="_blank"&gt;https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/a@b.com/?hapikeys=myApiKey&lt;/A&gt;' from origin '&lt;A href="http://php.local" target="_blank"&gt;http://php.local&lt;/A&gt;' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using my testing account api key for this. I also tried using the api key in my "real" account but neither worked. Please advise. Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 14:56:52 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/api-calls-from-local-env/m-p/546479#M49678</guid>
      <dc:creator>KToo</dc:creator>
      <dc:date>2021-12-23T14:56:52Z</dc:date>
    </item>
    <item>
      <title>Re: api calls from local env</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/api-calls-from-local-env/m-p/546498#M49679</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/300751"&gt;@KToo&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A few things here,&amp;nbsp; first the reason it is being blocked is becuase browsers these days block most post requests from the client unless the endpoint specifically enables &lt;A href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS" target="_blank" rel="noopener"&gt;Cross-Origin Resource Sharing (CORS)&lt;/A&gt;. Which the hubspot endpoints do not. To get around this you'll need to set up another endpoint on a seperate server. I would recommend using AWS serverless functions, which are free for most users' small loads, and you can enable CORS on your endpoints.&lt;BR /&gt;&lt;BR /&gt;Secondly &lt;STRONG&gt;do not put this code in the browser ever&lt;/STRONG&gt;. You had the api key in the browser, if for some reason HubSpot did enable CORS, any person could go into the wordpress code and grab your api key, and grab all of your contact data, and then delete all of your contact for example.&lt;STRONG&gt; Never use your api key client side&lt;/STRONG&gt;. Even if somehow you encrypt it, the request will still be unencrypted and they grab the api key by intercepting the request. This can also be fixed by setting up an endpoint soemwhere like AWS, where the call to this endpoint does not include the api key, but the code in AWS does have it.&lt;BR /&gt;&lt;BR /&gt;Lastly, it looks like you are using a form to create leads, this can be completely avoided if you &lt;A href="https://knowledge.hubspot.com/forms/create-forms" target="_blank" rel="noopener"&gt;create a hubspot form&lt;/A&gt; which you can embed in your website. Then you do not have to mess with any code, or wory about your API key at all, and leads just get created when they fill out the form.&lt;BR /&gt;&lt;BR /&gt;If you are just trying to test your API calls, then I would recomend a REST client, like &lt;A href="https://hoppscotch.io/" target="_blank" rel="noopener"&gt;Hopscotch&lt;/A&gt; or &lt;A href="https://www.postman.com/" target="_blank" rel="noopener"&gt;Postman&lt;/A&gt;. Neither of which have this CORS restriction. Another solution would be to test your API calls form the command line using a tool like curL, or running a Node app from the commandline, where you could still use axios.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 15:33:03 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/api-calls-from-local-env/m-p/546498#M49679</guid>
      <dc:creator>JBeatty</dc:creator>
      <dc:date>2021-12-23T15:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: api calls from local env</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/api-calls-from-local-env/m-p/546586#M49681</link>
      <description>Thanks for your reply. I'm new to development and I just wanted to try my&lt;BR /&gt;hand at using APIs. Would you be able to point me to any resources where I&lt;BR /&gt;can learn more about CORS in layman terms, setting up endpoints on separate&lt;BR /&gt;servers, using AWS serverless functions, etc? That would greatly help me on&lt;BR /&gt;the academic front.&lt;BR /&gt;&lt;BR /&gt;That being said, I also want to get my website up and running using my own&lt;BR /&gt;form designs. Do you know what the best way to do this is? I read somewhere&lt;BR /&gt;that I could embed a hubspot form in my html and then hide it, and use js&lt;BR /&gt;to submit the form when the user clicks my button. Thanks for your help.&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Dec 2021 19:10:48 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/api-calls-from-local-env/m-p/546586#M49681</guid>
      <dc:creator>KToo</dc:creator>
      <dc:date>2021-12-23T19:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: api calls from local env</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/api-calls-from-local-env/m-p/547789#M49713</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/300751"&gt;@KToo&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;The best place to learn about CORS would be Mozilla's Documentation, which I linked above, there is not too much to other then once it is properly enabled a javascirpt browser client can make post requests to it. To learn about settings up endpoints using AWS serverless functions I would recommend following &lt;A href="https://aws.amazon.com/getting-started/hands-on/run-serverless-code/" target="_blank" rel="noopener"&gt;Amazons Tutorials, there is a lot here&lt;/A&gt;, so it can take quite some time to fully understand everything.&lt;BR /&gt;&lt;BR /&gt;To get style your form however you want, you'll need&amp;nbsp;Marketing Hub and CMS Hub Professional or Enterprise, or Legacy Marketing Hub Basic only, at which point you &lt;A href="https://knowledge.hubspot.com/forms/how-can-i-share-a-hubspot-form-if-im-using-an-external-site#Style%20your%20form%20with%20CSS" target="_blank" rel="noopener"&gt;can set as a raw html form&lt;/A&gt;. Then you can style it yourself. Though theoretically it could be possible to do it for free by &lt;A href="https://legacydocs.hubspot.com/docs/methods/forms/advanced_form_options" target="_blank" rel="noopener"&gt;customizing the forms embed code to modify the CSS of the DOM directly&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 16:21:11 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/api-calls-from-local-env/m-p/547789#M49713</guid>
      <dc:creator>JBeatty</dc:creator>
      <dc:date>2021-12-30T16:21:11Z</dc:date>
    </item>
  </channel>
</rss>

