SOLVED

Re: Remove line breaks from a Text field

Go to solution
ChadWebb
Level 2

Remove line breaks from a Text field

Is it possible to remove line breaks from within a Text field using a Flow step?
We are using a Text field in a webhook call, and getting a BadRequest error when the field has line breaks and does not adhere to JSON string format.

Chad Webb
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Remove line breaks from a Text field

You don’t add quotes around the tokens in the payload.

 

JSON encoding takes care of quoting when necessary. It encodes values based on the datatype (string, number, boolean).

View solution in original post

9 REPLIES 9
SanfordWhiteman
Level 10 - Community Moderator

Re: Remove line breaks from a Text field

Your question isn't clear: string values don't need to "adhere to JSON string format" because Marketo JSON-encodes strings properly when you have JSON selected in the webhook definition.

It's impossible for stored values to all be valid JSON. That would mean they'd have literal double quotes in the database!
ChadWebb
Level 2

Re: Remove line breaks from a Text field

Here is the response I got from the target system admin...


I checked the logs of PROD and looks like there is an issue with the "message" tag . Its having multiple line breaks and not adhering to JSON string format  hence you are getting Bad Request. 
Below is the message tag which is coming with multiple line breaks and not adhering to the right JSON Format.
image.png
Solution : 
Please replace the line breaks with \n so it adheres to string format ( as shown below)  Post this it should work .
   "message""Please send me a quote for this instrument Roche Cobas Z 480 .\nThanks,\nBin",
Chad Webb
SanfordWhiteman
Level 10 - Community Moderator

Re: Remove line breaks from a Text field

You need to have Request Token Encoding set to JSON:

SanfordWhiteman_0-1709744954637.png

There’s no need to make changes to the stored value.

 

ChadWebb
Level 2

Re: Remove line breaks from a Text field

Already in place...

JSON Setting.jpg

Chad Webb
SanfordWhiteman
Level 10 - Community Moderator

Re: Remove line breaks from a Text field

Where is that “message“ JSON property coming from?

ChadWebb
Level 2

Re: Remove line breaks from a Text field

It is part of the Payload of the webhook call - the syntax is below.

 

{

"salesOrg": "{{lead.Sales Org:default=edit me}}",
"contactId": "{{member.PMCFstring6}}",
"accountId": "{{lead.Account Nbr (SFDC):default=edit me}}",
"campaignName": "{{member.PMCFstring5}}",
"firstName": "{{lead.First Name:default=edit me}}",
"lastName": "{{lead.Last Name:default=edit me}}",
"fullName": "{{lead.Full Name:default=edit me}}",
"email": "{{lead.Email Address:default=edit me}}",
"phone": "{{lead.Phone Number:default=edit me}}",
"city": "{{lead.City:default=edit me}}",
"state": "{{lead.State:default=edit me}}",
"zip": "{{lead.Postal Code:default=edit me}}",
"country": "{{lead.Country:default=edit me}}",
"currencyIsoCode": "{{lead.Lead Currency:default=edit me}}",
"company": "{{lead.Company_formUse:default=edit me}}",
"profession": "{{lead.Profession:default=edit me}}",
"position": "{{lead.Primary Position:default=edit me}}",
"leadId": "{{member.PMCFstring7}}",
"products": "{{Lead.Web product Interest:default=edit me}}",
"inquiryType": "{{member.PMCFstring1}}",
"message": "{{Lead.Feedback_txt_long:default=edit me}}",
"formId": "{{member.PMCFstring3}}",
"formName": "{{member.PMCFstring4}}",
"formUrl": "{{member.PMCFstring2}}",
"sourceSystem": "{{lead.Lead Source:default=edit me}}"

}

 

The fields on the left are SFDC fields. 

Chad Webb
SanfordWhiteman
Level 10 - Community Moderator

Re: Remove line breaks from a Text field

You don’t add quotes around the tokens in the payload.

 

JSON encoding takes care of quoting when necessary. It encodes values based on the datatype (string, number, boolean).

ChadWebb
Level 2

Re: Remove line breaks from a Text field

Thanks Sanford - that did it!

Chad Webb
SanfordWhiteman
Level 10 - Community Moderator

Re: Remove line breaks from a Text field

Good to hear, thought it would be something like that.