customerio-node icon indicating copy to clipboard operation
customerio-node copied to clipboard

Escaping quotes in requests

Open danielpadmore opened this issue 3 years ago • 3 comments

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 avatar May 30 '22 09:05 danielpadmore

@danielpadmore Thanks for reporting this! Unfortunately I'm not able to replicate it. Can you provide the following info:

  • node version
  • npm version
  • customerio-node version

Thanks!

mike-engel avatar May 31 '22 14:05 mike-engel

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-node version: 3.1.0

danielpadmore avatar Jun 23 '22 08:06 danielpadmore

@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!

mike-engel avatar Jul 14 '22 13:07 mike-engel