Show nav
Heroku Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
View categories

Categories

  • Heroku Architecture
    • Dynos (app containers)
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Command Line
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery
    • Continuous Integration
  • Language Support
    • Node.js
    • Ruby
      • Rails Support
      • Working with Bundler
    • Python
      • Background Jobs in Python
      • Working with Django
    • Java
      • Working with Maven
      • Java Database Operations
      • Working with the Play Framework
      • Java Advanced Topics
    • PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
    • Kotlin
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
    • Heroku Redis
    • Apache Kafka on Heroku
    • Other Data Stores
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
    • Compliance
  • Heroku Enterprise
    • Private Spaces
      • Infrastructure Networking
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
    • Single Sign-on (SSO)
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Extending Heroku
  • ›
  • Platform API
  • ›
  • Getting Started with the Platform API

Getting Started with the Platform API

Last updated 11 June 2018

Table of Contents

  • Prerequisites
  • Samples
  • Authentication
  • Calling the API
  • Alternatives
  • Wrap-up

This is a brief guide to help you get started with the Heroku Platform API. For a detailed reference, please see the Platform API Reference article.

Prerequisites

  1. A shell with curl
  2. A Heroku user account. Signup is free and instant.

Samples

The samples below use curl simply for convenience. We recommend using your favorite programming language and a HTTP library with the API.

Alternatively, several client libraries are available:

  • Go: heroku-go.
  • Node: node-heroku-client
  • PHP: php-heroku-client
  • Ruby: platform-api
  • Scala: Heroku.scala

Authentication

Authentication is passed in the Authorization header with a value set to Bearer {token}.

If you are using curl and are logged in with the Heroku CLI, you can use curl -n to automatically set this header to the same token as the CLI. This token can also be retrieved with heroku auth:token, however it is only valid for a maximum of 1 year by default.

You can create a non-expiring token by running heroku authorizations:create:

$ heroku authorizations:create -d "getting started token"
Creating OAuth Authorization... done
Client:      <none>
ID:          a6e98151-f242-4592-b107-25fbac5ab410
Description: getting started token
Scope:       global
Token:       cf0e05d9-4eca-4948-a012-b91fe9704bab
Updated at:  Fri Jun 01 2018 13:26:56 GMT-0700 (PDT) (less than a minute ago)

Calling the API

Here is how to create an app with curl using the token from the netrc file:

$ curl -nX POST https://api.heroku.com/apps \
-H "Accept: application/vnd.heroku+json; version=3"

Alternatively, to create an app with an API key created with heroku authorizations:create and stored in the HEROKU_API_KEY environment variable:

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

On Windows it would be defined like this:

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

The API returns JSON with details of the newly created app:

{
  "created_at":"2013-05-21T22:36:48-00:00",
  "id":"01234567-89ab-cdef-0123-456789abcdef",
  "git_url":"git@heroku.com:cryptic-ocean-8852.git",
  "name":"cryptic-ocean-8852",
  ...
}

You can also query the API for info on the app you created by passing the id in the path:

$ curl -nX GET https://api.heroku.com/apps/01234567-89ab-cdef-0123-456789abcdef \
-H "Accept: application/vnd.heroku+json; version=3"

You can also list all the apps that you own or collaborate on:

$ curl -nX GET https://api.heroku.com/apps \
-H "Accept: application/vnd.heroku+json; version=3"

Let’s update the name of the app we created above by making a PATCH request to the same path you used for info:

$ curl -nX PATCH https://api.heroku.com/apps/01234567-89ab-cdef-0123-456789abcdef \
-H "Accept: application/vnd.heroku+json; version=3" \
-H "Content-Type: application/json" \
-d "{\"name\":\"my-awesome-app\"}"

You can also use the name to query the app, which is especially handy when you have changed it to something more memorable:

$ curl -n https://api.heroku.com/apps/my-awesome-app \
-H "Accept: application/vnd.heroku+json; version=3"

Finally, you can clean up and delete the test app:

$ curl -nX DELETE https://api.heroku.com/apps/01234567-89ab-cdef-0123-456789abcdef \
-H "Accept: application/vnd.heroku+json; version=3"

Alternatives

The Heroku API plugin can be used to make arbitrary commands to the CLI:

$ heroku plugins:install api
$ heroku api POST /apps --body '{"name": "mynewapp"}'
POST api.heroku.com/apps... 201
{
  "name": "mynewapp12345jeff",
  "region": {
    "id": "59accabd-516d-4f0e-83e6-6e3757701145",
    "name": "us"
  },
  "updated_at": "2018-06-01T21:00:41Z",
  "web_url": "https://mynewapp12345jeff.herokuapp.com/",
  ...
}

httpie is a useful cURL replacement that is a bit more user friendly. It automatically uses the authentication credential from netrc and it assumes you’re POSTing JSON by default:

$ http PATCH https://api.heroku.com/apps/myapp/config-vars \
"Accept:application/vnd.heroku+json; version=3" \
RAILS_ENV=production
HTTP/1.1 200 OK
Cache-Control: private, no-cache
Content-Encoding: gzip
Content-Length: 672
Content-Type: application/json
...
{
    "DATABASE_URL": "postgres://pg",
    "RAILS_ENV": "production"
}

Wrap-up

This tutorial demonstrates how to call the Heroku Platform API using curl, but you can transfer this approach to whatever language and environment you favor. The tutorial focused specifically on creating, updating and deleting apps. The API has many more resources available, including add-ons, config vars and domains. They all work quite similarly to apps and detailed information can be found in the API reference.

Keep reading

  • Platform API
  • Platform API Reference

Feedback

Log in to submit feedback.

Creating Slugs from ScratchJSON Schema for Platform API

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Podcasts
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing

Subscribe to our monthly newsletter

  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Heroku Podcasts
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Facebook
  • Instagram
  • Github
  • LinkedIn
Heroku is acompany

 © Salesforce.com

  • heroku.com
  • Terms of Service
  • Privacy
  • Cookies