Escaping quotes in requests
We have come across an issue where the customer.io client fails to send notifications when quotes are included in the payload.
For example, when sending a payload like this:
const trackClient = new TrackClient(
process.env.CUSTOMERIO_SITE_ID,
process.env.CUSTOMERIO_API_KEY
);
trackClient.track('some_user_id', {
name: 'notify',
data: {
'title': 'My Title "Just Will Not Work" With Quotes Included',
},
});
The notification will result in an "attempted" status with reason:
Custom payload is invalid JSON: invalid character 'J' after object key:value pair
I believe this is due to the quotes not being escaped by the client before the request is sent.
We are applying a fix for this prior to client use by escaping the quotes before the track call. But I wanted to flag this as a potential feature to add so others aren't caught by the same issue.
@danielpadmore Thanks for reporting this! Unfortunately I'm not able to replicate it. Can you provide the following info:
- node version
- npm version
-
customerio-nodeversion
Thanks!
Hey @mike-engel,
- node version:
16.13.1 - yarn version:
1.22.17(we use yarn cli over npm if that makes any difference) - npm version:
8.1.2 -
customerio-nodeversion:3.1.0
@danielpadmore thanks for that! I just tried this locally again with this example exactly, and everything worked correctly.
import { TrackClient } from 'customerio-node';
const trackClient = new TrackClient(
process.env.CUSTOMERIO_SITE_ID,
process.env.CUSTOMERIO_API_KEY
);
async function main() {
try {
await trackClient.track('some_user_id', {
name: 'notify',
data: {
'title': 'My Title "Just Will Not Work" With Quotes Included',
},
});
} catch (err) {
console.log(err.body);
}
}
await main();
Can you verify that this is still occurring with the latest version of customerio-node (3.3.2)? Thank you!