Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escaping quotes in requests #112

Open
danielpadmore opened this issue May 30, 2022 · 3 comments
Open

Escaping quotes in requests #112

danielpadmore opened this issue May 30, 2022 · 3 comments

Comments

@danielpadmore
Copy link

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.

@mike-engel
Copy link
Collaborator

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

@danielpadmore
Copy link
Author

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

@mike-engel
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants