Skip to main content
Solved

Creating an event via API

  • September 6, 2023
  • 1 reply
  • 919 views

Forum|alt.badge.img+1

Hello there,

I’m new to this community and was wondering if you can give me some guidance in a simple integration we are working on.

We already have a profile created on the platform, and I want to create an Event using the API. I’m following this documentation: https://developers.klaviyo.com/en/reference/create_event

Everything works ok, but I can’t understand why we need to attach all those Profile attributes, like name, address, etc. Is there a way to simple “attach the event View Product Page” to an existing Profile, using its ID?

Thanks in advance!

Best answer by KeviSunshine

Hi @gustavog,

You absolutely do not need to do that. I’ve never used this exact API (I’m using an older version of a POST event api), but you should only need a profile identifier (ID, email, phone), and an event name.

The API in the article you linked to is extremely verbose and unnecessary. I wish they showed a simplified version.

It should be something like this, but even this is verbose.

{
  "data": {
    "type": "event",
    "attributes": {
      "properties": {
        "newKey": "New Value"
      },
      "time": "2022-11-08T00:00:00",
      "value": 9.99,
      "metric": {
        "data": {
          "type": "metric",
          "attributes": {
            "name": "Viewed Product"
          }
        }
      },
      "profile": {
        "data": {
          "type": "profile",
          "id": "01GDDKASAP8TKDDA2GRZDSVP4H"
       }
    }
  }
}

With an older endpoint my request body is as simple as this…

{
  "token": "<...>",
  "event": "EVENT_NAME",
  "customer_properties": {
    "$email": "<ID>" // This is the profile identifier
    "new field": "whatever you'd like" // this will add this new field to the profile
  },
  "properties": {
    // Anything you want here, object, array, etc. These are the event properties.
  }
}

 

View original
Did this topic or the replies in the thread help you find an answer to your question?

1 reply

KeviSunshine
Expert Problem Solver III
Forum|alt.badge.img+8
  • Expert Problem Solver III
  • 159 replies
  • Answer
  • September 6, 2023

Hi @gustavog,

You absolutely do not need to do that. I’ve never used this exact API (I’m using an older version of a POST event api), but you should only need a profile identifier (ID, email, phone), and an event name.

The API in the article you linked to is extremely verbose and unnecessary. I wish they showed a simplified version.

It should be something like this, but even this is verbose.

{
  "data": {
    "type": "event",
    "attributes": {
      "properties": {
        "newKey": "New Value"
      },
      "time": "2022-11-08T00:00:00",
      "value": 9.99,
      "metric": {
        "data": {
          "type": "metric",
          "attributes": {
            "name": "Viewed Product"
          }
        }
      },
      "profile": {
        "data": {
          "type": "profile",
          "id": "01GDDKASAP8TKDDA2GRZDSVP4H"
       }
    }
  }
}

With an older endpoint my request body is as simple as this…

{
  "token": "<...>",
  "event": "EVENT_NAME",
  "customer_properties": {
    "$email": "<ID>" // This is the profile identifier
    "new field": "whatever you'd like" // this will add this new field to the profile
  },
  "properties": {
    // Anything you want here, object, array, etc. These are the event properties.
  }
}