<?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 How can we get access to geopy APIs in custom workflow code in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/How-can-we-get-access-to-geopy-APIs-in-custom-workflow-code/m-p/808147#M64952</link>
    <description>&lt;P&gt;Hopeing that someone can offer advice here. I need some API access to python support for distance calculation between two locatons (not the HubDB filter).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have seen the sophisticated and well supported GeoPy package referenced to offer such functionality, but it seems that it it is not possible to import this API into python code in a custom workflow step ( module not found errors when using import ). So two questions arise:&lt;/P&gt;&lt;P&gt;- Is there a generic access mechanism to install python packages not available in the standard custom code environment to get access to available powerful APIs?&lt;/P&gt;&lt;P&gt;- Is there any alternative funtionality for geographic distance calculation etc. available within the standard python custom code run-time?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Grateful for all pointers here.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Jun 2023 21:12:48 GMT</pubDate>
    <dc:creator>SteveHTM</dc:creator>
    <dc:date>2023-06-15T21:12:48Z</dc:date>
    <item>
      <title>How can we get access to geopy APIs in custom workflow code</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-can-we-get-access-to-geopy-APIs-in-custom-workflow-code/m-p/808147#M64952</link>
      <description>&lt;P&gt;Hopeing that someone can offer advice here. I need some API access to python support for distance calculation between two locatons (not the HubDB filter).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have seen the sophisticated and well supported GeoPy package referenced to offer such functionality, but it seems that it it is not possible to import this API into python code in a custom workflow step ( module not found errors when using import ). So two questions arise:&lt;/P&gt;&lt;P&gt;- Is there a generic access mechanism to install python packages not available in the standard custom code environment to get access to available powerful APIs?&lt;/P&gt;&lt;P&gt;- Is there any alternative funtionality for geographic distance calculation etc. available within the standard python custom code run-time?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Grateful for all pointers here.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2023 21:12:48 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-can-we-get-access-to-geopy-APIs-in-custom-workflow-code/m-p/808147#M64952</guid>
      <dc:creator>SteveHTM</dc:creator>
      <dc:date>2023-06-15T21:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: How can we get access to geopy APIs in custom workflow code</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-can-we-get-access-to-geopy-APIs-in-custom-workflow-code/m-p/808429#M64978</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/63499"&gt;@SteveHTM&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":waving_hand:"&gt;👋&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Have you thought about using the &lt;A href="https://en.wikipedia.org/wiki/Haversine_formula" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;Haversine formula&lt;/STRONG&gt;&lt;/A&gt;? This would let us stick to only using&amp;nbsp;&lt;SPAN&gt;Python's built-in maths library.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Here's an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;def calculate_distance(lat1, lon1, lat2, lon2):
    R = 6371.0 # radius of Earth in kilometers. Use 3956 for miles

    lat1, lon1, lat2, lon2 = map(radians, [lat1, lon1, lat2, lon2])

    dlon = lon2 - lon1
    dlat = lat2 - lat1

    a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2
    sqrt_a = sqrt(a)
    c = 2 * atan2(sqrt_a, hypot(1, -sqrt_a))

    distance = R * c
    return distance
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Just remember to pass latitude and longitude values as decimal degrees into the function. The function will return the distance in kilometers due to the Earth's radius (R) being set to 6371.0 kilometers.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let us know if this worked or if you found another way to solve this challenge.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have fun building! — Jaycee&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS, In full disclosure, I did ask GPT-4 for help in converting the formula into Python. What's not to like about a little spherical trigonometry amongst friends? &lt;span class="lia-unicode-emoji" title=":rolling_on_the_floor_laughing:"&gt;🤣&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 13:53:13 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-can-we-get-access-to-geopy-APIs-in-custom-workflow-code/m-p/808429#M64978</guid>
      <dc:creator>Jaycee_Lewis</dc:creator>
      <dc:date>2023-06-16T13:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: How can we get access to geopy APIs in custom workflow code</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-can-we-get-access-to-geopy-APIs-in-custom-workflow-code/m-p/808517#M64982</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/127074"&gt;@Jaycee_Lewis&lt;/a&gt;&amp;nbsp;(and ChatGPT) for this formula - very interesting! Getting lat and long (from city/zip for example) still seems to be an problem without GeoPy. I realize that there is a HubL function, but functionality does not seem to be found elsewhere.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 16:20:32 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-can-we-get-access-to-geopy-APIs-in-custom-workflow-code/m-p/808517#M64982</guid>
      <dc:creator>SteveHTM</dc:creator>
      <dc:date>2023-06-16T16:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: How can we get access to geopy APIs in custom workflow code</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-can-we-get-access-to-geopy-APIs-in-custom-workflow-code/m-p/808562#M64985</link>
      <description>&lt;P&gt;Hey, Steve! You are 100% correct. Without a way to convert zip codes to lat/long, I can steal all the trig I want from 19th century ship captains, but it won't make a lick of difference.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's tag some of our community members into the converstaion — 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;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/101258"&gt;@Teun&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/241684"&gt;@ChrisoKlepke&lt;/a&gt;, do you have any additional suggestions for our friend&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/63499"&gt;@SteveHTM&lt;/a&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did have another thought if we're committed to having to use a workaround of some type. Care to go down another rabbit hole?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What if we have two workflows? Both with a custom coded action. One to handle the zip to lat/long conversion for your Contacts. And one to do the measuring.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Workflow A:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Enroll contacts based on the condition that a ZIP code &lt;EM&gt;is known&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;Use a custom coded action to send a request to your external server with the ZIP code&lt;/LI&gt;
&lt;LI&gt;The server performs the ZIP code to latitude/longitude conversion&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://developers.google.com/maps/documentation/geocoding/overview" target="_blank" rel="noopener"&gt;Google's Geocoding API&lt;/A&gt;&amp;nbsp;is an option&lt;/LI&gt;
&lt;LI&gt;Your server sends the latitude and longitude back to the Contacts API as values for custom properties&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Workflow B:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Enroll contacts based on the condition that both latitude and longitude properties are known&lt;/LI&gt;
&lt;LI&gt;Use a Python action to calculate the distance between the two points using the latitude and longitude properties&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;While it's enjoyable for me to brainstorm creative solutions, I acknowledge that there are likely real-world limitations that I am unaware of or not seeing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example,&lt;SPAN&gt;&amp;nbsp;setting up an external server and using Google's Geocoding API (or any other geocoding service) may involve additional costs and technical expertise. It's also important to make sure your server is secure and that it can handle the volume of requests that may be sent to it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Talk soon! — Jaycee&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 17:40:02 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-can-we-get-access-to-geopy-APIs-in-custom-workflow-code/m-p/808562#M64985</guid>
      <dc:creator>Jaycee_Lewis</dc:creator>
      <dc:date>2023-06-16T17:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: How can we get access to geopy APIs in custom workflow code</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-can-we-get-access-to-geopy-APIs-in-custom-workflow-code/m-p/808593#M64991</link>
      <description>&lt;P&gt;Thanks again for community advice!&lt;/P&gt;&lt;P&gt;I'm looking into the use of&amp;nbsp;&lt;A href="https://zipcodedownload.com/APIDocs#Filter" target="_blank"&gt;https://zipcodedownload.com/APIDocs#Filter&lt;/A&gt;&amp;nbsp;as a commercial service to do city/zip translation into lat/lon - at least for US/CA.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll then be in a position to use your spendid Haversine code to generate distances! I'll update here when I have all the parts working smoothly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Steve&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 18:48:33 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-can-we-get-access-to-geopy-APIs-in-custom-workflow-code/m-p/808593#M64991</guid>
      <dc:creator>SteveHTM</dc:creator>
      <dc:date>2023-06-16T18:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: How can we get access to geopy APIs in custom workflow code</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-can-we-get-access-to-geopy-APIs-in-custom-workflow-code/m-p/808603#M64993</link>
      <description>&lt;P&gt;That's wonderful! Glad we could talk it through together &lt;span class="lia-unicode-emoji" title=":raising_hands:"&gt;🙌&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I look forward to hearing how you get it all set up &lt;span class="lia-unicode-emoji" title=":chequered_flag:"&gt;🏁&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have fun building! —Jaycee&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 19:07:56 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-can-we-get-access-to-geopy-APIs-in-custom-workflow-code/m-p/808603#M64993</guid>
      <dc:creator>Jaycee_Lewis</dc:creator>
      <dc:date>2023-06-16T19:07:56Z</dc:date>
    </item>
  </channel>
</rss>

