Solved

How to use fields[profile] while requesting events in API v2?

  • 2 November 2022
  • 3 replies
  • 308 views

Badge +2

Hi there,

We’re migrating our integration with Klaviyo to v2 and I faced the issue with retrieving such profile properties as first_name, last_name, email when collecting events.

API reference declares optional query param “fields[profile]”: https://developers.klaviyo.com/en/reference/get_events

But when I try to use this param:

GET https://a.klaviyo.com/api/events?sort=datetime&fields[profile]=first_name,last_name,email&filter=greater-or-equal(datetime,2022-10-20)

I got the error 400 Bad Request:

{
    "errors": [
        {
            "id": "cc99c0e8-a548-43ed-827b-793d82f78aad",
            "status": 400,
            "code": "invalid",
            "title": "Invalid input.",
            "detail": "'profile' is not an allowed field family for this resource.",
            "source": {
                "parameter": "fields"
            },
            "meta": {}
        }
    ]
}

 

Please advise how I can retrieve profile properties from /events endpoint? I would like don’t requesting /profiles endpoint for a some reasons.

Thanks in advance!

icon

Best answer by Brian Turcotte 29 December 2022, 18:46

View original

3 replies

Userlevel 7
Badge +36

Hi @imp_dev and welcome to the Community!

 

If the use case is to retrieve Profile properties or information that isn’t intrinsically related to an event, then I would generally advise utilizing the Profiles endpoint which is essentially available for that exact purpose.

 

Are you comfortable sharing why you need to use the Events endpoint? If not, I totally understand, but it may help me to understand the parameters of your use case.

 

As far as the reason why the param is throwing an error, I will have to consult the documentation and potentially our engineering team for further information, and then I will update the thread. 

 

Thanks for using the Community!

-Brian

 

Badge +2

Hi Brian,

Thank you for answering!

Using v1 API, we retrieving Events details along with some Profile properties.

And we would like to make it using v2 API. Otherwise, using Profiles endpoint we should rework our datasets and dashboards for our clients.

Userlevel 7
Badge +36

Hi @imp_dev!

 

Sorry for my delay in getting back around to this post - appending  &include=profiles  to the query string might resolve this issue:

 

https://a.klaviyo.com/api/events?sort=datetime&fields[profile]=first_name,last_name,email&filter=greater-or-equal(datetime,2022-10-20)&include=profiles

 

I’ve seen other users resolve similar issues this way, so I hope this helps!

 

-Brian

Reply