Well I was able to create new entries but couldnt find out how do UPDATE existing entries. The code above only creates new ones. Does anyone have a clue how to do that? And is it even possible to update singletons from frontend?
Ah, and is there a way to contribute to the documentation? Like help them creating better updated docs?
The only difference in usage between update and insert is the fact that you pass an ID along or not.
If you post with the “_id” field set in your data, cockpit will update the data determined by the id you gave; if you post without the “_id” field cockpit will create a fresh new entry.
Thank you very much for your reply! Will try it as soon I can. Is there a way to update singletons as well from frontend? I do not see like /singletons/save in the api.
And thanks for the link with the git for the docs.
There is an error in @raffaelj’s, but otherwise is correct.
The php file singletonname.php should be in config/api/singletons/save/singletonname.php, which would then create an endpoint to save to Singleton “singletonname” at https://url.to/cockpit/api/singletons/save/singletonname?token=xxtokenxx
The API endpoint won’t work when not in api folder.
Equally, one could also put singletonname.php in config/api/singletonname.php and then POST data to https://url.to/cockpit/api/singletonname?token=xxtokenxx.
Hello there. I want to save singleton data via API, using only the API key without user credentials, but I can’t quite get this to work. When I POST a JSON body to my singleton save endpoint /api/singletons/save/prepared_spells?token=xyz (created as described in raffaelj’s answer) I get a response with code 302 Found but no body:
The header response Location: /auth/login?to=/api/singletons/save/prepared_spells makes me believe it wants a user auth, but I would like this particular singleton to be updateable without user credentials, with only an API token.
Any pointers on what I need to adjust to get this to work would be appreciated.
{"error":"Call to a member function isResourceEditableByCurrentUser() on
null","file":"\/var\/www\/html\/modules\/Singletons\/Controller\/Admin.php","line":157}