klaviyo-api-node
klaviyo-api-node copied to clipboard
Calling `profilesApi.updateProfile` returns a `409` error `duplicate_profile`
I'm working in typescript.
- Attempting to update a profile returns a duplicate profile error.
- The
updateProfilemethod takesprofileIdas 2 different arguments for no good reason; enforced by typescript.
import {
ApiKeySession,
ProfilesApi,
ProfilePartialUpdateQuery,
ProfilePartialUpdateQueryResourceObjectAttributes,
} from 'klaviyo-api';
const session = new ApiKeySession(process.env.KLAVIYO_PRIVATE_TOKEN);
const profilesApi = new ProfilesApi(session);
const profileAttributes: ProfilePartialUpdateQueryResourceObjectAttributes = {
email: '[email protected]',
firstName: 'test',
lastName: 'user',
phoneNumber: '+15551230987'
};
const profileResponse = await profilesApi.getProfiles({
filter: `equals(email,"${profileAttributes.email}")`,
});
const profileId = profileResponse.body.data[0].id;
if (!profileId) {
throw new Error('This profile doesn't exist.');
}
const partialUpdateQuery: ProfilePartialUpdateQuery = {
data: {
id: profileId, // why is this required if the updateProfile method takes profile ID as an argument?
type: 'profile',
attributes: profileAttributes,
},
};
await profilesApi.updateProfile(profileId, partialUpdateQuery);
this is the error that's returned:
{
"errors": [
{
"id": "853cbd75-0a3b-40ab-a13f-d729ff826844",
"status": 409,
"code": "duplicate_profile",
"title": "Conflict.",
"detail": "A profile already exists with one of these identifiers.",
"source": {
"pointer": "/data/attributes"
},
"links": {},
"meta": {
"duplicate_profile_id": "< profile id here >"
}
}
]
}
E-mail and phone numbers for profiles are unique properties, so the API won't allow you to update a profile with a value that already exists. Could you double check that the values you're passing for those two fields are unique values? I believe the same applies for your other open issue here.