SDKs overview

The Heroku API enables developers to programmatically interact with the Heroku platform, managing applications, add-ons, databases, and other resources. While Heroku itself supports several programming languages for application deployment, its primary official SDK for API interaction is the Heroku Command Line Interface (CLI). The CLI provides a comprehensive set of commands that abstract the underlying HTTP API, offering a streamlined experience for common development and operations tasks. For direct programmatic access within applications, developers often utilize community-maintained libraries that wrap the Heroku Platform API.

The Heroku Platform API is a RESTful API that allows for interactions such as creating and deleting applications, managing dynos, configuring environment variables, and provisioning add-ons. It uses standard HTTP methods and JSON payloads. Authentication for both the CLI and direct API access is typically handled via OAuth 2.0 tokens, which can be generated through the Heroku dashboard or via the CLI itself, ensuring secure access to user accounts and resources.

Official SDKs by language

Heroku's primary official tool for interacting with its API is the Heroku CLI. This command-line interface is language-agnostic, meaning it can be used from any shell environment regardless of the application's programming language. It is developed and maintained by Heroku, providing direct access to platform functionalities. While there are no official SDKs specifically for individual programming languages maintained directly by Heroku, the CLI acts as the de facto official SDK, allowing scripting and automation across various environments.

The Heroku CLI is built on Node.js, but its usage does not require Node.js expertise from the user. It provides a consistent interface for operations such as deploying code, scaling dynos, inspecting logs, and managing databases. Its capabilities extend to managing buildpacks, collaborating with teams, and integrating with third-party add-ons. The CLI's architecture allows for extensibility through plugins, which can be developed by both Heroku and the community to add new commands or customize existing behaviors.

Language/Tool Package/Interface Installation Command Maturity
Language-agnostic (Shell) Heroku CLI brew install heroku/brew/heroku (macOS)
choco install heroku (Windows)
Refer to Heroku CLI installation instructions for other OSes
Official, Stable

Installation

Installing the Heroku CLI is the recommended first step for most developers interacting with the Heroku API. The installation process varies slightly depending on your operating system. Heroku provides detailed instructions for macOS, Windows, and various Linux distributions.

macOS

For macOS users, the most common and recommended method is to use Homebrew:

brew tap heroku/brew
brew install heroku

After installation, you can verify it by running:

heroku --version

Windows

On Windows, you can install the Heroku CLI using the standalone installer or Chocolatey package manager:

Standalone Installer

Download and run the appropriate installer from the Heroku Dev Center.

Chocolatey

choco install heroku

Verify the installation:

heroku --version

Linux

For Debian/Ubuntu-based systems, you can install the CLI using apt:

curl https://cli-assets.heroku.com/install.sh | sh

For other Linux distributions, refer to the official Heroku CLI installation documentation.

Quickstart example

This quickstart example demonstrates how to use the Heroku CLI to deploy a simple Node.js application. This process involves logging in, creating a new Heroku application, deploying code via Git, and opening the application in a browser. This example assumes you have Git installed and have a basic Node.js application (e.g., a simple Express server) in a local directory.

1. Log in to Heroku

Open your terminal and authenticate with your Heroku account:

heroku login

This command will open a web browser to complete the login process. Once authenticated, return to your terminal.

2. Create a new Heroku application

Navigate to your Node.js application's root directory. Then, create a new Heroku application:

cd my-node-app
heroku create my-unique-app-name

Replace my-unique-app-name with a unique name for your application. If you omit the name, Heroku will generate a random one. This command also adds a Git remote named heroku to your local repository.

3. Deploy your application

Deploy your code to Heroku using Git:

git add .
git commit -m "Initial commit"
git push heroku main

Heroku will detect your Node.js application, install dependencies, and build the slug. This process may take a few minutes.

4. Open your application

Once deployment is complete, open your application in your web browser:

heroku open

This command will automatically open the URL of your deployed application.

5. View logs and scale dynos (optional)

To view your application's real-time logs:

heroku logs --tail

To scale your application's web dynos (e.g., to 2 instances):

heroku ps:scale web=2

This quickstart demonstrates the core workflow using the Heroku CLI, which is central to managing applications on the Heroku platform.

Community libraries

While Heroku provides the official CLI for platform interaction, the developer community has created various libraries and wrappers for specific programming languages. These libraries often aim to provide a more idiomatic way to interact with the Heroku Platform API directly within application code, bypassing the need to shell out to the CLI for every operation. They typically handle API authentication, rate limiting, and request/response serialization, simplifying programmatic management of Heroku resources.

Examples of community libraries include:

  • Ruby: The heroku.rb gem is a popular Ruby client for the Heroku API. It provides an object-oriented interface to interact with Heroku applications, add-ons, and other resources. Developers can find its source code and installation instructions on GitHub.
  • Python: Libraries like heroku.py allow Python developers to manage Heroku applications programmatically. These libraries typically mirror the functionality available via the CLI, enabling tasks such as creating apps, setting config variables, and managing dynos from Python scripts. A common client is available on PyPI as heroku3.
  • Node.js: For Node.js environments, several npm packages provide interfaces to the Heroku API. These can be used to build custom automation scripts, integrate Heroku management into CI/CD pipelines, or develop monitoring tools. Popular options can be found by searching the npm registry.

When choosing a community library, it is advisable to check its maintenance status, documentation, and community support. Since these are not officially supported by Heroku, their reliability and feature completeness can vary. However, they offer flexibility for developers who prefer to work within a specific language ecosystem.