Problem Description
We're encountering inconsistencies in the data type returned by the Klaviyo API client. At the beginning of the integration we are developing, the response is a Pydantic model object that can be accessed using dot notation (.attributes.updated), but now it's a dictionary that needs to be accessed using dictionary methods (.get("attributes", {}).get("updated")).
This inconsistency leads to AttributeError: 'dict' object has no attribute 'attributes' when our code expects an object but receives a dictionary.
Reproduction Steps
- Make calls to the Klaviyo API (e.g.,
create_profile, update_profile, get_profiles)
- Try to access response data with dot notation
Current Workaround
We've implemented a try/except pattern to handle both cases:
Object-style Response (Pydantic Model):
POST_PROFILE_RESPONSE = PostProfileResponse(
data=PostProfileResponseData(
type=ProfileEnum.PROFILE,
id="01JM21MJPKEV69YZK25DG0WAOW",
attributes=PostProfileResponseDataAttributes(
email="example@example.com",
phone_number="+12345678901",
created=datetime(2025, 2, 14, 10, 56, 26, 837280, tzinfo=None),
updated=datetime(2025, 2, 14, 10, 56, 26, 837311, tzinfo=None),
# ...other attributes
),
# ...other fields
)
)
Dictionary-style Response:
response = [
{
"id": "01JM21MJPKEV69YZK25DG0WAOW",
"attributes": {
"email": "example@example.com",
"phone_number": "+12345678901",
"created": "2025-02-14T10:56:26.837280",
"updated": "2025-02-14T10:56:26.837311",
# ...other attributes
},
# ...other fields
}
]
Request
Could you please:
- Standardize the response format (either always return Pydantic models or always return dictionaries)
- Document the expected response types for each API method
- Provide a helper method to convert between the formats if both are needed for backward compatibility
Environment
- Klaviyo API client version: [17.0.0]
Thank you for your help!
Problem Description
We're encountering inconsistencies in the data type returned by the Klaviyo API client. At the beginning of the integration we are developing, the response is a Pydantic model object that can be accessed using dot notation (
.attributes.updated), but now it's a dictionary that needs to be accessed using dictionary methods (.get("attributes", {}).get("updated")).This inconsistency leads to
AttributeError: 'dict' object has no attribute 'attributes'when our code expects an object but receives a dictionary.Reproduction Steps
create_profile,update_profile,get_profiles)Current Workaround
We've implemented a try/except pattern to handle both cases:
Object-style Response (Pydantic Model):
Dictionary-style Response:
Request
Could you please:
Environment
Thank you for your help!