Dear Peter-san,
>How did you try to access Joomla's API?
>Via command line (CURL), via a PHP script or using Postman?
Thank you for your reply.
I followed the guidance below and created the following PHP script
guidance:
https://slides.woluweb.be/api/api.html# ... ost-script
PHP script:
-----------------------------------------------------------
<?php
// Before passing the HTTP METHOD to CURL
$curl = curl_init();
$url = 'https://roboblo.com/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/resear ... crets.html
$token = 'c2hhMjU2OjQxNjpmYjJiYzY5NDk3YzlhNzExZjUxZDExNjY0NjczMWMxNGRkYWRmYWRmMjEwMGQ2OWQ0NTQwMjJjYmY3N2YwYjAx';
$categoryId = 11; // 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',
'articletext' => 'I have no idea...',
'catid' => $categoryId,
'language' => '*',
'metadesc' => '',
'metakey' => '',
];
$dataString = json_encode($data);
// HTTP request headers
$headers = [
'Accept: application/vnd.api+json',
'Content-Type: application/json',
'Content-Length: ' . mb_strlen($dataString),
sprintf('X-Joomla-Token: %s', trim($token)),
];
curl_setopt_array($curl, [
CURLOPT_URL => sprintf('%s/%s',$url,'content/articles'),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => 'utf-8',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2TLS,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $dataString,
CURLOPT_HTTPHEADER => $headers,
]
);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
-----------------------------------------------------------
>Do you get anything back when you try to access the API?
Although I am not a technical person, I also tried Postman according to the manual.
The results were the same as the error displayed at the following URL.
1. URL:
https://roboblo.com/api-post.php
{"errors":[{"code":500,"title":"Internal server error"}]}
2. Postman:
{
"errors": [
{
"code": 500,
"title": "Internal server error"
}
]
}
Best Regards,
dg78
>How did you try to access Joomla's API?
>Via command line (CURL), via a PHP script or using Postman?
Thank you for your reply.
I followed the guidance below and created the following PHP script
guidance:
https://slides.woluweb.be/api/api.html# ... ost-script
PHP script:
-----------------------------------------------------------
<?php
// Before passing the HTTP METHOD to CURL
$curl = curl_init();
$url = 'https://roboblo.com/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/resear ... crets.html
$token = 'c2hhMjU2OjQxNjpmYjJiYzY5NDk3YzlhNzExZjUxZDExNjY0NjczMWMxNGRkYWRmYWRmMjEwMGQ2OWQ0NTQwMjJjYmY3N2YwYjAx';
$categoryId = 11; // 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',
'articletext' => 'I have no idea...',
'catid' => $categoryId,
'language' => '*',
'metadesc' => '',
'metakey' => '',
];
$dataString = json_encode($data);
// HTTP request headers
$headers = [
'Accept: application/vnd.api+json',
'Content-Type: application/json',
'Content-Length: ' . mb_strlen($dataString),
sprintf('X-Joomla-Token: %s', trim($token)),
];
curl_setopt_array($curl, [
CURLOPT_URL => sprintf('%s/%s',$url,'content/articles'),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => 'utf-8',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2TLS,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $dataString,
CURLOPT_HTTPHEADER => $headers,
]
);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
-----------------------------------------------------------
>Do you get anything back when you try to access the API?
Although I am not a technical person, I also tried Postman according to the manual.
The results were the same as the error displayed at the following URL.
1. URL:
https://roboblo.com/api-post.php
{"errors":[{"code":500,"title":"Internal server error"}]}
2. Postman:
{
"errors": [
{
"code": 500,
"title": "Internal server error"
}
]
}
Best Regards,
dg78
Statistics: Posted by dg78 — Thu Mar 28, 2024 11:53 am