<?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: How can all dropdown options from a product's property be passed in a filtering list? in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/How-can-all-dropdown-options-from-a-product-s-property-be-passed/m-p/1031623#M76111</link>
    <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/69549"&gt;@DrAS&lt;/a&gt;&amp;nbsp;- From a property related API call, you can retrieve all possible options for a dropdown list (as you have found) as an array. Applying this array (or subsets of the array) to a search API filter can be done with an IN filter type and values array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note these API calls can't be made from client side JS (only HubDB APIs are permitted in this context) - so it seems likely that the HubL option offered in this thread is going to be the best option for the display you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Steve&lt;/P&gt;</description>
    <pubDate>Fri, 23 Aug 2024 18:18:59 GMT</pubDate>
    <dc:creator>SteveHTM</dc:creator>
    <dc:date>2024-08-23T18:18:59Z</dc:date>
    <item>
      <title>How can all dropdown options from a product's property be passed in a filtering list?</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-can-all-dropdown-options-from-a-product-s-property-be-passed/m-p/1031489#M76094</link>
      <description>&lt;P&gt;I am using hubspot's product object to record different real estate projects and properties. A custom property was created for the product object, with internal value asset_type, and field type Dropdown select. Same for bedrooms, and bathrooms.&lt;BR /&gt;&lt;BR /&gt;A module has been created to display, with the ability of filtering, properties listings - a card-type list of properties, dependent on filters, containing information about those properties. For the time being, I am trying to make just a few filters work, before moving on to add filters.&lt;BR /&gt;&lt;BR /&gt;I managed to make the minimum and maximum price work as filters, i.e.: when they are set, both of them together or independently of one another, and the filter button is hit, what is then displayed are only the correct properties.&lt;BR /&gt;&lt;BR /&gt;However, I am stuck with the other ones. What is displayed as an option in all the lists is simply 'All', but for each of those lists what I want displayed are the existing dropdown options found in the product object's properties. I do not want to hard-code the drop-down options (apartment, house, studio, etc; 1, 2, 3, etc). That is suboptimal, as those options may change at any time, which means they got to be hard-coded again; plus, more filters will be added for this module and others later on, and each time those options could change also. I want to pull the dropdown options directly from the property itself, as set within properties settings of the product object.&lt;BR /&gt;&lt;BR /&gt;I understand this is possible with HubDB (&lt;A href="https://community.hubspot.com/t5/APIs-Integrations/How-to-get-all-options-from-a-select-field-from-HubDB-from/m-p/674328" target="_blank" rel="noopener"&gt;https://community.hubspot.com/t5/APIs-Integrations/How-to-get-all-options-from-a-select-field-from-HubDB-from/m-p/674328&lt;/A&gt;), and I see no reason why it cannot be possible with CRM Objects also.&lt;BR /&gt;&lt;BR /&gt;Here's the module:&lt;BR /&gt;&lt;BR /&gt;module.html&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{% set asset_type_options = crm_object("product", "asset_type", 200) %}
{% set bedrooms_options = crm_object("product", "bedrooms", 200) %}
{% set bathrooms_options = crm_object("product", "bathrooms", 200) %}

&amp;lt;!-- Debug Information --&amp;gt;
{% for options in asset_type_options %}
  &amp;lt;p&amp;gt;Asset Type Options Raw Data: {{ option|pprint }}&amp;lt;/p&amp;gt;        
{% endfor %}

&amp;lt;p&amp;gt;Asset Type Options Raw Data: {{ asset_type_options|pprint }}&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;Bedrooms Options Raw Data: {{ bedrooms_options|pprint }}&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;Bathrooms Options Raw Data: {{ bathrooms_options|pprint }}&amp;lt;/p&amp;gt;

{% if dynamic_page_crm_object_type_fqn %}
    {# Fetch the products with the limit of 200 #}
    {% set products = crm_objects("product", "limit=200", "hs_sku, price, cover_photo, address, asset_type, bedrooms, bathrooms") %}

    &amp;lt;p&amp;gt;Total products fetched: {{ products.results|length }}&amp;lt;/p&amp;gt;

    {# Debug the first product's data #}
    &amp;lt;pre&amp;gt;{{ products.results[0]|pprint }}&amp;lt;/pre&amp;gt;

    &amp;lt;div class="product__listing"&amp;gt;
        {% for product in products.results %}
            &amp;lt;div class="product__card"&amp;gt;
                &amp;lt;a href="{{ request.path }}/{{ product.hs_sku }}"&amp;gt;
                    &amp;lt;div class="product__cover_photo"&amp;gt;
                        {% if product.cover_photo %}
                            &amp;lt;img src="{{product.cover_photo}}" alt="{{product.hs_sku}} {{product.price}} {{product.asset_type}}"&amp;gt;
                        {% else %}
                            &amp;lt;img src="https://f.hubspotusercontent20.net/hubfs/9307273/Imported%20images/plchldr255.png" alt="Picture coming soon"&amp;gt;
                        {% endif %}
                    &amp;lt;/div&amp;gt;  
                    &amp;lt;div class="product__details"&amp;gt;
                        &amp;lt;div class="product__price"&amp;gt;
                            Price: {{product.price |format_currency("en-US")}}
                        &amp;lt;/div&amp;gt;
                        &amp;lt;div class="product__asset_type"&amp;gt;
                            Type: {{ product.asset_type}}
                        &amp;lt;/div&amp;gt;
                        &amp;lt;div class="product__bedrooms"&amp;gt;
                            Bedrooms: {{product.bedrooms}} 
                        &amp;lt;/div&amp;gt;
                        &amp;lt;div class="product__bathrooms"&amp;gt;
                            Bathrooms: {{product.bathrooms}} 
                        &amp;lt;/div&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/a&amp;gt;
            &amp;lt;/div&amp;gt;
        {% endfor %} 
    &amp;lt;/div&amp;gt;
{% elif dynamic_page_crm_object %}
    &amp;lt;p&amp;gt;This is a dynamic page detail view. The listing is hidden.&amp;lt;/p&amp;gt;
{% else %}
    {# Default product listing when not in a dynamic page context #}
    {% set object_type = dynamic_page_crm_object_type_fqn | default("product") %}
    {% set products = crm_objects("product", "limit=5", "hs_sku, price, cover_photo, address, asset_type, bedrooms, bathrooms") %}

    &amp;lt;p&amp;gt;Total products fetched: {{ products.results|length }}&amp;lt;/p&amp;gt;

    {# Debug the first product's data #}
    &amp;lt;pre&amp;gt;{{ products.results[0]|pprint }}&amp;lt;/pre&amp;gt;

    &amp;lt;section aria-labelledby="product-listing-heading"&amp;gt;
        &amp;lt;h3 id="product-listing-heading"&amp;gt;
            Available Properties  
        &amp;lt;/h3&amp;gt;
        &amp;lt;ul&amp;gt;   
            {% for product in products.results %}
                &amp;lt;li&amp;gt;&amp;lt;a href="/product/{{ product.sku }}"&amp;gt;{{ product.asset_type }} ({{ product.price }}) in {{ product.address }}&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
            {% endfor %}
        &amp;lt;/ul&amp;gt;
    &amp;lt;/section&amp;gt;
{% endif %}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;module.js&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;document.addEventListener("DOMContentLoaded", function() {
    const accessToken = '******';

    function fetchPropertyOptions(propertyName, dropdownId) {
        fetch(`https://api.hubapi.com/crm/v3/properties/${propertyName}?archived=false`, {
            headers: {
                'Authorization': `Bearer ${accessToken}`,
                'Content-Type': 'application/json'
            }
        })
        .then(response =&amp;gt; response.json())
        .then(data =&amp;gt; {
            const dropdown = document.getElementById(dropdownId);
            dropdown.innerHTML = `&amp;lt;option value=""&amp;gt;All&amp;lt;/option&amp;gt;`; // Default option
            data.options.forEach(option =&amp;gt; {
                dropdown.innerHTML += `&amp;lt;option value="${option.value}"&amp;gt;${option.label}&amp;lt;/option&amp;gt;`;
            });
        })
        .catch(error =&amp;gt; console.error('Error fetching property options:', error));
    }

    // Fetch and populate dropdowns
    fetchPropertyOptions('asset_type', 'asset_type_dropdown');
    fetchPropertyOptions('bedrooms', 'bedrooms_dropdown');
    fetchPropertyOptions('bathrooms', 'bathrooms_dropdown');
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2024 14:26:54 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-can-all-dropdown-options-from-a-product-s-property-be-passed/m-p/1031489#M76094</guid>
      <dc:creator>DrAS</dc:creator>
      <dc:date>2024-08-23T14:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: How can all dropdown options from a product's property be passed in a filtering list?</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-can-all-dropdown-options-from-a-product-s-property-be-passed/m-p/1031500#M76096</link>
      <description>&lt;P&gt;Good morning!&lt;BR /&gt;&lt;BR /&gt;So the function you are looking for would be the &lt;STRONG&gt;crm_property_definitions&lt;/STRONG&gt; hubl function which you can read more about here:&amp;nbsp;&lt;A href="https://developers.hubspot.com/docs/cms/hubl/functions#crm-property-definitions" target="_blank"&gt;https://developers.hubspot.com/docs/cms/hubl/functions#crm-property-definitions&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;This will return a dynamic list of all available options in the properties you designate when declaring it and will update as the dropdown options change.&lt;BR /&gt;&lt;BR /&gt;Let me know if you have any further questions!&lt;BR /&gt;&lt;BR /&gt;Dan&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2024 14:31:29 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-can-all-dropdown-options-from-a-product-s-property-be-passed/m-p/1031500#M76096</guid>
      <dc:creator>DanielPicklo</dc:creator>
      <dc:date>2024-08-23T14:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: How can all dropdown options from a product's property be passed in a filtering list?</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/How-can-all-dropdown-options-from-a-product-s-property-be-passed/m-p/1031623#M76111</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/69549"&gt;@DrAS&lt;/a&gt;&amp;nbsp;- From a property related API call, you can retrieve all possible options for a dropdown list (as you have found) as an array. Applying this array (or subsets of the array) to a search API filter can be done with an IN filter type and values array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note these API calls can't be made from client side JS (only HubDB APIs are permitted in this context) - so it seems likely that the HubL option offered in this thread is going to be the best option for the display you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Steve&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2024 18:18:59 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/How-can-all-dropdown-options-from-a-product-s-property-be-passed/m-p/1031623#M76111</guid>
      <dc:creator>SteveHTM</dc:creator>
      <dc:date>2024-08-23T18:18:59Z</dc:date>
    </item>
  </channel>
</rss>

