Giter VIP home page Giter VIP logo

Comments (1)

jon-batscha avatar jon-batscha commented on September 28, 2024

Hey Savraj,

Thanks for reaching out.

In our recent upgrade of our APIs, we split both the track and identify endpoints into two client- and server-side equivalents, each.

I am assuming you're using these serverside (but correct me otherwise).

In this case, here is how you would migrate:

  1. install the new package
pip install klaviyo-api
  1. instantiate the client:
from klaviyo_api import KlaviyoAPI

klaviyo = KlaviyoAPI("YOUR_API_KEY_HERE")
  1. track -> create_event:
body = {
  "data": {
    "type": "event",
    "attributes": {
      "properties": {},
      "metric": {
        "data": {
          "type": "metric",
          "attributes": {
            "name": "<string>",
          }
        }
      },
      "profile": {
        "data": {
          "type": "profile",
          "attributes": {
            "email": "<string>",
            "phone_number": "<string>",
            "external_id": "<string>",
            "anonymous_id": "<string>",
            "_kx": "<string>",
            "first_name": "<string>",
            "last_name": "<string>",
            "organization": "<string>",
            "title": "<string>",
            "image": "<string>",
            "location": {
              "address1": "<string>",
              "address2": "<string>",
              "city": "<string>",
              "country": "<string>",
              "latitude": "<string>",
              "longitude": "<string>",
              "region": "<string>",
              "zip": "<string>",
              "timezone": "<string>"
            },
            "properties": {}
          },
          "id": "<string>",
          "meta": {
            "patch_properties": {
              "append": {},
              "unappend": {},
              "unset": "<string>"
            }
          }
        }
      },
      "time": "<dateTime>",
      "value": "<number>",
      "unique_id": "<string>"
    }
  }
}
klaviyo.Events.create_event(body)

in your case, you could substitute in the values you have for event, email, event_properties and customer_properties into the above. Some reminders:

  • separate the customer_properties into "custom_properties", which would go in attributes.properties, from the standard predefined customer properties, that go in attributes and attributes.location
  • if your event_properties uses the deprecated $value, make sure to move that to attributes.value (more broadly, we have moved away from the $<attribute>) in favor of the new predefined properties, which are optional
  • include email within attributes, as presumably, that's the identifier you'll be using. the predefined properties above are optional, with the exception of at least on identifier (email, phone_number, etc), so minimally, your payload could look like this:
body = {
  "data": {
    "type": "event",
    "attributes": {
      "properties": event_properties,
      "metric": {
        "data": {
          "type": "metric",
          "attributes": {
            "name": event_name,
          }
        }
      },
      "profile": {
        "data": {
          "type": "profile",
          "attributes": {
            "email": email,
            "properties": customer_properties
          },
        }
      },
      "value": event_properties.get('$value'),
      "unique_id": "<string>"
    }
  }
}
  1. identify -> create_profile:

This is similar to the create_event call above, just with a simpler payload. As above, feel free to remove any of the optional predefined attributes:

body = {
	"data": {
		"type": "profile",
		"attributes": {
			"email": "<string>",
			"phone_number": "<string>",
			"external_id": "<string>",
			"first_name": "<string>",
			"last_name": "<string>",
			"organization": "<string>",
			"title": "<string>",
			"image": "<string>",
			"location": {
				"address1": "<string>",
				"address2": "<string>",
				"city": "<string>",
				"country": "<string>",
				"latitude": "<string>",
				"longitude": "<string>",
				"region": "<string>",
				"zip": "<string>",
				"timezone": "<string>"
			},
			"properties": {}
		}
	}
}

klaviyo.Profiles.create_profile(body)

If you have any other migration related questions, we have some resources on this page.

Though to your point, we definitely need to add some SDK-specific migration resources; I'll add that to our team's near-term roadmap.

Definitely reach out if you run into any further issues.

(also, i see you've been a GitHub user since the year it was founded, very cool)

Cheers,
Jon

from klaviyo-api-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.