Support

Send SMS with Python - 3 Simple Steps to Get Started with 46elks

If you know how to program in Python you can send text messages with 46elks. Just follow these three simple steps to get started and in a few minutes you will receive an SMS that you have sent from Python.

1. Create a user

To send an SMS with 46elks you first have to create an account. Go to the registration page and fill in your details. You will then receive an automatic phone call to verify your new account.

To start using 46elks to send a text messages you will need to purchase some credits. The minimum purchase is 10 EUR, which is more than enough to get started.

2. Username and password

Once you have an account it’s time to login to the 46elks dashboard. This is where you can see all your important account information - like the username and password you need to send an SMS.

Tip: Click on the blurred text under API password to see your own password.

Every time you do something with 46elks, like sending an SMS, you have to provide your username and password via Basic HTTP Authentication. When you are using Python you need to set Basic Authentication username and password in the Authorization HTTP Header (see the code examples below).

3. Send an SMS

Finally, it’s time to write some Python. Your code needs to be able to do the following:

Define the content of the SMS, who will receive it and who is the sender

Set your username and password

Send all this information to 46elks by an HTTP POST to https://api.46elks.com/a1/SMS

Receive the response and handle any errors that might occur

There are many ways to implement this in Python. Here are examples of how it can be done with the Requests library (for Python 2 & 3), with Python 2.x or Python 3.x (both without any extra libraries).

Tip: The phone number to send to should be formatted with country code and without spaces, dashes or parentheses. For example +468123123 and not 08-123123 or +46 (8) 123 123.

Use the Python example by creating a send.py file, copy/paste the example code above to the file, add your username, password and phone number to the code. Then execute it by using the command python send.py and your phone will buzz. Congratulations, you’ve just sent an SMS from Python.

Next step

You’ve just sent a text message with a text sender (i.e. not from a phone number). By doing this you can use SMS to remind customers of reservations, send confirmations of new orders, etc.