APIs & Integrations

YQin
Member

How to escape single quote and double quote when programmatically set default value of a token

Hello Team, 

I have a question. We use API /content/api/v2/templates to push marketing emails to Hubspot. And when constructing the email, We replace some content with tokens to load personalized content. We inject the token using {{ personalization_token('${hubObjectType}.${p13nToken}', '${originalText.replace(/\n/g, '<br>').replace(/(['"])/g, '\\$1').trim()}')') }}, so that the originalText will display when the token isn’t available. But it seems HubSpot can’t correctly recognize the token when originalText contains single quotes (') or double quotes (''). We’ve tried some escape methods (e.g., using HTML codes for ‘ and ", javascript string replacement), but none work in all cases. Is there a reliable way to safely escape single quotes and double quotes for this case? Thank you.

 

Yizhu

0 Upvotes
2 Replies 2
BérangèreL
Community Manager
Community Manager

How to escape single quote and double quote when programmatically set default value of a token

Hi @YQin, I hope that you are well!

Thanks for asking the Community!

I'd like to invite a couple of subject matter experts to this conversation: Hi @Indra, @Syeda_Fatima and @stefen do you have suggestions to help @YQin, please?

Thanks so much and have a great day!

Best,
Bérangère


Saviez-vous que la Communauté est disponible en Français ?
Rejoignez les discussions francophones en changeant votre langue dans les paramètres !

Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings!


0 Upvotes
EJCHO
Member

How to escape single quote and double quote when programmatically set default value of a token

Hi @Indra @stefen and others, wondering if you have any tips here?

 

Basically, we cannot include an apostrophe or quotation marks in the default value for personalization_token when pushing the source content using the `/content/api/v2/templates` endpoint.

It seems there should be a way to escape these characters.

 

Thanks!

0 Upvotes