Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How we able to use sendEvent? #42

Open
jack-fdrv opened this issue Feb 2, 2024 · 8 comments
Open

How we able to use sendEvent? #42

jack-fdrv opened this issue Feb 2, 2024 · 8 comments

Comments

@jack-fdrv
Copy link

jack-fdrv commented Feb 2, 2024

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?

@jon-batscha
Copy link
Collaborator

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

@jack-fdrv
Copy link
Author

jack-fdrv commented Feb 2, 2024

@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
Copy link
Author

jack-fdrv commented Feb 2, 2024

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

@jon-batscha
Copy link
Collaborator

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?

@jack-fdrv
Copy link
Author

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?

@cristiansoftlead
Copy link

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

@cristiansoftlead
Copy link

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants