diff --git a/docs/general-concept/webservices.md b/docs/general-concept/webservices.md index 6a538c00..4184976c 100644 --- a/docs/general-concept/webservices.md +++ b/docs/general-concept/webservices.md @@ -9,10 +9,12 @@ Description of the webservices concept # Communicate with the Joomla 4.x Web Services API The communication with Joomla's Web Services API takes place via specified endpoints. + - Joomla's core endpoints: https://docs.joomla.org/J4.x:Joomla_Core_APIs - A collection of Joomla endpoints to use in Postman: https://github.com/alexandreelise/j4x-api-collection ## Using the Joomla framework + More often than not, when using the Joomla framework, under the hood it still uses cURL or php streams. Most of the cURL is available with your web hosting provider. Otherwise check phpinfo(); You should be able to follow along because the examples using the Joomla framework will mimic those with cURL. @@ -202,26 +204,31 @@ The cURL functions needs to be available and enabled in your PHP configuration, ### Define some variables First we define some variables that we use in all our cURL requests: + - the URL of your Joomla 4.x website and - the Joomla's API Token of a Super User account or an account which has at least core.login.api permission and core.login.site to be able to see change current logged-in user's token. + ```php // Before passing the HTTP METHOD to CURL $curl = curl_init(); + $url = 'https://example.org/api/index.php/v1'; // Put your Joomla! Api token in a safe place, for example a password manager or a vault storing secrets // We should not use environment variables to store secrets. // Here is why: https://www.trendmicro.com/en_us/research/22/h/analyzing-hidden-danger-of-environment-variables-for-keeping-secrets.html $token = ''; + ``` ### POST - Create an Article in the Category "Uncategorized" (Category ID = 2) ```php $categoryId = 2; // Joomla's default "Uncategorized" Category + $data = [ 'title' => 'How to add an article to Joomla via the API?', 'alias' => 'how-to-add-article-via-joomla-api', @@ -265,6 +272,7 @@ echo $response; ```php $categoryId = 2; // Joomla's default "Uncategorized" Category + // HTTP request headers $headers = [ 'Accept: application/vnd.api+json', @@ -294,6 +302,7 @@ echo $response; ```php $articleId = 1; // The Article ID of a specific Article + // HTTP request headers $headers = [ 'Accept: application/vnd.api+json', @@ -322,6 +331,7 @@ echo $response; ```php $articleId = 1; // The Article ID of a specific Article + $data = [ 'id' => $articleId, 'title' => 'How to add an article via the Joomla 4 API?', @@ -362,6 +372,7 @@ echo $response; ```php $articleId = 1; // The Article ID of a specific Article + // HTTP request headers $headers = [ 'Accept: application/vnd.api+json',