This past Summer, I was the Product Management Intern and had the purpose of improving Bandwidth’s API documentation. To find areas of improvement I was asked to make a simple Java app that could:
Now experience wise, I had never implemented an API nor had I used Java to create a web app. Hopefully my experience and choices while not objectively the best, can help anyone get started with Bandwidth’s API.
- Follow Heroku’s Getting Started tutorial for Java and just alter the files they create for you in the tutorial
- Add Spark and Bandwidth SDK dependencies to their POM file
- Follow Spark Beginner video tutorials to make endpoints and front end (tutorials use freemarker and show how to set up)
- Code in whatever functions you would like with the help of the Bandwidth SDK
1) Download and Install Maven
Instructions on how to do this step, found here, was fairly straightforward if you know how to add path variables.
Your bash_profile should look something like this:
2) Follow Heroku’s Getting Started tutorial for Java and just alter the files they create for you in the tutorial.
Copying word for word the terminal entries is much easier and less susceptible to mistakes. Plus you will know that the app has the ability to deploy to Heroku, which is a great service for hosting applications. All that is left after that is making the app and the webpage itself.
3) Add Spark and Bandwidth SDK dependencies to their POM file
The Heroku getting started app will already have a POM.xml file that you will just need to add the Spark and Java Bandwidth SDK dependencies. Given the small stature of the app, the Spark micro framework was perfect. If you are looking for something more robust, then you might want to use the Spring framework.
The main dependencies you’ll need are:
4) Follow Spark Beginner video tutorials to make endpoints and front end (tutorials use freemarker and show how to set up)
Spark’s video tutorials are very useful for showing how to make endpoints and how to use the freemarker engine to make templates and forms.
Your basic endpoint in java will look similar to this:
While the .ftl files will look like:
The video tutorials also provide text to accompany them. The text is more of a compliment to the videos as opposed to being a straight transcription of the video.
The convenient perk of freemarker is the ability to create a layout with the a standard header and body that all other pages can fit inside of, giving a uniformity throughout the application.
5) Code in whatever functions you would like with the help of the Bandwidth SDK.
For authenticating, sending SMS, and creating calls:
This can be whatever you want. Some notes though, if you utilize any BXML, you have to make a GET request. Also, any callback events (i.e. Answer Event), you’ll need to set the callback URL also in the Bandwidth API developer console.
Handling a callback event (ex. What happens when the person answers the call):
Now if you’re like me, then you’ll most likely have to do a lot of debugging. The Bandwidth API developer console has some error logs in their developer console, but what was even more useful to me was the Heroku logs. Every println appears in the Heroku logs, which is one of the best ways for me to debug. This method helps me see and understand the data that’s being passed between endpoints and methods.
Again, none of this is necessarily the best way to get the results, but that’s how you learn. Also try the version with voicemail! (transcription still in beta)