Hey David,
This is how you can use the HTTP class provided by the core for your API requests to retrieve the article text:
Replace the placeholders in your code: API-KEY, DOMAIN and ARTICLE-ID
This is how you can use the HTTP class provided by the core for your API requests to retrieve the article text:
Code:
$apiKey = 'API-KEY';$apiUrl = 'https://DOMAIN/api/index.php/v1/content/articles/ARTICLE-ID';$headers = ['X-Joomla-Token' => $apiKey];try { $apiRequest = Joomla\CMS\Http\HttpFactory::getHttp()->get($apiUrl, $headers);} catch (Exception $e) { // Error handling - Log error message}$returnCode = $apiRequest->getStatusCode();if ($returnCode !== 200) { // Error handling - throw Exception() or log error message}$returnBody = $apiRequest->body;if ($returnBody === '') { // Error handling - throw Exception() or log error message}$body = json_decode($returnBody, true, 512, JSON_THROW_ON_ERROR);$articeText = $body['data']['attributes']['text'] ?? '';
Statistics: Posted by Kubik-Rubik — Fri Apr 12, 2024 2:32 pm