We can use REST API below to achieve it.
https://management.azure.com/subscriptions/CustomerSubscriptionID/providers/Microsoft.Authorization/roleAssignments/GUID(need to generated)?api-version=2015-07-01
The following article with step by step for your reference.
How to use REST API to assign CSP subscription roles to new created CSP customer .
More information:
Add or remove role assignments using Azure RBAC and the REST API
Add or remove role assignments using Azure RBAC and Azure PowerShell