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/>";
}
}
Article created and article deleted
Article created, but upon delete you get: curl result: {"errors":[{"code":500,"title":"Internal server error"}]}
Joomla 4.2.8
PHP 8
Labels |
Added:
No Code Attached Yet
|
Labels |
Added:
?
|
Yes - thanks - have learned that now, and it works.
so let's close the issue
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-03-04 07:54:35 |
Closed_By | ⇒ | alikon |
you cannot delete an article if it is not in "trashed" state
as per #31130 (comment) and #31581