How to identify which URL to POST?

Hi everyone!

I want to send an Add member request in Azure AD to either a Group or a Directory Role. How can I send a call that is able to identify whether the request is for a group or a directory role? I got the parameters for a group and directory role respectively from the Azure documentation below

POST https://graph.microsoft.com/v1.0/groups/{group-id}/members/$ref

Content-type: application/json

{
@odata.id”: “https://graph.microsoft.com/v1.0/directoryObjects/{id}
}

POST https://graph.microsoft.com/v1.0/directoryRoles/{Directory-id}/members/$ref

Content-type: application/json

{
@odata.id”: “https://graph.microsoft.com/v1.0/directoryObjects/{id}
}