Some APIs require your IP to be whitelisted beforehand for security reasons. However, due to the way Heroku works, it is impossible to get a static IP address from Heroku, and you won’t be able to whitelist anything. Which means no access to the API. It was our case for some API at Okarito, and we had to figure out a solution.
Meet QuotaGuard, a Heroku addon that provides you with 2 static IP addresses that you can use for your whitelisted API calls.
As soon as you add the plugin to your current app, it automatically adds a config variable named QUOTAGUARDSTATIC_URL. Click on the QuotaGuard Static addon to arrive on your dashboard, and discover the 2 static IP addresses that have been created for you.
Follow the instructions on http://support.quotaguard.com/support/solutions/articles/5000013940-getting-started-with-the-httparty-gem-quotaguard-static and use these IP addresses for the first time!
However, even though this setup works great for simple GET requests, I didn’t find anything working with HTTParty POST requests, and I had to find a small hack to make it work.
Create a file called httproxy.rb in your initializers folder.
In this file, create the HTTProxy class, that will use the QuotaGuard params when in production (you don’t want to waste money by using their service for development purposes).
Restart your server.
You were using HTTParty to make API calls, you will now be able to use HTTProxy, which will use your QuotaGuard static IPs. It will behave exactly like HTTParty (it includes it), but will ensure your static IP will be used.
Now, back to code 💪
(Disclaimer: I am not related to QuotaGuard, that I discovered today. I chose them because they were the only static IP Heroku addon available in Europe).