cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Escaped quotes turning into not-escaped quotes and \n being turned into newline (HTTP to GraphQL)

bedelman0731
Deputy Chef II
Deputy Chef II

I'm building a pipeline that takes contents from one system (via an API call using the HTTP connector) which is then being used to create/update an object in a different system (via the GraphQL connector issuing a mutation). The content coming from the source system, at times, can contain embedded quotes in the content that are escaped (ex. \") - especially when that content is HTML based. Content that does not contain escaped quotes is working without issue.

Example of the incoming content: 

<p>Throughout this engaging session you will:</p>\n\n<ul>\n<li><span style=\"font-size:11pt\"><span style=\"font-family:Calibri,sans-serif\">Explore the transformative potential of leveraging low-code and no-code tools and workflows to automate repetitive and time-consuming office processes</span></span></li>\n<li><span style=\"font-size:11pt\"><span style=\"font-family:Calibri,sans-serif\">Capture data that can be used to make informed decisions regarding resource allocation</span></span></li>\n<li><span style=\"font-size:11pt\"><span style=\"font-family:Calibri,sans-serif\">Identify areas where investing time and energy can be most impactful</span></span></li>\n</ul>

However, when it goes to use the content from that step in the recipe to use GraphQL, it appears that the escaped quotes are not being escaped - which, I think, is what is causing the GraphQL connector to have an error.

Example of the content being sent via GraphQL: 

<p>Throughout this engaging session you will:</p>

<ul>
<li><span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">Explore the transformative potential of leveraging low-code and no-code tools and workflows to automate repetitive and time-consuming office processes</span></span></li>
<li><span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">Capture data that can be used to make informed decisions regarding resource allocation</span></span></li>
<li><span style="font-size:11pt"><span style="font-family:Calibri,sans-serif">Identify areas where investing time and energy can be most impactful</span></span></li>
</ul>

If I use the content with the escaped quotes and the escaped newlines to issue the same call using GraphQL to the destination system using Postman, the operation succeeds without issue.

Is there anyway to change things so that the content remains as it was originally ingested?

1 ACCEPTED SOLUTION

bedelman0731
Deputy Chef II
Deputy Chef II

Thank you for the suggestions! The issue was two-fold in that the escaped quotes were being un-escaped and the \n (or \r) were being expanded into newline or carriage returns. The solution which is working is to perform two .gsub operations

  1. Replace \r\n or \n or \r with a <p />
  2. Replace plain embedded quotes with escaped quotes
DATA.gsub(/(\r\n|\n|\r)/,'<p />').gsub('"','\"')

 

View solution in original post

6 REPLIES 6

shivakumara
Executive Chef II
Executive Chef II

Hi @bedelman0731 ,

From your requirement, I understand that: 
 1. You need to pass an HTML payload with escaped double quotes (\") to GraphQL.
2. However, GraphQL is ignoring the escape sequence when processing the request, leading to errors.

To resolve this, we can use Workatoโ€™s gsub function to explicitly replace double quotes (") with escaped quotes (\").

๐Ÿ“Œ Solution:
Apply the following formula in Workato before sending the request:

data.gsub('"', '\"')

Here, data refers to the incoming HTML content. This ensures that double quotes remain properly escaped when passed to GraphQL, preventing any parsing issues.

Please let me know if my understanding is incorrect so that I can refine the approach and provide a better solution.

Thanks and Regards,
Shivakumar K A

Thank you - I implemented the gsub and the content is now properly escaped. However, the GraphQL is still having issues as it is throwing a Expected string or block string, but it was malformed  error. And if I perform the same mutate via Postman, it succeeds

I suspect that the GraphQL connector isn't "liking" having quotes inside of a field (whether they're escaped or not)

Upon further testing - it now appears that the issue is NOT solely with the escaped quotes as originally thought. It seems that it is the \n representation for newline that are being translated to actual newlines within what is trying to be sent over

This content succeeds

<p>Throughout this engaging session you will:</p>\n\n<ul>\n<li><span style=\"font-size:11pt\"><span style=\"font-family:Calibri,sans-serif\">Explore the transformative potential of leveraging low-code and no-code tools and workflows to automate repetitive and time-consuming office processes</span></span></li>\n<li><span style=\"font-size:11pt\"><span style=\"font-family:Calibri,sans-serif\">Capture data that can be used to make informed decisions regarding resource allocation</span></span></li>\n<li><span style=\"font-size:11pt\"><span style=\"font-family:Calibri,sans-serif\">Identify areas where investing time and energy can be most impactful</span></span></li>\n</ul>

But it fails when the \n is being replaced with actual newlines

gary1
Executive Chef III
Executive Chef III

On a successful API call to write the data to the second system without any replacing,  what's the issue? Is the second system displaying "\n" literally?