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

Function signature - unclear on SDK payload structure vs API Docs #92

Open
gkatsanos opened this issue Jan 3, 2025 · 1 comment
Open

Comments

@gkatsanos
Copy link

gkatsanos commented Jan 3, 2025

Hello,

While going through the API Docs + the SDK examples, I'm not so clear on what the expected object should be passed into calls like eventsApi.createEvent.

For example, to create a placed order server event/metric, the API docs give this example:

curl --request POST \
     --url https: //a.klaviyo.com/api/events/ \
     --header 'Authorization: Klaviyo-API-Key your-private-api-key' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --header 'revision: 2024-02-15' \
     --data '
{
    "data": {
        "type": "event",
        "attributes": {
            "properties": {
                "OrderId": "1234",
                "Categories": [
                    "Fiction",
                    "Classics",
                    "Children"
                ],
                "ItemNames": [
                    "Winnie the Pooh",
                    "A Tale of Two Cities"
                ],
                "DiscountCode": "Free Shipping",
                "DiscountValue": 5,
                "Brands": [
                    "Kids Books",
                    "Harcourt Classics"
                ],
                "Items": [
                    {
                        "ProductID": "1111",
                        "SKU": "WINNIEPOOH",
                        "ProductName": "Winnie the Pooh",
                        "Quantity": 1,
                        "ItemPrice": 9.99,
                        "RowTotal": 9.99,
                        "ProductURL": "http://www.example.com/path/to/product",
                        "ImageURL": "http://www.example.com/path/to/product/image.png",
                        "Categories": [
                            "Fiction",
                            "Children"
                        ],
                        "Brand": "Kids Books"
                    },
                    {
                        "ProductID": "1112",
                        "SKU": "TALEOFTWO",
                        "ProductName": "A Tale of Two Cities",
                        "Quantity": 1,
                        "ItemPrice": 19.99,
                        "RowTotal": 19.99,
                        "ProductURL": "http://www.example.com/path/to/product2",
                        "ImageURL": "http://www.example.com/path/to/product/image2.png",
                        "Categories": [
                            "Fiction",
                            "Classics"
                        ],
                        "Brand": "Harcourt Classics"
                    }
                ],
                "BillingAddress": {
                    "FirstName": "John",
                    "LastName": "Smith",
                    "Address1": "123 Abc St",
                    "City": "Boston",
                    "RegionCode": "MA",
                    "CountryCode": "US",
                    "Zip": "02110",
                    "Phone": "+15551234567"
                },
                "ShippingAddress": {
                    "Address1": "123 Abc St"
                }
            },
            "time": "2022-11-08T00:00:00",
            "value": 29.98,
            "value_currency": "USD",
            "unique_id": "d47aeda5-1751-4483-a81e-6fcc8ad48711",
            "metric": {
                "data": {
                    "type": "metric",
                    "attributes": {
                        "name": "Placed Order"
                    }
                }
            },
            "profile": {
                "data": {
                    "type": "profile",
                    "attributes": {
                        "email": "[email protected]",
                        "phone_number": "+15005550006"
                    }
                }
            }
        }
    }
}
'

How would this be translated to the object passed in eventsApi.createEvent ?

@cpcurtis1218
Copy link

Hi there, the data object that should be passed to the SDK is the same --data object shown in the API documentation. In your example, the data that you would pass to the eventsApi.createEvent() method would be:

{ "data": { "type": "event", "attributes": { "properties": { "OrderId": "1234", "Categories": [ "Fiction", "Classics", "Children" ], "ItemNames": [ "Winnie the Pooh", "A Tale of Two Cities" ], "DiscountCode": "Free Shipping", "DiscountValue": 5, "Brands": [ "Kids Books", "Harcourt Classics" ], "Items": [ { "ProductID": "1111", "SKU": "WINNIEPOOH", "ProductName": "Winnie the Pooh", "Quantity": 1, "ItemPrice": 9.99, "RowTotal": 9.99, "ProductURL": "http://www.example.com/path/to/product", "ImageURL": "http://www.example.com/path/to/product/image.png", "Categories": [ "Fiction", "Children" ], "Brand": "Kids Books" }, { "ProductID": "1112", "SKU": "TALEOFTWO", "ProductName": "A Tale of Two Cities", "Quantity": 1, "ItemPrice": 19.99, "RowTotal": 19.99, "ProductURL": "http://www.example.com/path/to/product2", "ImageURL": "http://www.example.com/path/to/product/image2.png", "Categories": [ "Fiction", "Classics" ], "Brand": "Harcourt Classics" } ], "BillingAddress": { "FirstName": "John", "LastName": "Smith", "Address1": "123 Abc St", "City": "Boston", "RegionCode": "MA", "CountryCode": "US", "Zip": "02110", "Phone": "+15551234567" }, "ShippingAddress": { "Address1": "123 Abc St" } }, "time": "2022-11-08T00:00:00", "value": 29.98, "value_currency": "USD", "unique_id": "d47aeda5-1751-4483-a81e-6fcc8ad48711", "metric": { "data": { "type": "metric", "attributes": { "name": "Placed Order" } } }, "profile": { "data": { "type": "profile", "attributes": { "email": "[email protected]", "phone_number": "+15005550006" } } } } } }

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

2 participants