Skip to content

Commit

Permalink
fix: add check to remove empty properties object from payload (#2896)
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwal-ab authored Dec 12, 2023
1 parent bf39215 commit 1a86a07
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/v0/destinations/klaviyo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ const identifyRequestHandler = async (message, category, destination, reqMetadat
data.attributes.properties = flattenProperties
? flattenJson(data.attributes.properties, '.', 'normal', false)
: data.attributes.properties;

if (isEmptyObject(data.attributes.properties)) {
delete data.attributes.properties;
}
const payload = {
data: removeUndefinedAndNullValues(data),
};
Expand Down
144 changes: 144 additions & 0 deletions test/__tests__/data/klaviyo.json
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,150 @@
}
]
},
{
"description": "Identify call without user custom Properties",
"input": {
"destination": {
"Config": {
"publicApiKey": "dummyPublicApiKey",
"privateApiKey": "dummyPrivateApiKey",
"enforceEmailAsPrimary": false
}
},
"message": {
"type": "identify",
"sentAt": "2021-01-03T17:02:53.195Z",
"userId": "user@1",
"channel": "web",
"context": {
"os": {
"name": "",
"version": ""
},
"app": {
"name": "RudderLabs JavaScript SDK",
"build": "1.0.0",
"version": "1.1.11",
"namespace": "com.rudderlabs.javascript"
},
"traits": {
"firstName": "Test",
"lastName": "Rudderlabs",
"email": "[email protected]",
"phone": "+12 345 578 900",
"userId": "user@1",
"title": "Developer",
"organization": "Rudder",
"city": "Tokyo",
"region": "Kanto",
"country": "JP",
"zip": "100-0001",
"properties": {
"listId": "XUepkK",
"subscribe": true,
"consent": ["email", "sms"]
}
},
"locale": "en-US",
"screen": {
"density": 2
},
"library": {
"name": "RudderLabs JavaScript SDK",
"version": "1.1.11"
},
"campaign": {},
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0"
},
"rudderId": "8f8fa6b5-8e24-489c-8e22-61f23f2e364f",
"messageId": "2116ef8c-efc3-4ca4-851b-02ee60dad6ff",
"anonymousId": "97c46c81-3140-456d-b2a9-690d70aaca35",
"integrations": {
"All": true
},
"originalTimestamp": "2021-01-03T17:02:53.193Z"
}
},
"output": [
{
"version": "1",
"type": "REST",
"method": "PATCH",
"endpoint": "https://a.klaviyo.com/api/profiles/01GW3PHVY0MTCDGS0A1612HARX",
"headers": {
"Authorization": "Klaviyo-API-Key dummyPrivateApiKey",
"Content-Type": "application/json",
"Accept": "application/json",
"revision": "2023-02-22"
},
"params": {},
"body": {
"JSON": {
"data": {
"type": "profile",
"attributes": {
"email": "[email protected]",
"first_name": "Test",
"last_name": "Rudderlabs",
"phone_number": "+12 345 578 900",
"external_id": "user@1",
"title": "Developer",
"organization": "Rudder",
"location": {
"city": "Tokyo",
"region": "Kanto",
"country": "JP",
"zip": "100-0001"
}
},
"id": "01GW3PHVY0MTCDGS0A1612HARX"
}
},
"JSON_ARRAY": {},
"XML": {},
"FORM": {}
},
"files": {}
},
{
"version": "1",
"type": "REST",
"method": "POST",
"endpoint": "https://a.klaviyo.com/api/profile-subscription-bulk-create-jobs",
"headers": {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": "Klaviyo-API-Key dummyPrivateApiKey",
"revision": "2023-02-22"
},
"params": {},
"body": {
"JSON": {
"data": {
"type": "profile-subscription-bulk-create-job",
"attributes": {
"list_id": "XUepkK",
"subscriptions": [
{
"email": "[email protected]",
"phone_number": "+12 345 578 900",
"channels": {
"email": ["MARKETING"],
"sms": ["MARKETING"]
}
}
]
}
}
},
"JSON_ARRAY": {},
"XML": {},
"FORM": {}
},
"files": {}
}
]
},
{
"description": "Identify call without email and phone & enforceEmailAsPrimary enabled from UI",
"input": {
Expand Down

0 comments on commit 1a86a07

Please sign in to comment.