Skip to main content
Contributor II
September 14, 2021
Solved

Klaviyo's track API with POST method returns 0

  • September 14, 2021
  • 12 replies
  • 1392 views

here is the payload:

{"token":"public or private key used here","event":"Order Confirmation","customer_properties":{"$email":"test@tohigherground.com","$first_name":"test","$last_name":"test","$phone_number":"1234567890","$address1":"00 abcd, Suite 200","$city":"Forest city","$zip":"94545","$region":"CA","$country":"US","Email Last Acquired Source":"00-000013","Email Last Acquired Date":"2021-09-14 09:41:37"},"properties":{"$event_id":"388948924","$value":"323.01","OrderId":"3000470847612","OrderedDate":"2021-07-26T03:25:33","PaymentTerm":"Credit Card","ProductSubTotal":"294.98","EstimatedTax":"28.03","ShippingTotal":"0.0","OrderTotal":"323.01","DiscountTotal":"0.0","Domain":"workspaceart.com","CurrencyISOCode":"USD","CountryISOCode":"US","Items":[{"LineId":"334987274","ProductID":"1871616","SKU":"12377756A","ProductName":"Doctor Maria Montessori","ItemDisplayedType":"Premium Giclee Print","Quantity":"1","UnitCharge":"157.99","Discount":"0","OriginalPrice":"157.99","SellingPrice":"157.99","ItemType":"POD","UnitOfMeasure":"INC","Height":"12","Width":"16","ServiceType":"Frame","ServiceAttributes":{"GlassName":"Acrylic: Clear","Mats":[{"Position":1,"MatName":"Crisp - Bright White"}],"Moldings":[{"Position":"1","MoldingName":"ALLEGRO Silver Wide","SideLengths":{"Top":"18","Right":"22","Bottom":"18","Left":"22"}}],"Liners":[]},"TimeToShip":{"WebsitePromisedTimeToShipDays":"4","WebsitePromisedTimeToShipDate":"2021-08-05T03:24:56","EstimatedShipDate":"2021-08-09T23:59:00","ArrivalByDateMin":"2021-09-18T09:41:36","ArrivalByDateMax":"2021-09-18T09:41:36"},"PrintSize":"12x16","ProductImageURL":"https://imgc.allpostersimages.com/img/print/u-g-OU1RQC7DO8.jpg?w=338&h=450&p=0","ImageId":"1743359","PODConfigId":"4986478","PhysicalDimensionWidth":"16","PhysicalDimensionHeight":"12","PhysicalDimensionUnit":"INC"},{"LineId":"334987273","ProductID":"6804869","SKU":"4123616437A","ProductName":"Montessori School","ItemDisplayedType":"Giclee Print","Quantity":"1","UnitCharge":"136.99","Discount":"0","OriginalPrice":"136.99","SellingPrice":"136.99","ItemType":"POD","UnitOfMeasure":"INC","Height":"18","Width":"12","ServiceType":"Frame","ServiceAttributes":{"GlassName":"Acrylic: Clear","Mats":[{"Position":1,"MatName":"Crisp - Bright White"}],"Moldings":[{"Position":"1","MoldingName":"GRAMERCY Black","SideLengths":{"Top":"24","Right":"18","Bottom":"24","Left":"18"}}],"Liners":[]},"TimeToShip":{"WebsitePromisedTimeToShipDays":"4","WebsitePromisedTimeToShipDate":"2021-08-05T03:24:56","EstimatedShipDate":"2021-08-09T23:59:00","ArrivalByDateMin":"2021-08-13T05:17:13","ArrivalByDateMax":"2021-08-13T05:17:13"},"PrintSize":"12x18","ProductImageURL":"https://imgc.allpostersimages.com/img/print/u-g-Q1G8CVRD1A1W.jpg?w=400&h=267&p=0","ImageId":"4755636","PODConfigId":"9436042","PhysicalDimensionWidth":"12","PhysicalDimensionHeight":"18","PhysicalDimensionUnit":"INC"}],"BillingAddress":{"FirstName":"Steven","LastName":"Gaudino","Address1":"10 Orchard, Suite 200","City":"Lake Forest","State":"CA","Country":"United States","CountryCode":"US","ZipCode":"92630","Phone":"7134092597"},"ShippingAddress":{"FirstName":"Guidepost","LastName":"Leavenworth","Address1":"571 Metropolitan Ave","City":"Leavenworth","State":"KS","Country":"United States","CountryCode":"US","ZipCode":"66048","Phone":"9132971476"},"Email":"aacosta@tohigherground.com","ShippingPriority":"Standard","CreditCard":{"Type":"MC","Token":"RTA","AccountIdentifier":"0965","ExpirationMonth":"09","ExpirationYear":"2023","AccountName":"Steven Gaudino"}}}

    This topic has been closed for replies.
    Best answer by cbarley


    Hey @lbaskar , makes sense as to why you’d want to use POST then! I just tested in postman with that payload (using my own account for testing) and was able to get a 1 back successfully. Some things to take note of:

    1. Be sure to use a form urlencoded header:
      'Content-Type: application/x-www-form-urlencoded'
    2. Be sure to add the JSON of the payload as the value to a key called “data”

    Here’s my exported request from Postman… 

    cURL: 

    curl --location --request POST 'https://a.klaviyo.com/api/track' \

    --header 'Content-Type: application/x-www-form-urlencoded' \

    --data-urlencode 'data={ "token":"REDACTED", "event":"Order Confirmation", "customer_properties":{ "$email":"connor+testing@gmail.com", "$first_name":"test", "$last_name":"test", "$phone_number":"1234567890", "$address1":"00 abcd, Suite 200", "$city":"Forest city", "$zip":"94545", "$region":"CA", "$country":"US", "Email Last Acquired Source":"00-000013", "Email Last Acquired Date":"2021-09-14 09:41:37" }, "properties":{ "$event_id":"388948924", "$value":"323.01", "OrderId":"3000470847612", "OrderedDate":"2021-07-26T03:25:33", "PaymentTerm":"Credit Card", "ProductSubTotal":"294.98", "EstimatedTax":"28.03", "ShippingTotal":"0.0", "OrderTotal":"323.01", "DiscountTotal":"0.0", "Domain":"workspaceart.com", "CurrencyISOCode":"USD", "CountryISOCode":"US", "Items":[ { "LineId":"334987274", "ProductID":"1871616", "SKU":"12377756A", "ProductName":"Doctor Maria Montessori", "ItemDisplayedType":"Premium Giclee Print", "Quantity":"1", "UnitCharge":"157.99", "Discount":"0", "OriginalPrice":"157.99", "SellingPrice":"157.99", "ItemType":"POD", "UnitOfMeasure":"INC", "Height":"12", "Width":"16", "ServiceType":"Frame", "ServiceAttributes":{ "GlassName":"Acrylic: Clear", "Mats":[ { "Position":1, "MatName":"Crisp - Bright White" } ], "Moldings":[ { "Position":"1", "MoldingName":"ALLEGRO Silver Wide", "SideLengths":{ "Top":"18", "Right":"22", "Bottom":"18", "Left":"22" } } ], "Liners":[ ] }, "TimeToShip":{ "WebsitePromisedTimeToShipDays":"4", "WebsitePromisedTimeToShipDate":"2021-08-05T03:24:56", "EstimatedShipDate":"2021-08-09T23:59:00", "ArrivalByDateMin":"2021-09-18T09:41:36", "ArrivalByDateMax":"2021-09-18T09:41:36" }, "PrintSize":"12x16", "ProductImageURL":"https://imgc.allpostersimages.com/img/print/u-g-OU1RQC7DO8.jpg?w=338&h=450&p=0", "ImageId":"1743359", "PODConfigId":"4986478", "PhysicalDimensionWidth":"16", "PhysicalDimensionHeight":"12", "PhysicalDimensionUnit":"INC" }, { "LineId":"334987273", "ProductID":"6804869", "SKU":"4123616437A", "ProductName":"Montessori School", "ItemDisplayedType":"Giclee Print", "Quantity":"1", "UnitCharge":"136.99", "Discount":"0", "OriginalPrice":"136.99", "SellingPrice":"136.99", "ItemType":"POD", "UnitOfMeasure":"INC", "Height":"18", "Width":"12", "ServiceType":"Frame", "ServiceAttributes":{ "GlassName":"Acrylic: Clear", "Mats":[ { "Position":1, "MatName":"Crisp - Bright White" } ], "Moldings":[ { "Position":"1", "MoldingName":"GRAMERCY Black", "SideLengths":{ "Top":"24", "Right":"18", "Bottom":"24", "Left":"18" } } ], "Liners":[ ] }, "TimeToShip":{ "WebsitePromisedTimeToShipDays":"4", "WebsitePromisedTimeToShipDate":"2021-08-05T03:24:56", "EstimatedShipDate":"2021-08-09T23:59:00", "ArrivalByDateMin":"2021-08-13T05:17:13", "ArrivalByDateMax":"2021-08-13T05:17:13" }, "PrintSize":"12x18", "ProductImageURL":"https://imgc.allpostersimages.com/img/print/u-g-Q1G8CVRD1A1W.jpg?w=400&h=267&p=0", "ImageId":"4755636", "PODConfigId":"9436042", "PhysicalDimensionWidth":"12", "PhysicalDimensionHeight":"18", "PhysicalDimensionUnit":"INC" } ], "BillingAddress":{ "FirstName":"Steven", "LastName":"Test", "Address1":"123 main street", "City":"Boston", "State":"MA", "Country":"United States", "CountryCode":"US", "ZipCode":"02118", "Phone":"1234567890" }, "ShippingAddress":{ "FirstName":"Steven", "LastName":"Test", "Address1":"123 main street", "City":"Boston", "State":"MA", "Country":"United States", "CountryCode":"US", "ZipCode":"02118", "Phone":"1234567890" }, "Email":"connor+test@gmail.com", "ShippingPriority":"Standard", "CreditCard":{ "Type":"MC", "Token":"RTA", "AccountIdentifier":"123", "ExpirationMonth":"123", "ExpirationYear":"3000", "AccountName":"Test" } } }'

    Python:

    import requests

    url = "https://a.klaviyo.com/api/track"

    payload='data=%7B%20%22token%22%3A%22REDACTED%22%2C%20%22event%22%3A%22Order%20Confirmation%22%2C%20%22customer_properties%22%3A%7B%20%22%24email%22%3A%22connor%2Btesting%40gmail.com%22%2C%20%22%24first_name%22%3A%22test%22%2C%20%22%24last_name%22%3A%22test%22%2C%20%22%24phone_number%22%3A%221234567890%22%2C%20%22%24address1%22%3A%2200%20abcd%2C%20Suite%20200%22%2C%20%22%24city%22%3A%22Forest%20city%22%2C%20%22%24zip%22%3A%2294545%22%2C%20%22%24region%22%3A%22CA%22%2C%20%22%24country%22%3A%22US%22%2C%20%22Email%20Last%20Acquired%20Source%22%3A%2200-000013%22%2C%20%22Email%20Last%20Acquired%20Date%22%3A%222021-09-14%2009%3A41%3A37%22%20%7D%2C%20%22properties%22%3A%7B%20%22%24event_id%22%3A%22388948924%22%2C%20%22%24value%22%3A%22323.01%22%2C%20%22OrderId%22%3A%223000470847612%22%2C%20%22OrderedDate%22%3A%222021-07-26T03%3A25%3A33%22%2C%20%22PaymentTerm%22%3A%22Credit%20Card%22%2C%20%22ProductSubTotal%22%3A%22294.98%22%2C%20%22EstimatedTax%22%3A%2228.03%22%2C%20%22ShippingTotal%22%3A%220.0%22%2C%20%22OrderTotal%22%3A%22323.01%22%2C%20%22DiscountTotal%22%3A%220.0%22%2C%20%22Domain%22%3A%22workspaceart.com%22%2C%20%22CurrencyISOCode%22%3A%22USD%22%2C%20%22CountryISOCode%22%3A%22US%22%2C%20%22Items%22%3A%5B%20%7B%20%22LineId%22%3A%22334987274%22%2C%20%22ProductID%22%3A%221871616%22%2C%20%22SKU%22%3A%2212377756A%22%2C%20%22ProductName%22%3A%22Doctor%20Maria%20Montessori%22%2C%20%22ItemDisplayedType%22%3A%22Premium%20Giclee%20Print%22%2C%20%22Quantity%22%3A%221%22%2C%20%22UnitCharge%22%3A%22157.99%22%2C%20%22Discount%22%3A%220%22%2C%20%22OriginalPrice%22%3A%22157.99%22%2C%20%22SellingPrice%22%3A%22157.99%22%2C%20%22ItemType%22%3A%22POD%22%2C%20%22UnitOfMeasure%22%3A%22INC%22%2C%20%22Height%22%3A%2212%22%2C%20%22Width%22%3A%2216%22%2C%20%22ServiceType%22%3A%22Frame%22%2C%20%22ServiceAttributes%22%3A%7B%20%22GlassName%22%3A%22Acrylic%3A%20Clear%22%2C%20%22Mats%22%3A%5B%20%7B%20%22Position%22%3A1%2C%20%22MatName%22%3A%22Crisp%20-%20Bright%20White%22%20%7D%20%5D%2C%20%22Moldings%22%3A%5B%20%7B%20%22Position%22%3A%221%22%2C%20%22MoldingName%22%3A%22ALLEGRO%20Silver%20Wide%22%2C%20%22SideLengths%22%3A%7B%20%22Top%22%3A%2218%22%2C%20%22Right%22%3A%2222%22%2C%20%22Bottom%22%3A%2218%22%2C%20%22Left%22%3A%2222%22%20%7D%20%7D%20%5D%2C%20%22Liners%22%3A%5B%20%5D%20%7D%2C%20%22TimeToShip%22%3A%7B%20%22WebsitePromisedTimeToShipDays%22%3A%224%22%2C%20%22WebsitePromisedTimeToShipDate%22%3A%222021-08-05T03%3A24%3A56%22%2C%20%22EstimatedShipDate%22%3A%222021-08-09T23%3A59%3A00%22%2C%20%22ArrivalByDateMin%22%3A%222021-09-18T09%3A41%3A36%22%2C%20%22ArrivalByDateMax%22%3A%222021-09-18T09%3A41%3A36%22%20%7D%2C%20%22PrintSize%22%3A%2212x16%22%2C%20%22ProductImageURL%22%3A%22https%3A%2F%2Fimgc.allpostersimages.com%2Fimg%2Fprint%2Fu-g-OU1RQC7DO8.jpg%3Fw%3D338%26h%3D450%26amp%3Bp%3D0%22%2C%20%22ImageId%22%3A%221743359%22%2C%20%22PODConfigId%22%3A%224986478%22%2C%20%22PhysicalDimensionWidth%22%3A%2216%22%2C%20%22PhysicalDimensionHeight%22%3A%2212%22%2C%20%22PhysicalDimensionUnit%22%3A%22INC%22%20%7D%2C%20%7B%20%22LineId%22%3A%22334987273%22%2C%20%22ProductID%22%3A%226804869%22%2C%20%22SKU%22%3A%224123616437A%22%2C%20%22ProductName%22%3A%22Montessori%20School%22%2C%20%22ItemDisplayedType%22%3A%22Giclee%20Print%22%2C%20%22Quantity%22%3A%221%22%2C%20%22UnitCharge%22%3A%22136.99%22%2C%20%22Discount%22%3A%220%22%2C%20%22OriginalPrice%22%3A%22136.99%22%2C%20%22SellingPrice%22%3A%22136.99%22%2C%20%22ItemType%22%3A%22POD%22%2C%20%22UnitOfMeasure%22%3A%22INC%22%2C%20%22Height%22%3A%2218%22%2C%20%22Width%22%3A%2212%22%2C%20%22ServiceType%22%3A%22Frame%22%2C%20%22ServiceAttributes%22%3A%7B%20%22GlassName%22%3A%22Acrylic%3A%20Clear%22%2C%20%22Mats%22%3A%5B%20%7B%20%22Position%22%3A1%2C%20%22MatName%22%3A%22Crisp%20-%20Bright%20White%22%20%7D%20%5D%2C%20%22Moldings%22%3A%5B%20%7B%20%22Position%22%3A%221%22%2C%20%22MoldingName%22%3A%22GRAMERCY%20Black%22%2C%20%22SideLengths%22%3A%7B%20%22Top%22%3A%2224%22%2C%20%22Right%22%3A%2218%22%2C%20%22Bottom%22%3A%2224%22%2C%20%22Left%22%3A%2218%22%20%7D%20%7D%20%5D%2C%20%22Liners%22%3A%5B%20%5D%20%7D%2C%20%22TimeToShip%22%3A%7B%20%22WebsitePromisedTimeToShipDays%22%3A%224%22%2C%20%22WebsitePromisedTimeToShipDate%22%3A%222021-08-05T03%3A24%3A56%22%2C%20%22EstimatedShipDate%22%3A%222021-08-09T23%3A59%3A00%22%2C%20%22ArrivalByDateMin%22%3A%222021-08-13T05%3A17%3A13%22%2C%20%22ArrivalByDateMax%22%3A%222021-08-13T05%3A17%3A13%22%20%7D%2C%20%22PrintSize%22%3A%2212x18%22%2C%20%22ProductImageURL%22%3A%22https%3A%2F%2Fimgc.allpostersimages.com%2Fimg%2Fprint%2Fu-g-Q1G8CVRD1A1W.jpg%3Fw%3D400%26amp%3Bh%3D267%26amp%3Bp%3D0%22%2C%20%22ImageId%22%3A%224755636%22%2C%20%22PODConfigId%22%3A%229436042%22%2C%20%22PhysicalDimensionWidth%22%3A%2212%22%2C%20%22PhysicalDimensionHeight%22%3A%2218%22%2C%20%22PhysicalDimensionUnit%22%3A%22INC%22%20%7D%20%5D%2C%20%22BillingAddress%22%3A%7B%20%22FirstName%22%3A%22Steven%22%2C%20%22LastName%22%3A%22Test%22%2C%20%22Address1%22%3A%22123%20main%20street%22%2C%20%22City%22%3A%22Boston%22%2C%20%22State%22%3A%22MA%22%2C%20%22Country%22%3A%22United%20States%22%2C%20%22CountryCode%22%3A%22US%22%2C%20%22ZipCode%22%3A%2202118%22%2C%20%22Phone%22%3A%221234567890%22%20%7D%2C%20%22ShippingAddress%22%3A%7B%20%22FirstName%22%3A%22Steven%22%2C%20%22LastName%22%3A%22Test%22%2C%20%22Address1%22%3A%22123%20main%20street%22%2C%20%22City%22%3A%22Boston%22%2C%20%22State%22%3A%22MA%22%2C%20%22Country%22%3A%22United%20States%22%2C%20%22CountryCode%22%3A%22US%22%2C%20%22ZipCode%22%3A%2202118%22%2C%20%22Phone%22%3A%221234567890%22%20%7D%2C%20%22Email%22%3A%22aacosta%40tohigherground.com%22%2C%20%22ShippingPriority%22%3A%22Standard%22%2C%20%22CreditCard%22%3A%7B%20%22Type%22%3A%22MC%22%2C%20%22Token%22%3A%22RTA%22%2C%20%22AccountIdentifier%22%3A%22123%22%2C%20%22ExpirationMonth%22%3A%22123%22%2C%20%22ExpirationYear%22%3A%223000%22%2C%20%22AccountName%22%3A%22Steven%20Gaudino%22%20%7D%20%7D%20%7D'

    headers = {
    'Content-Type': 'application/x-www-form-urlencoded'
    }

    response = requests.request("POST", url, headers=headers, data=payload)

    print(response.text)

    It’ll look a bit weird because of the form encoded payload, but at any rate, you can use built in functions from whatever language you’re using to form/urlencode the payload before sending the track request.

     

    Let me know if that helps!

    12 replies

    David To
    Klaviyo Employee
    Klaviyo Employee
    November 9, 2021

    Hey@smp,

    It looks like you may have to URL encode the data you are sending. 

    When comparing the code examples from the Track & Identify section of the Klaviyo's API Documentation versus your example request, we can see the data is not encoded.

    Example from the Track & Identify section:

    CURLOPT_POSTFIELDS => "data=%7B%22token%22%3A%20%22PUBLIC_KEY%22%2C%20%22event%22%3A%20%22Ordered%20Product%22%2C%20%22customer_properties%22%3A%20%7B%22%24email%22%3A%20%22abraham.lincoln%40klaviyo.com%22%7D%2C%20%22properties%22%3A%20%7B%22item_name%22%3A%20%22Boots%22%2C%22%24value%22%3A%20100%7D%7D",

    Your example request:

    CURLOPT_POSTFIELDS => array('data' => '{"token": "VYUvy9", "event": "Placed Order", "customer_properties": {"$email": "thomas.jefferson@gmail.com"}, "properties": {"item_name": "Boots","$value": 100}}'),

    David

     

    Contributor II
    November 10, 2021

    Thank you for taking a look! I copy pasted the example and swapped my public key and it posted! now I just have to figure out how to code that.