What is Basic Auth about?
When talking to a service over the internet it is sometimes needed to let the service know who you are. That is why you sometimes need to identify yourself with a username and a password. HTTP Basic Auth is one way to do this.
How to use Basic Auth.
The 46elks API uses Basic Auth to know who is using it to send and receive SMS etc. To get your 46elks username and a password you need to create an account. When you have done that you will find your “API Username” and “API password” in the dashboard.
The username and password should be used for every API request using Basic Authentication. That way 46elks knows who you are and what you are allowed to do (like sending an SMS from your phone number).
One way to do this is to include username and password in the URL when you are sending an API request:
Try the link above with your username and password and you’ll see that 46elks know who you are.
Authorization HTTP Header
Including your username and password in the URL is one of the easiest ways to use Basic Auth, but a more common way is to set username and password in the Authorization HTTP header. This is done by Base64 encoding username:password and setting the Authorization HTTP Header to Basic theBase64EncodedString.
For example the username 46elks with password secretPassword would mean that the string 46elks:secretPassword needs to be Base64 encoded which results in NDZlbGtzOnNlY3JldFBhc3N3b3Jk. In each request to the 46elks API you would then need to set the Authorization HTTP Header to the value:
Most HTTP libraries in most programming languages handle this for you. So all you need to do is specify username, password and that Basic Auth is used and the library will take care of the rest.
To start using Basic Auth in your programming langugage you can take a look at the many code examples on github and read the tutorials on how to talk to the 46elks API. Take a look at the documentation to see how to make a request to the api to send an SMS, or trigger a phone call.