klaviyo-api-php icon indicating copy to clipboard operation
klaviyo-api-php copied to clipboard

How we able to use sendEvent?

Open jack-fdrv opened this issue 1 year ago • 10 comments

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?

jack-fdrv avatar Feb 02 '24 13:02 jack-fdrv

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 Screenshot 2024-02-02 at 9 39 36 AM

jon-batscha avatar Feb 02 '24 14:02 jon-batscha

@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?

jack-fdrv avatar Feb 02 '24 19:02 jack-fdrv

If we try to pass data like this, it just doesnt work. So docs doesnt help... Or I dont understand how to use it. image

jack-fdrv avatar Feb 02 '24 19:02 jack-fdrv

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?

jon-batscha avatar Feb 16 '24 19:02 jon-batscha

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?

jack-fdrv avatar Feb 16 '24 21:02 jack-fdrv

Same issue here. If i try to create an event with the payload mentioned in the documentation, i get "Invalid input" error message.

cristiansoftlead avatar Feb 28 '24 08:02 cristiansoftlead

@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',
         ],
       ],
     ],
   ],
 ],
] 

cristiansoftlead avatar Feb 28 '24 08:02 cristiansoftlead

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

cristiansoftlead avatar Feb 28 '24 08:02 cristiansoftlead