Where are examples of using the VoIP.ms API

Does anyone here have experience with the VoIP.ms API, specifically with Python?

Here’s an example of how you could send an SMS using the voip.ms API with Python.

In a production environment I import my credentials using a .env file and the python-dotenv module.

The code is a little rough but it’s a starting point.

import requests

class VoipMS:
    def __init__(self, username: str, password: str):
        self.params: dict[str, str] = {
            "api_username": username,
            "api_password": password
        self.url = "https://voip.ms/api/v1/rest.php"

    def send_sms(self, did: str, destination: str, message: str) -> requests.Response:
        """Send an sms.

        did : str
            Your SMS enabled VoipMS DID.

        destination : str
            The number you want to send an SMS to.

        message : str
            The body of your SMS message (max chars: 160)
        _params: dict[str, str] = {
            "method": "sendSMS",
            "did": did,
            "dst": destination,
            "message": message
        return requests.get(self.url, params=self.params)

def main(voipms: VoipMS):
    message = "Hello World"
    response = voipms.send_sms(did="1231231234", destination="3213213210", message=message)

if __name__ == "__main__":
    main(VoipMS("[email protected]", "APIpassword"))
1 Like

What is requests module?


1 Like

See the documentation provided by dicko. Requests is one of the most downloaded Python packages. It is used to make API requests.

Yes. I have used it but a long time ago.

Then in case you forgot this also . . .

Never used it. Most stuff I’ve done in python has been with boto3 with the AWS cli or geocoding modules.

It looks useful

When I try to use my number as the destination, ít says it’s invalid. 8054676070. Still investigating it authenticates okay and it accepts the did I put in which is the same as the destination. I tried another destination too and it still wouldn’t accept it

Two things to check:

The number you pass in the did parameter needs to be a voipms did and needs to have sms enabled.

In the API section of your voipms portal, you need to make sure to whitelist the IP address that you’re running the Python script from.

If those things are ok and it still doesn’t work, you should open up a ticket with voipms.

The DID is fine. It is saying the destination is invalid

They won’t support python

The problem was the destination was the same as the DID, which is not allowed

Thanks for your help. This gets me started

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.