SOLVED

Newline in form fields causes problems in web hook

Go to solution
Franky_Ruyssch2
Level 4

Newline in form fields causes problems in web hook

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 :

screenshot_2022-02.png

 

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

Franky Ruysschaert
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Newline in form fields causes problems in web hook

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.

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Newline in form fields causes problems in web hook

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

Re: Newline in form fields causes problems in web hook

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 - Community Moderator

Re: Newline in form fields causes problems in web hook


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 - Community Moderator

Re: Newline in form fields causes problems in web hook


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.