Created
November 11, 2019 04:11
-
-
Save chetanmadaan/9db31e89cac239722d9fb24a65c8cffb to your computer and use it in GitHub Desktop.
Create article via Joomla 4 API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Enter the path of your Joomla site. | |
$baseurl = 'http://localhost/j4a12'; | |
// Joomla Super Admin Credentials | |
$user = 'admin'; | |
$pass = 'admin'; | |
// Content of the Article | |
$article = new stdClass(); | |
$article->articletext = 'My text goes here and there'; | |
$article->title = 'Article Title Goes here'; | |
$article->catid = 8; | |
$article->language = '*'; | |
$article->metadesc = ''; | |
$article->metakey = ''; | |
$articlecontent = json_encode($article); | |
$curl = curl_init(); | |
curl_setopt_array($curl, array( | |
CURLOPT_URL => $baseurl."/api/index.php/v1/content/article", | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_ENCODING => "", | |
CURLOPT_MAXREDIRS => 10, | |
CURLOPT_TIMEOUT => 30, | |
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | |
CURLOPT_CUSTOMREQUEST => "POST", | |
CURLOPT_POSTFIELDS => $articlecontent, | |
CURLOPT_HTTPHEADER => array( | |
"Accept: */*", | |
"Accept-Encoding: gzip, deflate", | |
"Authorization: Basic ".base64_encode($user.':'.$pass), | |
"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 { | |
echo $response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment