1

New to ACS and I simply want to send a SMS message. The official MS example doesn't work. I get a 401 unauthorized error. I have tried to build the client with connection string just like the example and I've tried using the DefaultAzureCredential. Going that direction it causes an unknown error. Does anyone have any advice how to get the ACS SMS SendAsync call to work or let me know what I am doing wrong?

Chris Parker
  • 206
  • 1
  • 9
  • You can refer to [Azure Communication Services – Building an experimental messaging solution](https://abhijitjana.net/2020/12/07/azure-communication-services/) ,[SmsClient.SendAsync Method](https://learn.microsoft.com/en-us/dotnet/api/azure.communication.sms.smsclient.sendasync?view=azure-dotnet) and [How to get and print response from Httpclient.SendAsync call](https://stackoverflow.com/questions/41762947/how-to-get-and-print-response-from-httpclient-sendasync-call) – Ecstasy Dec 20 '21 at 05:05
  • hi @DeepDave-MT. Well written article, however, it did not solve my problem. I have done the exact steps in your article and I get the Unauthorized error. I use the connection string, etc. It doesn't make sense why the simple code doesn't work. At this point I guess I am stuck with Twilio. – Chris Parker Dec 21 '21 at 16:14
  • 1
    A couple of questions: 1) by "The official MS example" you mean [this](https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/sms/send?pivots=programming-language-csharp) 2) Have you registered a phonenumber with `sms:PhoneNumberCapabilityType.Outbound`? 3) Do you use that phonenumber as the ? – rocky Jan 03 '22 at 14:06
  • @rocky 1). Yes. 2). Yes I did. – Chris Parker Jan 04 '22 at 03:00
  • @rocky Your suggestion helped. The example given in the documentation worked once the From number is update to be the same as the registered phone number – Kiran Vedula Feb 16 '22 at 13:56
  • @kiran-vedula I added it as an answer then. – rocky Mar 18 '22 at 13:41

1 Answers1

1

Make sure that the <from-phone-number> is set to a phone number that you've registered earlier with the phone number capability sms:PhoneNumberCapabilityType.Outbound.

var capabilities = new PhoneNumberCapabilities(sms:PhoneNumberCapabilityType.Outbound);

// ... register the phone number and use it in the following code:

SmsSendResult sendResult = smsClient.Send(
    from: "<from-phone-number>",
    to: "<to-phone-number>",
    message: "Hello World via SMS"
);
rocky
  • 7,506
  • 3
  • 33
  • 48