No Code Attached Yet ?
avatar rbuelund
rbuelund
3 Mar 2023

Steps to reproduce the issue

Create some article with web API:

`function createarticle($concertname, $imageurl, $concertvenue, $date){
// Enter the path of your Joomla site.
$baseurl = 'https://xxxxxx.dk';
$token = "xxxxxxxxx";
// Content of the Article
$article = new stdClass();
$article->articletext = 'Ap med ' . $concertname . " på " . $concertvenue;
$article->title = $concertname;
$article->catid = 9;
$article->language = '*';
$article->metadesc = 'Ap med ' . $concertname . " på " . $concertvenue;
$article->metakey = 'Ap med ' . $concertname;

$articlecontent = json_encode($article);
$curl = curl_init();
curl_setopt_array($curl, array(
	CURLOPT_URL => $baseurl."/api/index.php/v1/content/articles",
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => "",
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 30,
	CURLOPT_HTTP_VERSION => 'CURL_HTTP_VERSION_2TLS',
	CURLOPT_CUSTOMREQUEST => "POST",
	CURLOPT_POSTFIELDS => $articlecontent,
	CURLOPT_HTTPHEADER => array(
		"Accept: */*",
		"Accept-Encoding: gzip, deflate",
		sprintf('X-Joomla-Token: %s', trim($token)),
		"Cache-Control: no-cache",
		"Connection: keep-alive",
		"Content-Length: ".strlen($articlecontent),
		"Content-Type: application/json",
		"cache-control: no-cache"
	),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
	echo "cURL Error #:" . $err;
} else {
	$concertobject = json_decode($response);
	var_dump($concertobject);
	echo "<br/><br/>";
}

}`

Delete article with web API by ID

function delete_article($articleid){
	// Enter the path of your Joomla site.
	$baseurl = 'https://xxxxxx.dk';
	$token = "xxxxxxxxxx";
	$curl = curl_init();
	curl_setopt_array($curl, array(
		CURLOPT_URL => $baseurl."/api/index.php/v1/content/articles/" . $articleid,
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_ENCODING => "utf-8",
		CURLOPT_MAXREDIRS => 10,
		CURLOPT_TIMEOUT => 30,
		CURLOPT_HTTP_VERSION => "CURL_HTTP_VERSION_2TLS",
		CURLOPT_CUSTOMREQUEST => "DELETE",
		CURLOPT_POSTFIELDS => '',
		CURLOPT_HTTPHEADER => array(
			"Accept: application/vnd.api+json",
			"Accept-Encoding: gzip, deflate",
			sprintf('X-Joomla-Token: %s', trim($token)),
			"Cache-Control: no-cache",
			"Connection: keep-alive",
			"Content-Type: application/json",
			"cache-control: no-cache"
		),
	));

	$response = curl_exec($curl);
	$err = curl_error($curl);
	curl_close($curl);

	if ($err) {
		echo "cURL Error #:" . $err;
	} else {
		echo "Article deleted";
		print_r($response);
		echo "<br/><br/>";
	}
}

Expected result

Article created and article deleted

Actual result

Article created, but upon delete you get: curl result: {"errors":[{"code":500,"title":"Internal server error"}]}

System information (as much as possible)

Joomla 4.2.8
PHP 8

Additional comments

avatar rbuelund rbuelund - open - 3 Mar 2023
avatar joomla-cms-bot joomla-cms-bot - change - 3 Mar 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 3 Mar 2023
avatar rbuelund rbuelund - change - 3 Mar 2023
The description was changed
avatar rbuelund rbuelund - edited - 3 Mar 2023
avatar rbuelund rbuelund - change - 3 Mar 2023
The description was changed
avatar rbuelund rbuelund - edited - 3 Mar 2023
avatar alikon alikon - change - 3 Mar 2023
Labels Added: ?
avatar alikon alikon - labeled - 3 Mar 2023
avatar alikon
alikon - comment - 4 Mar 2023

you cannot delete an article if it is not in "trashed" state
as per #31130 (comment) and #31581

avatar rbuelund
rbuelund - comment - 4 Mar 2023

Yes - thanks - have learned that now, and it works.

avatar alikon alikon - close - 4 Mar 2023
avatar alikon
alikon - comment - 4 Mar 2023

so let's close the issue

avatar alikon alikon - change - 4 Mar 2023
Status New Closed
Closed_Date 0000-00-00 00:00:00 2023-03-04 07:54:35
Closed_By alikon

Add a Comment

Login with GitHub to post a comment