klaviyo / klaviyo-api-python

Python SDK for Klaviyo API
https://developers.klaviyo.com
MIT License
36 stars 6 forks source link

Pydantic Error using query_campaign_values function #64

Closed robmitchell1987 closed 2 months ago

robmitchell1987 commented 2 months ago

I am getting a Pydantic error using klaviyo.Reporting.query_campaign_values on version 11.0.1 of the SDK due to there not being a links node in the response which is required by the validator.

Error below

 1 validation error for PostCampaignValuesResponseDTOData
links
Input should be a valid dictionary or instance of ObjectLinks [type=model_type, input_value=None, input_type=NoneType]
``

Example API response

{ "data": { "type": "campaign-values-report", "id": "", "attributes": { "results": [ { "groupings": { "send_channel": "email", "campaign_id": "" }, "statistics": { "clicks": 0.0, "opens": 2.0, "open_rate": 1.0, "delivered": 1.0 } } ] }, "relationships": { "campaigns": { "data": [ ... ] } } }, "links": { "self": "https://a.klaviyo.com/api/campaign-values-reports/", "next": null, "prev": null } }

ben-horgan-klaviyo commented 2 months ago

Thanks for bringing this up- we'll work on a patch for this.

In the meantime, you can work around this by passing options={ USE_DICTIONARY_FOR_RESPONSE_DATA: True } - this will give you a dictionary response and forego validation.

ben-horgan-klaviyo commented 2 months ago

This has been fixed in v12 - closing this out.