Delete folder using php cURL

Hi,

I am trying to delete a folder using the API, with a PHP cURL DELETE request but I never succeed.
Here are the two versions of the methods I am trying to use but none of them works. I always get a 404 Error.

public function deleteFolder($folderUid) {

$ch = curl_init('http://admin:password@172.0.0.1:3000/api/folders/');

$postFields = array(
	'uid' => $grafanaFolderUId
);

curl_setopt_array($ch, array(
	CURLOPT_CUSTOMREQUEST => 'DELETE',
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_HTTPHEADER => array(
		'Content-Type: application/json'
	),
    CURLOPT_POSTFIELDS => json_encode($postFields)
));

$response = curl_exec($ch);
// Decode the response
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo $httpCode;

}

public function deleteFolder($folderUid) {

$ch = curl_init('http://admin:password@172.0.0.1:3000/api/folders/' . $folderUid);

curl_setopt_array($ch, array(
	CURLOPT_CUSTOMREQUEST => 'DELETE',
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_HTTPHEADER => array(
		'Content-Type: application/json'
	),
));

$response = curl_exec($ch);
// Decode the response
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo $httpCode;

}

Can someone please tell me what am I doing wrong?

I am using Version 5.4.2 .

Hi, Can you explain how make call in Grafana? This 404 happens where (URL)? In develops tools of browser can you see request?

In $ch = curl_init(‘http://admin:password@172.0.0.1:3000/api/folders/’); remove ’ before @

The 404 Code ist the code I get from the cUrl response code that means that the folder wasn’t found.

In develops tools the call to grafana is not visible. I call grafana from a server php method.

The ’ before @ was a mistype for this post. :slight_smile:

DELETE /api/folders/:uid

Try:

$ch = curl_init('http://admin:password@172.0.0.1:3000/api/folders/:' . $folderUid);

Or submit with ajax:
//Post com Ajax
function method_ajax() {
const url = ‘http://admin:password@172.0.0.1:3000/api/folders/’;

$.ajax({
	url: url, //Submit
	data: { uid: uid.value }, //Parametros
	type: 'DELETE',

success: function(response){
	//Ok
  	setTimeout(function(){
    //Espera de 2 segundos
		alert(response);
		//window.location.reload();
		}, 2000);
},
  error: function(response) {
    alert("Erro identificado");
  }

});
}

Thanks, but I don’t want to use javascript on this matter.