Using Charges API to pull sub-parameters

Hi,

Got a question related to the Charges API. I am trying to pull the parameter “items.persons_entitled” or any sub parameter of “items” for numerous registration numbers.

The following is the code I am using. This code simply takes the list of register numbers and passes them through the get_charges function and brings back the API response.

for index, row in df_api.iterrows():

company_number = row["Company Number"]

api_data = companies_house_api.get_charges(company_number)

df_api.at[index, "items.persons_entitled"] = api_data.get("items.persons_entitled")

df_api.at[index, "items"] = api_data.get("items")


print(f"Num: {row['Company Number']} | "\

       f"Charges: {df_api.at[index,'items.persons_entitled']}")

Strangely, I am able to get the parameter “items” response as a list, which confirms that some of the register numbers do in fact have data for the parameter “items.persons_entitled”.
However, if I try to run just “items.persons_entitled” I get NaN.

Any idea how you access sub-parameters of “items” such as “items.persons_entitled” or “items.created_on”? Has anyone else dealt with this issue?

Thanks

Edgar

persons_entitled is an optional (array) value. Pertinently, the presence of items does NOT mean that all or any of the optional values exist. So, check for null before referencing the optional value.

PS: With the CH api, you should check all values for null, I have seen several payloads (on the streaming API) with missing mandatory property values!