How to pass a newline when setting a multi-line property via the API?

SOLVE
davidk
Member

Is it possible to include newlines in multi-line property fields, set via API?

 

Setting the value via API seems to strip or ignore newlines.

 

So if the JSON is any of:

"my_multi_line_type_property" : "Line 1\nLine 2"

"my_multi_line_type_property" : "Line 1\\nLine 2"

"my_multi_line_type_property" : "Line 1<br>Line 2"

 

the resulting property looks like

Line 1\nLine 2

Line 1\\nLine 2

Line 1<br>Line 2

 

I'm trying to achieve

Line 1

Line 2

 

There was prior discussion about this here on thread 19092.

 

0 Upvotes
1 Accepted solution

Accepted Solutions
dennisedson
Solution
Community Manager

@davidk 

The first version should work...I tested on my end.  Please see screengrab and code snippet I used

Property_Editor.png

{
    "properties": {
        "multi_line": "if i send it back...what about this?\nif we make it multiline?\ndoes it work"
    }
}

 

This is using the crm/v3/objects/contacts/:contactid with the patch method

Thanks,

Dennis




Check out our Community Developer Blog
where we feature our Community driven developer podcast and how to content

View solution in original post

3 Replies 3
webdew
Top Contributor | Diamond Partner

Hi @davidk ,

You also need to escape the backslash with this /\n/ or use replace(/\\n/g, "\\n") .Also you can do the string escaping online for any other type of string that you need to pass through json.

Hope this helps!


If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards. 

0 Upvotes
davidk
Member

Thanks for your answer, @webdew !  I'd like to clarify:

 

  • I'm new to hubspot. I RTFM'd and don't see regex or replace functions in hubspot. Can you point me at it?

  • are you saying the JSON value should be:

    "my_multi_line_type_property" : "Line 1/\n/Line 2"  ???

     

     replace(/\\n/g, "\\n") 
    Doesn't that just replace "\\n" with "\\n" ? or, with the escaped slach,  \n with \n?

  • you write  I need to escape the backslash with /\n/ 
    I'm not following. Are you saying that "/" escapes the back slash or.. that paired slashes act like quotes in hubspot fields? 

Thanks a lot! I'll experiment with your pointers and see if it works.

 

 

 

 

0 Upvotes
dennisedson
Solution
Community Manager

@davidk 

The first version should work...I tested on my end.  Please see screengrab and code snippet I used

Property_Editor.png

{
    "properties": {
        "multi_line": "if i send it back...what about this?\nif we make it multiline?\ndoes it work"
    }
}

 

This is using the crm/v3/objects/contacts/:contactid with the patch method

Thanks,

Dennis




Check out our Community Developer Blog
where we feature our Community driven developer podcast and how to content

View solution in original post