New line issue & Image need to pass in the cell for smartsheet API

77 Views Asked by At

we are passing the comment section with a rich-text editor which includes the image and paragraph type as the inputs to the smartsheet API cell. But i have the following error

{
"errorCode" : 1008,
"message" : "Unable to parse request. The following error occurred: Field \"value\" was 
not parsable. Illegal unquoted character ((CTRL-CHAR, code 13)): has to be escaped using 
backslash to be included in string value\n at [Source: 
java.io.PushbackInputStream@ae5bd59; line: 23, column: 337].",
"refId" : "3g83d4"
}

This is something with the New line "\" and CR "\r". But I tried with PHP Functions like str_replace, nl2br and Preg_replace but nothing reflected in the Smartsheet API cell.

                $curl = curl_init();
           curl_setopt_array($curl, array(
           CURLOPT_URL => 'API URL',
           CURLOPT_RETURNTRANSFER => true,
           CURLOPT_ENCODING => '',
           CURLOPT_MAXREDIRS => 10,
           CURLOPT_TIMEOUT => 0,
           CURLOPT_FOLLOWLOCATION => true,
           CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
           CURLOPT_CUSTOMREQUEST => 'POST',
           CURLOPT_POSTFIELDS =>'[
            {
                "toBottom": true,
                "cells": [
                    {
                        "columnId": 3894513397196676,
                        "value": "'.$body.'"
                    },
                    {
                        "columnId": 6797054443317124,
                        "value": "Link",
                        "hyperlink": {
                            "url": "'.$current_url.'"
                        }
                    },
                    {
                        "columnId": 1167554909104004,
                        "value": "Assigned"
                    }
                ]
            }
        ]',
          CURLOPT_HTTPHEADER => array(
            'Authorization: Values',
            'Content-Type: application/json'
          ),
        ));
        $response = curl_exec($curl);

Can you please help us with where I missed the issue?

0

There are 0 best solutions below