How to measure the size of a customer attribute in open messaging API?

Hi Folks,

Reviewing the Open Messaging API documentation , about The maximum size of all the custom attributes' key strings and value strings together (not including quotes, commas, or braces used in JSON representation) in one message must be less than 2KB.

However, when performing tests using the code below to limit the size to the maximum allowed (2KB), the API responds that the size is greater than 2048 bytes.

function checkCustomAttributesSize(customAttributes) {
let totalSize = 0;

// We recurse each key/value pair in customAttributes
for (const [key, value] of Object.entries(customAttributes)) {
// Sum the key size
totalSize += Buffer.byteLength(key, 'utf8');

// Sum the size of the value (convert to string if necessary)
totalSize += Buffer.byteLength(String(value), 'utf8');
}
}

I would like to receive instructions on how to calculate the maximum size allowed (2KB) in the open messaging API, in order to limit the sending of custom attributes to what is allowed by the API and avoid failures.

Attached are two examples, one in which the API accepts the message and one in which the API returns that the size has been exceeded.

However, both examples do not have a size greater than 2KB adding the key and value in utf8.

Thx advanced

Járlei
sample_nok.json (2.0 KB)
sample_ok.json (2.0 KB)

1 Like

Hi guys any news???

thx

Járlei

Hi Járlei,

So sorry for the delay in response and thank you for the feedback it has been very useful.
After looking into your issue. I would have to agree the docs outlined here Open Messaging API documentation are very misleading I will take and action to update them to more accurately reflect the check.

regarding your code snippet it should be as simple as

function checkCustomAttributesSize(customAttributes) {
return Buffer.byteLength(JSON.stringify(customAttributes), 'utf8');
}

From my digging into this topic there is a bug which slightly bloats your string value for this check which I hope to fix and rollout to all production regions in the coming weeks.

Hope this finds you well and thank you again for being an active member of our forum,
Colum Mullally

2 Likes

Do you know when this solution will be available?

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.