API Integration
Devin can integrate, configure, and test third party APIs in your applications.
Integrating SendGrid into an Application
Our sample application is an online educational platform written with the Django Python web framework. A PR was recently opened to integrate the SendGrid email API into the application, and in this tutorial we’re going to have Devin attempt its own SendGrid implementation to showcase how it can work with third party APIs.
In our prompt, we provide some specific instructions about how and where we want Devin to integrate our SendGrid hooks, and we have Devin revert to an earlier commit hash before the above PR was merged, to give us a clean starting point for our integration. Follow along with the live Devin session here.
Devin investigates the codebase and ensures that there’s no conflicting email implementation that already exists in the application.
It then moves on to implementing the SendGrid API, and prompts us for our API credentials which we can set up as Secrets in Devin’s environment so that it may access them going forward as ENV variables.
Now that it has proper API credentials, Devin finishes implementing SendGrid.
When I compare Devin’s SendGrid implementation to the actual merged PR we linked at the beginning, there are a few notable improvements I observe:
- Devin configured SendGrid in a new email.py module rather than in the same file as the view itself. It also returns True or False to indicate whether the email sending was successful based on the SendGrid response code.
- Devin uses Python’s built-in logging module rather than print (which was a pattern that the PR reviewer specifically commented on).
- Devin also makes the From email configurable rather than hardcoded, but also adds a default value if the ENV var does not exist.
- Devin adds exception handling to its mailInstructor method.
With its core implementation is finished, I can ask Devin to test the application by adding an instructor account under my email address. To test the application, it will also need to go through and install and configure all of the dependencies like a PostgreSQL server and relevant Python libraries.
Devin quickly encounters an error, which is because I never provided it with a FROM address for my SendGrid account. Devin actually navigates in its Browser to the API docs to figure out what is going on here and understand the error messages and implementation best practices:
I can go back into the Secrets dialog and add a SENDGRID_FROM_EMAIL variable for Devin to access.
I also instruct Devin to use the default SendGrid username ‘apikey’ since I have not set up a subaccount for the API:
Devin observes that my requests and implementation requirements may be generalizable, and prompts me to add Knowledge that it can utilize in the future:
If you so choose, you could also edit the Knowledge to add even more specifics if these tactics will be useful in future sessions that your team plans to run.
After a few minutes of environment configuration and setup, Devin finishes its successful session and I see the email in my inbox. I did not actually configure the SendGrid template to have real content in it, but the API request works and so Devin’s work is done!
If I choose to submit a PR, Devin has already drafted the message for me including details of everything it changed in the application and how it works:
Sign up today to try out Devin and tackle an API integration that’s burning a hole in your team’s backlog.