Help with creating public API
I'm currently evaluating UNA because our existing platform no longer meets our needs. So far, UNA appears to be a good fit, but there's a crucial feature on our current platform that I'm unsure is available in UNA: the ability to automatically create posts/discussions via public API.
In our current setup, we create content on a separate system and use a cron job to post it to our platform via API . Is there a way to achieve this in UNA? If not, is there any documentation explaining the relationships between entities that need to be populated when creating a post/discussion? This is the main obstacle preventing us from transitioning to UNA.
-
- · Wise
- ·
Hello @Olu Ade 👋
There is an API module. I haven't tackled that one yet, so I have no information outside it is possible. Basically you can access the internal service points using the API. Once you understand how that all works, its easy. It took me a while to wrap my head around service calls (coming from last 10 years of Android development, service calls is a whole different thing 😁). Anyhow..... Here is the stuff to get you started:
https://unacms.com/wiki/Dev-API
And a more in depth breakdown of the calls:
https://ci.una.io/docs/public_api.html
Be advised, API is a pro app: https://unacms.com/view-product/api
-
- · Olu Ade
-
·
In reply to Wise
- ·
@Wise Many thanks for your comments. I'll check the links and see if I can figure this out. I really appreciate your help.
-
- · Justin Ferber
- ·
When you do, I would also appreciate an update on your progress.
-
I haven't made much progress on this. I've gone through the documentation without any luck. I really need this functionality but I'm currently stuck.😢
-
- · Wise
- ·
There needs to be a lot more example scripts. No one knows how to use this stuff, except UNA.
-
-
·
Alex T⚜️
- ·
We've just updated UNA API documentation describing new API functionality how to authenticate with secret key
-
·
Alex T⚜️
-
- · Olu Ade
-
·
In reply to Alex T⚜️
- ·
Thank you for your response. I was able to resolve the issue after addressing a PHP Fatal error: Uncaught Error: Cannot use object of type stdClass as array in /home/ext/sites/una/modules/base/general/classes/BxBaseModGeneralFormsEntryHelper.php:196.
-
Thank you for the feedback, could you please more details on how to reproduce the issue and what is your UNA version ?
-
- · Olu Ade
-
·
In reply to Alex T⚜️
- ·
UNA Version: 14.0.0-A3
When using the curl example on the DEV API page:
An error occurs:
PHP Fatal error: Uncaught Error: Cannot use object of type stdClass as array in /home/ext/sites/una/modules/base/general/classes/BxBaseModGeneralFormsEntryHelper.php:196 Stack trace: #0 /home/ext/sites/una/modules/base/general/classes/BxBaseModGeneralModule.php(1230): BxBaseModGeneralFormsEntryHelper->addData() #1 /home/ext/sites/una/inc/classes/BxDolRequest.php(132): BxBaseModGeneralModule->serviceEntityAdd() #2 /home/ext/sites/una/inc/classes/BxDolRequest.php(57): BxDolRequest::_perform() #3 /home/ext/sites/una/inc/classes/BxDolService.php(51): BxDolRequest::processAsService() #4 /home/ext/sites/una/api.php(72): BxDolService::call() #5 {main} thrown in /home/ext/sites/una/modules/base/general/classes/BxBaseModGeneralFormsEntryHelper.php on line 196
Temporary Fix:
To resolve this issue, check for the type of the
$aValues
variable passed to theaddData
method. If it is not an array, cast it to an array.In
/home/ext/sites/una/modules/base/general/classes/BxBaseModGeneralFormsEntryHelper.php
, modify theaddData
method as follows:public function addData($iProfile, $aValues, $sDisplay = false) { if (!is_array($aValues)) { $aValues = (array) $aValues; } // Rest of the method implementation }
This modification ensures that
$aValues
is always treated as an array, preventing the fatal error and allowing the method to process the data correctly.