Skip to main content

Long Text with /n newline not working

  • July 15, 2020
  • 5 replies
  • 73 views

Hi,

I am using the API to create records in aritable, but cannot figure out how to create a new line in a long text field. I am currently passing a string with “/n” in it at the point I would like a new line, but all it does is show “/n” instead of creating a new line.

Any tips appreciated.

5 replies

ScottWorld
Forum|alt.badge.img+35
  • Genius
  • 9808 replies
  • July 15, 2020

You need to use \n, not /n.


Forum|alt.badge.img
  • New Participant
  • 3 replies
  • July 15, 2020

Whoops, sorry, typo. I used \n and still no luck. Even tried /n just in case, but it still just writes the sentence in one line with the \n in the text.


ScottWorld
Forum|alt.badge.img+35
  • Genius
  • 9808 replies
  • July 15, 2020

Whoops, sorry, typo. I used \n and still no luck. Even tried /n just in case, but it still just writes the sentence in one line with the \n in the text.


Hmm, not sure. It works for me. (I am using CURL, not JavaScript.) Maybe someone else will have some additional advice for you.


Forum|alt.badge.img
  • New Participant
  • 3 replies
  • July 15, 2020

Thanks Scott- appreciate for the effort. I am using Curl also.

My php Code setting up the string (as address):
$shippingaddress = $order->shipping_address_1 . ‘,\n’ . $order->shipping_address_2 . ‘\n’ . $order->shipping_city . ‘,\n’ . $order->shipping_state . ’ ’ .$order->shipping_postcode;

which results in a string something like this being passed to Airtable:
“10 Any Street,\nSuburb,\nVIC3000”

The fields are added into an array, json encoded, then Posted using the following:
curling statement here;
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
‘Content-Type: application/json’
));

This works fine, but \n is retained just as sent instead of being read as a line break.


Forum|alt.badge.img
  • New Participant
  • 3 replies
  • July 15, 2020

I found the problem. It was two-fold.

  1. The \n needs to be in double quotes: “\n”
  2. I needed to add options to the json_encode as it was adding another
    $data_json = json_encode($data,JSON_UNESCAPED_LINE_TERMINATORS | JSON_UNESCAPED_SLASHES);