I've just recently released a knowledge base site that makes heavy use of keywords, to identify machinery being maintained.
The users were interested in having new machinery keywords created in the Plone site as soon as another process generated a new machine number.
I created a regular page (e.g., with ID new-keywords-page) and a REST API call is made to set the page's keywords.
The side effect of setting the page's (or any content item's) keywords is that Plone will create the keyword if it doesn't already exist.
I created a new user, e.g., keywordadder
I used the management interface's Security tab, created a new role REST API User, and assigned the plone.restapi: Use REST API permission to that new role.
I assigned the new role to the new user.
This command sets the keyword on the page. (The -k flag tells curl to ignore SSL certificate errors).
curl -k -i -X PATCH -u 'keywordadder:password' -H “Accept: application/json” -H “Content-Type: application/json” -d '{“subjects”:[“9999”]}' https://site.local/new-keywords-page
This command lists the keywords on that page (you can point it to any content item, to see the keywords on that item):
curl -k -s -u 'keywordadder:password' -H “Accept: application/json” https://site.local/new-keywords-page | jq .subjects
The response should look like this:
[
"9999"
]
You can set multiple keywords in one command:
curl -k -i -X PATCH -u 'keywordadder:password' -H “Accept: application/json” -H “Content-Type: application/json” -d '{“subjects”:[“9999”, “1234”]}' https://site.local/new-keywords-page
When you query a content item's keywords, this is what it will look like if there is more than one keyword:
curl -k -s -u 'keywordadder:password' -H “Accept: application/json” https://site.local/new-keywords-page | jq .subjects
[
"9999",
"1234"
]