In general, the UI will make POST/GET requests to the REST API. Before you add a role in the UI, can you open browser dev tools and look at the network tab which will show you the exact requests being made. You can use that information to learn how to do it via curl or whatever http client you wish.
Another alternative is to use the awx collection which has modules for adding roles to AWX resources. https://galaxy.ansible.com/awx/awx
You cannot create roles through the UI, you only assign roles
when a workflow template is created, a set of roles (read, execute, etc) will be automatically created for it. You wonβt see those roles created via the API calls, this happens server-side
To get the role IDs, you can just add a user to the role for that workflow template in the UI, and you should set the POST associated with that role. So look for POST/GET when doing the role assignments the UI