How to delete a record via restapi

How to delete a record in the suitecrm via RestApi…
for Creating , Updating and geting the data I have used set_entry and get_entries methods for delete I have stucked of trying ,
Give the solution for this

To delete record, update record and set field deleted=1.

<?php
require_once 'common_url_function.php';

if ($_SERVER['REQUEST_METHOD'] !== 'DELETE') {
    sendErrorResponse('Invalid request method.');
}

// Read input JSON data from Postman
$rawData = file_get_contents("php://input");
$data = json_decode($rawData, true);

// Check if JSON data is valid
if ($data === null) {
    sendErrorResponse('Invalid JSON data.');
}

// Set session id
$session = $data['session']; // Assuming you have retrieved session id from login call

// Check if record ID is provided
if (!isset($data['record_id'])) {
    sendErrorResponse('Record ID is missing.');
}

// Set module name dynamically from input
$module = $data['module'] ?? ''; // Module name from Postman input

// Initialize entry data with session, module, and record ID
$entryData = [
    'session' => $session,
    'module_name' => $module,
    'name_value_list' => [
        ['name' => 'id', 'value' => $data['record_id']] // Provide the record ID to delete
    ]
];

// Call the delete_entry function to delete the record
$result = restRequest('delete_entry', $entryData); // Corrected function name and argument

// Check if the record deletion was successful
if ($result !== null) {
    sendSuccessResponse($result);
} else {
    sendErrorResponse('Record deletion failed.');
}
?>

this is my update record code how to do for delete here

$entryData = [
    "session" => $session,
    "module_name" => $module,
    "name_value_list" => [
       ['name' => 'id', 'value' => $data['record_id'] ],
       ['name' => 'deleted', 'value' => '1' ],
    ]
];

$result = restRequest('set_entry', $entryData);

Hey Thanks Man @chris001 !!!finally understand this finally works …

1 Like

@Ragavendran Please click “Solution” on the post which solved this.

I have done it…once again Thank yoyu

Hi @chris001

<?php require_once 'common_url_function.php'; // Read input JSON data $rawData = file_get_contents("php://input"); $data = json_decode($rawData, true); // Check if JSON data is valid if ($data === null) { sendErrorResponse('Invalid JSON data.'); exit; // Stop further execution } // Check if session is provided in the decoded JSON data if (!isset($data['session'])) { sendErrorResponse('Session not provided.'); exit; // Stop further execution } $session = $data['session']; // Check if module is provided in the decoded JSON data if (!isset($data['module'])) { sendErrorResponse('Module not provided.'); exit; // Stop further execution } $module = $data['module']; // Check if fields are provided in the decoded JSON data if (!isset($data['fields']) || !is_array($data['fields'])) { sendErrorResponse('Fields not provided or invalid.'); exit; // Stop further execution } $select_fields = $data['fields']; $entryArgs = array( // Session id 'session' => $session, // Module to get_entry_list for 'module_name' => $module, // Order by - unused // 'order_by' => 'name', // Start with the first record 'offset' => 0, // Select fields to retrieve 'select_fields' => $select_fields ); // Make the request to retrieve data $result = restRequest('get_entry_list', $entryArgs); // Send success response with retrieved data sendSuccessResponse($result); ?>

while integrating this code all the get method payload is working normally but not working in the integration …i think the issues with the format .I have sending this as a json format what is wrong with this please do this
{
“session”: “18018nnt8r9fg89t28c5td2ivi”,
“module”: “dem_Demo”,
“fields”: [“id”,
“name”]
}
this is the payload i’m passing
i think the problem is with this one
“fields”: [“id”,
“name”]

kindly please check give the correct solution for this

This is the docs for the get_entry_list method, all parameters are named and described:

select_fields array An array of fields to return. An empty array will return all fields.

How do you pass in array ? to get a particular fields please give the solution with example

Try passing for select_fields value of empty array, see if it returns all fields to you.