I would expect there to be an option to create new BAW groups via the REST API, but it doesn't appear that there is a way to do this according to the docs:
https://www.ibm.com/docs/en/baw/24.x?topic=resources-group
However, you definitely can create new groups via the JSAPI:
https://www.ibm.com/docs/en/baw/24.x?topic=apis-javascript-api-in-processes-cases-service-flows#OrgNamespace - see createRole()
And you can add members - users or nested roles - to the TWRole:
https://www.ibm.com/docs/en/baw/24.x?topic=apis-javascript-api-in-processes-cases-service-flows#TWRole
Therefore, you could build a utility - dashboard or startable service - which compiles all of the roles (and members, if needed) and outputs it as JSON such as:
[
{
roleName: "role1",
userMembers: ["user1","user2"],
roleMembers: ["role2","role3"],
},
{
roleName: "role5",
userMembers: ["user6","user7"],
roleMembers: ["role8","role9"],
....
}
]
Then run the utility in the source environment to obtain all of the role definitions.
Next create another utility that can iterate through the JSON and create the associated roles, and populate with members and run this in the target environment:
roleDefinitionJson.forEach(function(role) {
var newRole = tw.system.org.createRole(role);
newRole.addUsers(role.userMembers);
newRole.addRoles(role.roleMembers);
});
Something like that should get you started.