Back

Heroku API Essential Guide

Aug 7, 20246 minute read

What type of API does Heroku provide?

Heroku primarily uses a REST API, but also supports GraphQL APIs. The key points are:

  1. Heroku's main Platform API is a REST API. The documentation refers to it as the "platform API" and provides details on how to make REST requests to api.heroku.com endpoints.

  2. Heroku also supports building and deploying GraphQL APIs. There are examples and tutorials showing how to create GraphQL APIs on Heroku using Node.js and other technologies.

  3. The REST API is Heroku's core API for programmatically managing Heroku resources like apps, add-ons, etc. It uses JSON for data exchange and follows REST principles.

  4. For GraphQL, Heroku provides the ability to host and run GraphQL servers, but this is more for developers building their own APIs on top of Heroku, rather than Heroku's core API itself.

  5. There is no mention of SOAP APIs in the context of Heroku's official APIs.

In summary, while Heroku's primary API is REST-based, they also support developers building and deploying GraphQL APIs on their platform. The core Heroku Platform API uses REST, but GraphQL can be used for custom APIs built on Heroku.

Does the Heroku API have webhooks?

Yes, the official Heroku API does have webhooks. Here are the key points about Heroku webhooks:

Webhook Availability

Heroku offers app webhooks that enable you to receive notifications when particular changes are made to your Heroku app.

Event Types

You can subscribe to notifications for a wide variety of events, including:

  • Changes to domain settings
  • App builds
  • App releases
  • Add-on changes
  • Dyno formation changes
  • App details (e.g., app name changes)

How to Subscribe

You can subscribe to webhooks in several ways:

  1. Using the Heroku Dashboard
  2. Using the Heroku CLI
  3. Using the webhooks API

For example, using the CLI:

heroku webhooks:add -i api:release -l notify -u https://example.com/hooks -a your-app

Webhook Delivery

Webhook notifications are sent as HTTP POST requests to a URL of your choosing. The webhook payload contains detailed information about the event that occurred.

Security and Reliability

  • Webhooks can be set to "sync" level, where Heroku will automatically retry delivery of failed webhook events.
  • You can verify that the messages you receive were made by Heroku and that the information was not modified.

Best Practices

  1. Implement a server endpoint that receives and handles these webhook requests.
  2. Use the "sync" notification level for important events to ensure delivery.
  3. Verify the authenticity of webhook requests using the provided HMAC signature.
  4. Consider building custom integrations or notifications based on webhook events.

Migration from Deploy Hooks

Heroku is encouraging users to migrate from the older Deploy Hooks to the more powerful and secure app webhooks. Deploy Hooks will be sunset on February 17, 2023.

In summary, Heroku's official API offers a robust webhook system that allows you to subscribe to a wide range of events, providing real-time notifications about changes to your Heroku apps and resources.

Rate Limits and other limitations

Here are the key points about the API rate limits for the Heroku API:

Rate Limit Details

  • The Heroku API has a rate limit of 4500 calls per hour per account [2][4].

  • This limit applies across an entire account, not per application [4].

  • The rate limit resets hourly [4].

  • When the limit is exceeded, further API calls are blocked until the next hour when the limit resets [4].

How the Rate Limit Works

  • Each account has a pool of 4500 request tokens [5].

  • Each API call uses one token from the pool [5].

  • Tokens are replenished at a rate of about 75 per minute (4500 per hour) up to the 4500 maximum [5].

  • If no tokens remain, further calls return a 429 Too Many Requests error until more tokens become available [5].

Best Practices

  • Implement rate limiting/throttling in your own code when making API calls [3].

  • Cache data where possible to reduce API calls [4].

  • Batch operations to minimize API requests [4].

  • Be cautious with features that require frequent API calls, like "Restart Crashed Dynos" [4].

  • Consider implementing client-side rate throttling to avoid hitting the limit [5].

Key Considerations

  • The limit is per account, not per application, so all apps under an account share the same limit [4].

  • There is no limit on incoming requests to applications hosted on Heroku - the limit only applies to calls to Heroku's platform API [3].

  • Proper rate limiting/throttling is important to avoid exceptions and ensure smooth API usage [5].

By following these guidelines and implementing proper rate limiting, you can effectively work within Heroku's API rate limits and avoid disruptions to your API usage.

Latest API Version

Based on the search results provided, the most recent version of the Heroku API is version 3. Here are the key points:

  1. The current and only supported version of the Heroku Platform API is V3 [^5].

  2. To use the current v3 version of the API, you need to pass this header in requests: Accept: application/vnd.heroku+json; version=3 [^5].

  3. The API documentation consistently refers to version 3 in the examples, such as:

    $ curl -n https://api.heroku.com/pipelines/$PIPELINE_ID/latest-releases \
      -H "Accept: application/vnd.heroku+json; version=3"
    

    [^3]

  4. There is no mention of a newer version (e.g., v4) being available or in development in the provided search results.

  5. The Heroku Connect API also supports version 3 [^4].

It's worth noting that while version 3 is the current version, Heroku has a compatibility policy in place for introducing changes to the API. This policy outlines how changes are communicated and implemented, ensuring stability for existing applications using the API [^5].

[^3]: Heroku Platform API Reference [^4]: Heroku Connect API [^5]: Heroku API Compatibility Policy

How to get a Heroku developer account and API Keys?

To get a developer account for Heroku and create an API integration, you need to follow these steps:

1. Create a Heroku Account

First, you need to sign up for a Heroku account if you don't already have one. Signup is free and instant.

2. Install the Heroku CLI

Install the Heroku Command Line Interface (CLI) on your local machine. This will allow you to interact with Heroku from the command line.

3. Generate an API Token

To authenticate your API requests, you need to generate an API token. There are two main ways to do this:

  1. For development purposes, you can use heroku auth:token from the CLI. However, this token expires after 1 year by default.

  2. For production use, it's recommended to create a non-expiring token using heroku authorizations:create. Here's how:

$ heroku authorizations:create -d "API integration token"

This will output a token that you can use for API requests.

4. Use the API Token

Once you have your token, you can use it to make API requests. Include it in the Authorization header of your HTTP requests like this:

Authorization: Bearer YOUR_TOKEN_HERE

5. Make API Requests

You can now make requests to the Heroku Platform API. For example, to create a new app:

curl -X POST https://api.heroku.com/apps \
-H "Accept: application/vnd.heroku+json; version=3" \
-H "Authorization: Bearer YOUR_TOKEN_HERE"

What can you do with the Heroku API?

Here are the key data models you can interact with using the Heroku API, along with what is possible for each:

Connections

  • Create, retrieve, update and delete Heroku Connect connections
  • Configure connection settings like polling frequency, write mode, etc.
  • View connection status and sync activity

Mappings

  • Create, retrieve, update and delete object mappings
  • Configure field mappings between Salesforce objects and Heroku Postgres tables
  • Set sync direction (read-only, write-only, or bi-directional)
  • Enable/disable individual field mappings

Sync Operations

  • Trigger full or partial syncs on-demand
  • View sync status and progress
  • Access sync logs and error details

External Objects

  • Create and manage Heroku External Objects configurations
  • Map Heroku Postgres tables to Salesforce external objects
  • Configure read/write access for external objects

Apps

  • Create, retrieve, update and delete Heroku apps
  • Manage app settings, config vars, domains, etc.
  • Scale dynos up/down
  • View app metrics and logs

Add-ons

  • Provision and deprovision add-ons for apps
  • Upgrade/downgrade add-on plans
  • Access add-on specific configuration

Releases

  • View release history for apps
  • Rollback to previous releases
  • Create new releases by updating code/config

Dynos

  • Start, stop, restart dynos
  • Scale dyno formation
  • View dyno metrics

Databases

  • Create and manage Heroku Postgres databases
  • Run database operations like backups, followers, etc.
  • Access database credentials

Users/Teams

  • Manage user access and permissions
  • Create and manage teams
  • Transfer app ownership

The API provides comprehensive access to manage most aspects of Heroku applications, add-ons, and Heroku Connect configurations programmatically. The data models cover core platform functionality as well as Heroku Connect specific operations.