Copying Slugs with the Platform API
Last updated April 07, 2023
This article describes how a slug from one app can be used to create a release on another app. Imagine that you have pushed code to a staging app. The code has been tested and you’re now ready to release to production. Instead of pushing to the production app and waiting for the code to build again, you can simply copy the slug from the staging app to the production app.
A Heroku user can only manipulate slugs that were created on apps that they have access to. If you try to create a release using a slug that was created on an app that you don’t have access to, you get an HTTP 403 Forbidden status. See the Dev Center section on collaboration for details.
First, list releases on the staging app to get the id of the slug to release on the production app:
$ curl -H "Accept: application/vnd.heroku+json; version=3" -n \
https://api.heroku.com/apps/example-app-staging/releases
...
"slug":{ "id":"ff40c84f-a538-4b65-a838-88fdd5245f4b" }
Now, create a new release on the production app using the slug from the staging app:
$ curl -X POST -H "Accept: application/vnd.heroku+json; version=3" -n \
-H "Content-Type: application/json" \
-d '{"slug": "ff40c84f-a538-4b65-a838-88fdd5245f4b"}' \
https://api.heroku.com/apps/example-app-production/releases
That’s it! The new code is now running on the example-app-production
app.
Copying slugs between apps is already possible using the beta Pipelines plugin, and Heroku Fork. The release endpoint exposes the primitives necessary for third-party API developers to build services offering similar functionality.