Skip to main content
Solved

Error creating new profiles with phone_number only


Forum|alt.badge.img

We use Klaviyo on several different sites to sign users up for Email and SMS mailing lists, and I’ve recently started work on refactoring our API calls to use the latest endpoints (coming from v2). In the past, subscribing users to lists and adding custom properties only took a single call, but with the recent updates it appears that we now have to:

  1. Create the new user profile and add custom properties
  2. Subscribe that newly created user to the target list

All of this is working as expected when using email, but when I try to create a new user with only the phone_number field, and no email or id, I get the following error:

{
  id: 'e5988f66-18e7-4927-bdb2-7a1165a48958',
  status: 400,
  code: 'invalid',
  title: 'Invalid input.',
  detail: 'One or more identifiers is required',
  source: [Object],
  links: {},
  meta: {}
}

Is this expected behavior?

The profile creation is being triggered with the createOrUpdateProfile command from the node.js library: https://github.com/klaviyo/klaviyo-api-node

Here is an example payload for what’s being sent to the endpoint:

{
  "type":"profile",
  "attributes":{
    "$consent":"web",
    "subscriptions":{
      "sms":{
        "marketing":{
          "consent":"SUBSCRIBED"
        }
      }
    },
    "phone_number":"+19125554444",
    "properties":{
      "form_version":"x.x.x",
      "form_id":"form-id",
      "origin":"https://www.thewebsite.com"
    }
  }
}

Again, the above payload works fine when using email in place of phone_number (and changing the subscriptions.sms property to email)

Any insight is appreciated - thanks in advance,

Teddy

Best answer by KeviSunshine

It looks like the request payload is trying to do both the subscriptions and the profile creation–I didn’t think you could do that (as you mentioned, you need to do 2 API calls now).

That exact request body works with an email address? When I run the same query with an email, I get this error: 

(Note that I added the “data” prefix as that was the initial error I received)

 

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

5 replies

KeviSunshine
Expert Problem Solver III
Forum|alt.badge.img+8
  • Expert Problem Solver III
  • 158 replies
  • May 22, 2024

Hi @TeddyMichels,

We’ve recently gone through this transition and encountered some similar issues. However, we haven’t encountered this one in particular.

Do you know what endpoint your calling with the payload that you showed?

I just tried this out using the endpoints we’re using and I was able to (1) create a profile with just a phone number and (2) subscribe it to SMS.

Here is what I did:

  1. Create a profile

endpoint: `https://a.klaviyo.com/api/profile-import/`

request body:

{
    "data": {
            "type": "profile",
            "attributes": {
                "phone_number": "+15555551234",
                "properties": {
                    "test": true,
                    "first_name": "test",
                    "last_name": "test"
                }
        }
    }
}
  1. Subscribe profile to SMS

endpoint: `https://a.klaviyo.com/api/profile-subscription-bulk-create-jobs/`

request body:

{
    "data": {
        "type": "profile-subscription-bulk-create-job",
        "attributes": {
            "profiles": {
                "data": [
                    {
                        "type": "profile",
                        "attributes": {
                            "phone_number": "+15555551234",
                            "subscriptions": {
                                "sms": { "marketing": { "consent": "SUBSCRIBED" } }
                            }
                        }
                    }
                ]
            }
        },
        "relationships": {
            "list": {
                "data": {
                    "type": "list",
                    "id": "{LIST_ID}"
                }
            }
        }
    }
}

Hope that helps… 

 

Best,

Kevin.


Forum|alt.badge.img
  • Author
  • Contributor II
  • 3 replies
  • May 22, 2024

@KeviSunshine thanks for responding so quickly; good to know that your test worked - as far as I can tell the createOrUpdateProfile call is hitting the same endpoint you mentioned: https://a.klaviyo.com/api/profile-import/

Here’s the source code: https://github.com/klaviyo/klaviyo-api-node/blob/main/api/profilesApi.ts#L97

I’ll try cleaning up some extraneous bits in my code and if that doesn’t work I’ll try calling the endpoint directly rather than through the library - thanks again.


KeviSunshine
Expert Problem Solver III
Forum|alt.badge.img+8
  • Expert Problem Solver III
  • 158 replies
  • Answer
  • May 22, 2024

It looks like the request payload is trying to do both the subscriptions and the profile creation–I didn’t think you could do that (as you mentioned, you need to do 2 API calls now).

That exact request body works with an email address? When I run the same query with an email, I get this error: 

(Note that I added the “data” prefix as that was the initial error I received)

 


Forum|alt.badge.img
  • Author
  • Contributor II
  • 3 replies
  • May 22, 2024

Oh that’s interesting - yeah, here’s one I just did as a test on my end:

{
  "type":"profile",
  "attributes":{
    "$consent":"web",
    "subscriptions":{
      "email":{
        "marketing: {
          "consent":"SUBSCRIBED"
        }
      }
    }
    "email":"theodoremichels+email@gmail.com",
    "properties":{
      "form_version":"1.0.0",
      "form_id":"brick-modal",
      "origin":"http://localhost:9292",
      "BRICK_tags":[]
    }
  }
}

It seems like the new API is fine with the subscription consent stuff being there, even though I don’t think it actually works here. Maybe the klaviyo-api-node library is doing some cleanup before it hits the endpoint.

Then I did another call to subscribe the user created above, and things look good in the dashboard:

 


Forum|alt.badge.img
  • Author
  • Contributor II
  • 3 replies
  • June 21, 2024

I just wanted to check in again to report that the problem here seems to be with using the klaviyo-api-node library and not any issue with the API itself. I refactored our codebase to make the API calls directly via Axios rather than through the library and now the payloads are going through without any issues.

Using this method, it’s possible to create profiles using only a phone_number, whereas going through the API triggers the “One or more identifiers is required” error.

So as reported the payloads given above by @KeviSunshine should work. Thanks again @KeviSunshine for your time here.