I recently had the need to send an SMS programmatically. The reason I wanted to be able to do this si because Microsoft Bookings currently doesn’t send SMS reminders to attendees of a booking outside the US. That means, here in Australia, I needed to add the capability via another SMS integration option.
The most obvious choice, once again, is Power Automate. To handle the SMS component I needed to work with a SMS provider. The one who came to party was Mondotalk.
The first step was to consult the Mondotalk API to discover how to send an SMS using code. Luckily, their documentation contained a handy PowerShell script:
$messagebody1 = @{
id = $id
key = $key
username = $username
password = $password
to = “<phone>”
sender = “<phone>”
msg = “hello world”
replyto = director@ciaops.com
}
$url = <API url>
Invoke-RestMethod -Method POST -Uri $url -Body $messageBody1
In essence you create the body of the API request using an array and then you simply POST that to the API URL. Pretty straightforward and after I worked out all the variables like username, id and key, I had this working.
The key action is HTTP as shown above. It is important to remember that this a ‘premium’ connector and you may need a more advanced license to use this.
Initially, I thought I’d just bung in the parameters into the HTTP action as I have done before and it would be good to go. Not the case as it turned out. Everything I tried came back with a variation of the following error:
{“_meta”:{“status”:”ERROR”},”records”:{“errorCode”:401,”userMessage”:”Must login or provide credentials.”,”devMessage”:”Please provide credentials by either passing in a session token via cookie, or providing password and username via BASIC authentication.”,”more”:null,”applicationCode”:”Unauth:1″}}
In essence, the API is failing to login to my account to send the SMS. The PowerShell worked fine but Power Automate didn’t.
The solution ended up lying with adding a header field to the HTTP action:
Content type: application/x-www-form-urlencoded
and formatting the body with an ‘&’ between the fields i.e:
username=#####&password=*******&to=61######&id=#####&key=<GUID>msg=hello&replyto=director%40ciaops.com&sender=61########
as well as setting the authentication in the HTTP action to None as it was being done in the body of the request.
After all of that, I finally had success. The lesson here is that APIs don’t always want JSON!
I then decided to wrap a Power Virtual Agent bot around the Flow and publish it into a Team to allow users to send SMS directly from Teams. They simply use a key phrase to call the bot and tell it when number to send to. The bot passes those details to the Flow and runs what I had worked out previously
The only change here from the initial on demand Flow was the passing of a variable into the Flow from the bot and creating the body of the API request, also as a variable.
Again, it is important to get the body field in EXACTLY the right format for the API request when it is created.
So, that’s how you connect an SMS API gateway to Power Automate and Power Virtual Agents. The real trick was getting the right format of the API POST request which had to be deduced from the documentation. Hopefully, sharing that process here gives others a shortcut to getting it working in their environments because it took me a LONG time to work it out!
Thanks again to Mondotalk for being kind enough to give me a demo account and assist getting this working.