Skip to content

Commit 167c14a

Browse files
author
Mr Alexandre ELISÉ
authored
Merge branch 'pe7er-patch-1' into patch-1
2 parents 0a83e58 + d7ee12f commit 167c14a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

docs/general-concept/webservices.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ Description of the webservices concept
99

1010
# Communicate with the Joomla 4.x Web Services API
1111
The communication with Joomla's Web Services API takes place via specified endpoints.
12+
1213
- Joomla's core endpoints: https://docs.joomla.org/J4.x:Joomla_Core_APIs
1314
- A collection of Joomla endpoints to use in Postman: https://github.com/alexandreelise/j4x-api-collection
1415

1516
## Using the Joomla framework
17+
1618
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();
1719
You should be able to follow along because the examples using the Joomla framework will mimic those with cURL.
1820

@@ -202,26 +204,31 @@ The cURL functions needs to be available and enabled in your PHP configuration,
202204

203205
### Define some variables
204206
First we define some variables that we use in all our cURL requests:
207+
205208
- the URL of your Joomla 4.x website and
206209
- 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.
207210

208211

209212

213+
210214
```php
211215
// Before passing the HTTP METHOD to CURL
212216
$curl = curl_init();
217+
213218
$url = 'https://example.org/api/index.php/v1';
214219

215220
// Put your Joomla! Api token in a safe place, for example a password manager or a vault storing secrets
216221
// We should not use environment variables to store secrets.
217222
// Here is why: https://www.trendmicro.com/en_us/research/22/h/analyzing-hidden-danger-of-environment-variables-for-keeping-secrets.html
218223
$token = '';
224+
219225
```
220226

221227
### POST - Create an Article in the Category "Uncategorized" (Category ID = 2)
222228
```php
223229
$categoryId = 2; // Joomla's default "Uncategorized" Category
224230

231+
225232
$data = [
226233
'title' => 'How to add an article to Joomla via the API?',
227234
'alias' => 'how-to-add-article-via-joomla-api',
@@ -265,6 +272,7 @@ echo $response;
265272
```php
266273
$categoryId = 2; // Joomla's default "Uncategorized" Category
267274

275+
268276
// HTTP request headers
269277
$headers = [
270278
'Accept: application/vnd.api+json',
@@ -294,6 +302,7 @@ echo $response;
294302
```php
295303
$articleId = 1; // The Article ID of a specific Article
296304

305+
297306
// HTTP request headers
298307
$headers = [
299308
'Accept: application/vnd.api+json',
@@ -322,6 +331,7 @@ echo $response;
322331
```php
323332
$articleId = 1; // The Article ID of a specific Article
324333

334+
325335
$data = [
326336
'id' => $articleId,
327337
'title' => 'How to add an article via the Joomla 4 API?',
@@ -362,6 +372,7 @@ echo $response;
362372
```php
363373
$articleId = 1; // The Article ID of a specific Article
364374

375+
365376
// HTTP request headers
366377
$headers = [
367378
'Accept: application/vnd.api+json',

0 commit comments

Comments
 (0)