6969
7070
7171def fetch_data_for_properties (
72- props : Sequence [str ],
72+ props : List [str ],
7373 api_key : str ,
7474 object_type : str ,
7575 soft_delete : bool ,
@@ -78,16 +78,17 @@ def fetch_data_for_properties(
7878 Fetch data for a given set of properties from the HubSpot API.
7979
8080 Args:
81- props (Sequence [str]): List of property names to fetch.
81+ props (List [str]): List of property names to fetch.
8282 api_key (str): HubSpot API key for authentication.
8383 object_type (str): The type of HubSpot object (e.g., 'company', 'contact').
8484 soft_delete (bool): Flag to fetch soft-deleted (archived) records.
8585
8686 Yields:
8787 Iterator[TDataItems]: Data retrieved from the HubSpot API.
8888 """
89-
90- params : Dict [str , Any ] = {"properties" : props , "limit" : 100 }
89+ # The Hubspot API expects a comma separated string as properties
90+ joined_props = "," .join (sorted (props ))
91+ params : Dict [str , Any ] = {"properties" : joined_props , "limit" : 100 }
9192 context : Optional [Dict [str , Any ]] = (
9293 {SOFT_DELETE_KEY : False } if soft_delete else None
9394 )
@@ -135,7 +136,7 @@ def crm_objects(
135136 for prop , hb_type in props_to_type .items ()
136137 }
137138 for batch in fetch_data_for_properties (
138- "," . join ( sorted ( props_to_type .keys () )), api_key , object_type , archived
139+ list ( props_to_type .keys ()), api_key , object_type , archived
139140 ):
140141 yield dlt .mark .with_hints (batch , dlt .mark .make_hints (columns = col_type_hints ))
141142
@@ -151,9 +152,9 @@ def crm_object_history(
151152
152153 Args:
153154 object_type (str): Type of HubSpot object (e.g., 'company', 'contact').
154- api_key (str, optional ): API key for HubSpot authentication.
155- props (List[str], optional ): List of properties to retrieve. Defaults to None.
156- include_custom_props (bool, optional ): Include custom properties in the result. Defaults to True.
155+ api_key (str): API key for HubSpot authentication.
156+ props (List[str]): List of properties to retrieve. Defaults to None.
157+ include_custom_props (bool): Include custom properties in the result. Defaults to True.
157158
158159 Yields:
159160 Iterator[TDataItems]: Historical property data.
@@ -207,7 +208,11 @@ def pivot_stages_properties(
207208 continue
208209 id_val = record_not_null .pop (id_prop )
209210 new_data += [
210- {id_prop : id_val , property_prefix : v , "stage" : k .split (property_prefix )[1 ]}
211+ {
212+ id_prop : id_val ,
213+ property_prefix : v ,
214+ "stage" : k .split (property_prefix )[1 ],
215+ }
211216 for k , v in record_not_null .items ()
212217 if k .startswith (property_prefix )
213218 ]
@@ -221,12 +226,8 @@ def stages_timing(
221226) -> Iterator [TDataItems ]:
222227 """
223228 Fetch stage timing data for a specific object type from the HubSpot API. Some entities, like,
224- deals and tickets actually have pipelines with multiple stages, which they can enter and exit. This function fetches
225- history of entering and exiting different stages for the given object.
226-
227- We have to request them separately, because these properties has the pipeline stage_id in the name.
228- For example, "hs_date_entered_12345678", where 12345678 is the stage_id.
229-
229+ deals and tickets have pipelines with multiple stages, which they can enter and exit. This function fetches
230+ history of entering different stages for the given object.
230231
231232 Args:
232233 object_type (str): Type of HubSpot object (e.g., 'deal', 'ticket').
@@ -236,7 +237,6 @@ def stages_timing(
236237 Yields:
237238 Iterator[TDataItems]: Stage timing data.
238239 """
239-
240240 all_properties : List [str ] = list (
241241 _get_property_names_types (api_key , object_type ).keys ()
242242 )
@@ -248,10 +248,7 @@ def stages_timing(
248248 # data for the whole properties list. Therefore, in the following lines we request
249249 # data iteratively for chunks of the properties list.
250250 for chunk in chunk_properties (date_entered_properties , MAX_PROPS_LENGTH ):
251- props_part = "," .join (chunk )
252- for data in fetch_data_for_properties (
253- props_part , api_key , object_type , soft_delete
254- ):
251+ for data in fetch_data_for_properties (chunk , api_key , object_type , soft_delete ):
255252 yield pivot_stages_properties (data )
256253
257254
0 commit comments