How do I make a phone call using Call Automation REST API with a service principal?

01DT 11 Reputation points
2023-03-30T16:54:40.87+00:00

Hello,

I want to make a phone call using the REST API endpoint here:

https://learn.microsoft.com/en-us/rest/api/communication/callautomation/server-calling/create-call?tabs=HTTP

I am testing in Postman and I have a Service Principal that is granted access to the Azure Communication Services endpoint. I am able to get a bearer token using the Oauth client credentials flow and am able to pass it along to make the API call.

This is my request body:

{
    "source": {
        "identifier": {
            "communicationUser": {
                "id": "{{insertIdHere}}"
            }
        }
    },
    "targets": [
        {
            "kind": "phoneNumber",
            "phoneNumber": {
                "value": "+{{insertPhoneNumberHere}}"
            } 
        }
    ],
    "callbackUri": "{{mycallbackUriHere}}"
}

This is the response body:

{
    "error": {
        "code": "400",
        "message": "Invalid request",
        "details": [
            {
                "message": "Invalid Identifier in request, CommunicationUserIdentifier is required but provided CommunicationUserIdentifier is invalid.",
                "target": "Source.Identifier"
            }
        ]
    }
}

I have an Azure phone number that I have tried to substitute under source.identifer but it yielded the same response as above.

Do I need to create a new identity via https://learn.microsoft.com/en-us/rest/api/communication/communication-identity/create?tabs=HTTP in order to make this API call work even with a service principal?

Azure Communication Services
Azure Communication Services
An Azure communication platform for deploying applications across devices and platforms.
927 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Grmacjon-MSFT 18,641 Reputation points
    2023-04-06T20:59:31.4366667+00:00

    Hi 01DT We're glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer. Issue:  -you attempted to make a phone call using Call Automation REST API with a service principal -you were able to get a bearer token using the Oauth client credentials and it passed to make the API call however you got a 400 "invalid request" error code Solution: -you were able to make a phone call by generating a new identity within your request body [https://learn.microsoft.com/en-us/rest/api/communication/communication-identity/create?tabs=HTTP ] which resolved your issue If you have any other questions or are running into more Azure Communication Service issues, please let us know. Thank you again for your time and patience throughout this issue.    -Grace

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.