The Forge REST API

jamstack

#1

Forge has a basic REST API currently, which we created to enable our CLI tool and to test automated deployments from our sketch builder concept.

It’s basic and we need to extend it along the same lines as our Health platform with proper Developer accounts etc.

But, since it’s there, you can use it too, for all manner of static site hosting ideas…

Authentication

First, you need to login your user (they need to have an existing account from Forge

POST https://getforge.com/api/cli/login

curl -X POST "https://getforge.com/api/cli/login" \
 -H "Content-Type: application/json" \
 -H "Cache-Control: no-cache" \
 -d '{
    "email": "YOUR_EMAIL",
    "password": "YOUR_PASSWORD"
 }' 

Response Example:

{"name":"USERNAME","token":"YOUR_TOKEN"}

You’ll want to store the token somewhere safe for further requests to the user account.

Fetch Sites

You’ll probably want to retrieve a list of the Forge users sites at some stage, in order for User to select a site to perform some action.

You can do that like this…

GET https://getforge.com/api/cli/sites

curl -X GET -H "Content-Type: application/json" \ 
-H "Cache-Control: no-cache" \  
"https://getforge.com/api/cli/sites?token=YOUR_TOKEN"

Publish Site

You can upload an archive (.zip) of your site to publish on Forge. You need to specify the site you wish to deploy to in the params, along with the user token. The site should be submitted as multipart form data.

POST https://getforge.com/api/cli/deploy

Since multipart form data via cURL is a bit fiddly, here’s what it would look like via Postman REST Client


Forge REST API v2
#2

EDIT: Instead of using param site, use archive, when uploading your zip file