How we able to use sendEvent?
I am wondering why there is no example how to use this sdk? What approach should I use to be successful with this sdk?
For example here is my code
public function sendEvent( $event_name, $customer_email, $customer_properties = array(), $properties = array() ) {
$eventData = [
'data' => [
'type' => 'event',
'attributes' => [
'event' => $event_name,
'profile' => ['$email' => $customer_email] + $customer_properties,
'properties' => $properties,
],
],
];
$event = new KlaviyoAPI\Model\EventCreateQueryV2( $eventData );
$resp = $this->client->Events->createEvent($event);
}
to use createEvent i need to first create an object of event via some weird EventCreateQueryV2 but there is no example of data structure... How can i do it?
In the list of operations, the operation name is a link to our API-level docs, which give details on how the payload should be structured. In this case, that link is: https://developers.klaviyo.com/en/reference/create_event
@jon-batscha Thanks. But, i was not able to find any example or mentions that createEvent need object from EventCreateQueryV2. Did you? And there is no docs how to create that object via EventCreateQueryV2, what structure should be?
If we try to pass data like this, it just doesnt work. So docs doesnt help... Or I dont understand how to use it.
are you able to create an event in postman, but not in PHP? (asking to try to narrow down where the problem lies)
Also, can you share with me your code where you try to create an event?
I was able to create a postman, and even user GuzzleHttp from doc's example and it all works fine. But SDK, whic hhave amodel structure just build different. And it just hard to understand how can i pass data to model to create an event. I have played a lot and figure it out but it is hard. So I woud like to ask gheneral advice what is the best approach to do it? If there is not docs about strucutre, and it is really hard to understand structure from reaing original code, what is the right way to use sdk?
Same issue here. If i try to create an event with the payload mentioned in the documentation, i get "Invalid input" error message.
@jack-fdrv I just figured it out..idk why is this so complicated this payload, but i was able to create an event when a new account was created. Take a look at my payload example.
$eventPayload = [
'data' => [
'type' => 'event',
'attributes' => [
'properties' => [
'email' => 'EMAIL ADDRESS',
'first_name' => 'FIRST NAME',
'last_name' => 'LAST NAME',
],
'metric' => [
'data' => [
'type' => 'metric',
'attributes' => [
'name' => 'Created an account',
],
],
],
'profile' => [
'data' => [
'type' => 'profile',
'id' => 'KLAVIYO PROFILE ID',
'attributes' => [
'email' => 'EMAIL ADDRESS',
'first_name' => 'FIRST NAME',
'last_name' => 'LAST NAME',
],
],
],
],
],
]
PS: I was able to create this event without the profile > data > attributes array. So you can remove it and keep only the type and id