I had someone create a PHP script for me and now I can’t get them to respond and I need to make what I believe is a simple change, but I can’t figure it out with my minimal understanding of PHP and the Webflow API. I’m hoping the answer is simple to someone more experienced and willing to help me.
The current script sets a collection item to be archived and also if I have the toggle switch on for the item to mark it as ‘sold’, then it leaves that item alone. What I need instead is to no longer archive but simply delete the collection item. I no longer track if it was ‘sold’ or not and having the item be archived instead of deleted is causing manual work for me and an issue with some functionality. Here’s the current code I believe is relevant and if there’s something I should change to make the CMS collection items simply delete, I’d appreciate some help. Thanks!
function _delete_property($collection, $id)
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.webflow.com/collections/$collection/items/$id",
CURLOPT_HTTPHEADER => array(
"accept-version: 1.0.0",
"Authorization: Bearer " . TOKEN
),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "DELETE"
));
$response = curl_exec($curl);
curl_close($curl);
delete_table('properties', [
'id' => $id
]);
}
function delete_property($collection, $id)
{
$data = webflow_get("https://api.webflow.com/collections/$collection/items/$id");
if (isset($data['items']) && count($data['items']) > 0) {
$property = $data['items'][0];
if ($property['_archived']) {
_delete_property($collection, $id);
return TRUE;
} else {
$statusId = get_id('listing_status', 'Sold');
$property['_archived'] = true;
$property['status'] = $statusId;
unset($property['_id']);
unset($property['_cid']);
unset($property['updated-on']);
unset($property['updated-by']);
unset($property['created-on']);
unset($property['created-by']);
unset($property['published-on']);
unset($property['published-by']);
$params = [
'fields' => $property
];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.webflow.com/collections/$collection/items/$id?live=true",
CURLOPT_HTTPHEADER => array(
"accept-version: 1.0.0",
"Authorization: Bearer " . TOKEN,
"Content-Type: application/json",
),
CURLOPT_POSTFIELDS => json_encode($params),
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_RETURNTRANSFER => true,
));
$response = curl_exec($curl);
curl_close($curl);
$data = json_decode($response, TRUE);
if (!isset($data['_id'])) {
error_log($response);
return FALSE;
}
return TRUE;
}
}
return FALSE;
}