my app registration object id as principal id
Roles are not assigned to app registrations. The error message is really confusing though if this is the reason.
Anyway, you need to use the object ID of the service principal connected to the app registration. Either find it in the Enterprise applications list or click "Managed application in local directory" on the app registration.
To summarize, this is what you need:
POST /servicePrincipals/{id}/appRoleAssignedTo
Here {id} is the object ID of the service principal where the role is defined.
Then the parameters:
- resourceId: Same object ID as in URL
- principalId: Object ID of service principal the role should be granted to (what I described earlier)
- appRoleId: Id of the role to grant
Even though roles are not assigned to app registrations, in this case since you do have an app registration, it would be good to also add the role as a required permission on that app registration for documentation's sake.
You can do that with an update to the application object:
{
"requiredResourceAccess": [
{
"resourceAppId": "the-resourceId-value-from-before",
"resourceAccess": {
"id": "the-appRoleid-from-before",
"type": "Role"
}
}
]
}
API doc: https://learn.microsoft.com/en-us/graph/api/application-update?view=graph-rest-1.0&tabs=http