Skip to content

Commit

Permalink
Merge branch 'pe7er-patch-1' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr Alexandre ELISÉ authored Dec 6, 2022
2 parents 0a83e58 + d7ee12f commit 167c14a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/general-concept/webservices.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -265,6 +272,7 @@ echo $response;
```php
$categoryId = 2; // Joomla's default "Uncategorized" Category


// HTTP request headers
$headers = [
'Accept: application/vnd.api+json',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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?',
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 167c14a

Please sign in to comment.