Newline in form fields causes problems in web hook | Community
Skip to main content
Franky_Ruyssch2
Level 4
February 2, 2022
Solved

Newline in form fields causes problems in web hook

  • February 2, 2022
  • 2 replies
  • 2618 views

I have a form with 4 text area fields. The content is sent to a web hook , which transfers the data to our server.
Everything works smoothly as long as I do not place a newline in the text area fields.

All form fields are put together as new value in a ‘Change Data Value’, so I construct a json string :

 

 

{"<u>GOOGLE UTM</u>": "","Source":"{{lead.mkt_cp_utm_latest_source}}","Medium":"{{lead.mkt_cp_utm_latest_medium}}","Campaign":"{{lead.mkt_cp_utm_latest_campaign}}”,”Question 1”:”{{lead.mkt_5428_xmpie_answer_1}}","Question 2”:”{{lead.mkt_5428_xmpie_answer_2}}","Question 3”:”{{lead.mkt_5428_xmpie_answer_3}}","Question 4”:”{{lead.mkt_5428_xmpie_answer_4}}"}

 

The content is later used in the webbook :

 

Is a newline breaking the json?

Is the JSON sent from the Marketo web hook according  to RFC7159? 'Tabs and newline characters, unencoded, are not allowed in strings in JSON according to RFC 7159

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

You aren’t constructing a JSON string if the variables aren’t truly JSON-encoded. Simple as that. You’re assembling something vaguely like JSON and hoping the dynamic parts don’t require JSON encoding — not a reasonable expectation with Textarea fields, or even with Text fields for that matter (Text fields can contain double quotes).

 

I don’t understand why you’re trying to pre-create part of a webhook JSON payload. You should be setting Request Token Encoding=JSON and building the whole thing in the Payload box. Then Marketo correctly handles the encoding for you.

2 replies

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
February 2, 2022

You aren’t constructing a JSON string if the variables aren’t truly JSON-encoded. Simple as that. You’re assembling something vaguely like JSON and hoping the dynamic parts don’t require JSON encoding — not a reasonable expectation with Textarea fields, or even with Text fields for that matter (Text fields can contain double quotes).

 

I don’t understand why you’re trying to pre-create part of a webhook JSON payload. You should be setting Request Token Encoding=JSON and building the whole thing in the Payload box. Then Marketo correctly handles the encoding for you.

Franky_Ruyssch2
Level 4
February 2, 2022

Hi Sanford,

 

thanks for your reply.

I pre-create the json, because the content is different for multiple situations. As such I can keep re-using the same webhook.

 

Maybe not the best solution?

Franky Ruysschaert
SanfordWhiteman
Level 10
February 2, 2022

I pre-create the json, because the content is different for multiple situations. As such I can keep re-using the same webhook.

 

Maybe not the best solution?


I wouldn’t say so! You just can’t assemble JSON in a non-JSON-aware environment.

 

 

SanfordWhiteman
Level 10
February 2, 2022

Is the JSON sent from the Marketo web hook according  to RFC7159? 'Tabs and newline characters, unencoded, are not allowed in strings in JSON according to RFC 7159


Of course. But since you aren’t using Request Token Encoding=JSON, Marketo has no idea you’re considering this a JSON payload.