Create Custom Role using the api

I need to create dozens of custom roles and assign them to groups.

How can I do this using the API?

Is there a way to use a CSV to do this upload in bulk?

Are you talking about Admin Roles? If so, you can use the /api/v1/iam/roles endpoint to create and manage custom admin roles, including assigning them to users or groups.