Solved

POST | Create Event - Action silently fails if only a phone number is used as profile identifier

  • 6 March 2023
  • 7 replies
  • 215 views

Userlevel 1
Badge +1

Hello!

I was wondering if I could get confirmation that the following behaviour is correct. When making a POST request to the /events endpoints, if the payload only includes a phone_number, the event silently fails, with no corresponding event created on the relevant metric in the dashboard.

Does this endpoint have the similar requirement which the POST for /profile has with regards to requiring SMS to be setup if only using a phone number?

(I have tested this on an account which deliberately had SMS turned off, and am now awaiting the verification process for SMS to be active again on the account.)

icon

Best answer by maxchauandzen 6 March 2023, 21:56

View original

7 replies

Userlevel 2
Badge +6

Yes, this is expected behavior.  For an event to be recorded there must either be an ‘email’ or ‘id’ submitted with it, regardless if you are intended to use SMS only.

Userlevel 1
Badge +1

Oh interesting, I thought it was either or since the attributes payload documentation for it (https://developers.klaviyo.com/en/reference/create_event) states:

 

The profile must contain an identifier.The $email and/or $phone_number can be used as the identify the profile.

 

I suppose I would have also expected a 4xx to indicate a bad request.

Userlevel 2
Badge +6

Ah, you are correct that in API 3.0 this changed!

Post your (sanitized) payload here so we can take a look to see if there is anything else going on.

Badge +2

We have just come across the same situation and managed to get it to work. The reason it failed was because we thought the plus sign in front of the international phone numbers should be omitted.

We will also need a dollar sign in front of the phone_number key in the profile attribute.

Here is a sample PHP script that works for us:

<?

$attributes = (object)[
'profile' => (object) [
"\$phone_number" => "+" . str_replace('+', '', $phone)
]
];

So I believe playing around with the dollar sign and plus sign will get it to work.

Hope it helps!

Userlevel 1
Badge +1

Hi @cdetdi and @maxchauandzen ,

Here’s some more info.

POST https://a.klaviyo.com/api/events

 

Headers

{
"revision": "2022-10-17",
"accept": "application/json",
"Authorization": "Klaviyo-API-Key pk_***"
}

Payload

{
"data": {
"type": "event",
"attributes": {
"metric": { "name": "New Metric" },
"properties": { "value": "Test" },
"profile": { "$phone_number": "+12345678901" }
}
}
}

I can confirm that an event is successfully created if it is made from an account that is either:

  • setup and verified with an SMS number
  • setup and in process of verification.

However when making the request from an account which has not yet began SMS verification altogether, the request “fails” silently with a 202 response.

 

That is, the metric is created if it does not exist, but no event is added. 

I’m guessing that it is just some out of date documentation, and that it is indeed also a requirement when creating an event, for an account to have SMS setup, as is the case when creating a new profile.

Thanks for looking into this!

Ismael

Userlevel 2
Badge +6

My original reply was somewhat correct it seems.  Take a look at this page:
https://developers.klaviyo.com/en/reference/create_profile

If you use a phone number as the profile identifier and SMS is not set up in the Klaviyo account, you'll need to include at least one other identifier attribute (emailor external_id) in addition to the phone_number attribute for the API call to work.

 

This seems to be your exact situation - an event call to a profile which has not yet had SMS set up yet which triggers the create profile requirement.  In that case it seems that you *do* need an external identifier.

Might I suggest trying to submit the event with the external_id set to “ID[phone_numbner]” just to see it accepts this?

 

Userlevel 1
Badge +1

Hey guys, 

Had a look at this again and tested a few things. There was a helpful error API message that I noticed when trying to create the event with external id:

At least one profile identifier is required [$email, $phone_number, $id (in place of external_id used for profiles endpoints), or $kid]Any email must be valid. This request failed with reason: missing valid identifier.

In this case the event can be created only when using an id if no email is provided and sms is not setup.

Worth noting that both email and $email works, as well as id or $id.

Cheers!

Reply