How to create and share a folder with a group via script using occ or REST?

This concerns Nextcloud version 12.

I have been searching through the documentation and forums but have not found an answer to my question.

Is there a means to create a folder and share it with a group via a script, either using occ or some REST API via curl?

I need to automate the following process (some of the steps are clear how to achieve with occ but not all):

  1. Create a user U.
  2. Create a group G.
  3. Create a folder F owned by user U.
  4. Share the folder F with group G, with read-write privileges.


Did you find this one:

should be compatible with NC12 as well.