Laravel Forge JavaScript SDK

Servers

Servers

Create a Server

Method

forge.servers.create(payload)

Usage

1const forge = new Forge('API_TOKEN');
2
3const user = await forge.servers.create(payload);

Payload

1{
2 provider: 'ocean2',
3 type: 'web',
4 credential_id: 1,
5 name: 'test-via-api',
6 size: '512MB',
7 database: 'test123',
8 php_version: 'php71',
9 region: 'ams2',
10 recipe_id: null,
11}

Payload Parameters

KeyDescription
providerThe server provider. Valid values are ocean2 for Digital Ocean, linode, vultr, aws, hetzner and custom.
typeThe type of server to create. Valid values are app, web, loadbalancer, cache, database, worker, meilisearch. app is used by default if no value is defined.
credential_idThis is only required when the provider is not custom.
regionThe name of the region where the server will be created. This value is not required you are building a Custom VPS server. Valid region identifiers.
ip_addressThe IP Address of the server. Only required when the provider is custom.
private_ip_addressThe Private IP Address of the server. Only required when the provider is custom.
php_versionValid values are php80, php74, php73, php72, php71, php70, and php56.
databaseThe name of the database Forge should create when building the server. If omitted, forge will be used.
mariaIndicates if MariaDB should be installed. Otherwise, MySQL will be installed.
database_typeValid values are mysql, mysql8, mariadb, postgres.
node_balancerDetermines if the server should be provisioned as a load balancer.
networkAn array of server IDs that the server should be able to connect to.
recipe_idAn optional ID of a recipe to run after provisioning.
aws_vpc_idID of the existing VPC
aws_subnet_idID of the existing subnet
aws_vpc_nameWhen creating a new one

Example Response

1{
2 "server": {
3 "id": 16,
4 "credential_id": 1,
5 "type": "web",
6 "name": "test-via-api",
7 "size": "01",
8 "region": "ams2",
9 "php_version": "php71",
10 "ip_address": null,
11 "private_ip_address": null,
12 "blackfire_status": null,
13 "papertrail_status": null,
14 "revoked": false,
15 "created_at": "2016-12-15 15:04:05",
16 "is_ready": false,
17 "network": []
18 },
19 "sudo_password": "baracoda",
20 "database_password": "spotted_eagle_ray"
21}

List Servers

Method

forge.servers.list()

Usage

1const forge = new Forge('API_TOKEN');
2
3const servers = await forge.servers.list();

Example Response

1{
2 "servers": [
3 {
4 "id": 1,
5 "credential_id": 1,
6 "name": "test-via-api",
7 "size": "512MB",
8 "region": "Amsterdam 2",
9 "php_version": "php71",
10 "ip_address": "37.139.3.148",
11 "private_ip_address": "10.129.3.252",
12 "blackfire_status": null,
13 "papertrail_status": null,
14 "revoked": false,
15 "created_at": "2016-12-15 18:38:18",
16 "is_ready": true,
17 "network": []
18 }
19 ]
20}

Get a Server

Method

forge.servers.get(server_id)

Usage

1const forge = new Forge('API_TOKEN');
2
3const server = await forge.servers.get(server_id);

Example Response

1{
2 "server": {
3 "id": 1,
4 "credential_id": 1,
5 "name": "test-via-api",
6 "size": "512MB",
7 "region": "Amsterdam 2",
8 "php_version": "php71",
9 "ip_address": "37.139.3.148",
10 "private_ip_address": "10.129.3.252",
11 "blackfire_status": null,
12 "papertrail_status": null,
13 "revoked": false,
14 "created_at": "2016-12-15 18:38:18",
15 "is_ready": true,
16 "network": []
17 }
18}

Update a Server

Method

forge.servers.update(server_id, payload)

Usage

1const forge = new Forge('API_TOKEN');
2
3const server = forge.servers.update(server_id, payload);

Payload

1{
2 name: 'renamed-server',
3 size: '512MB',
4 ip_address: '192.241.143.108',
5 private_ip_address: '10.136.8.40',
6 max_upload_size: 123,
7 network: [
8 2,
9 3,
10 ],
11 timezone: 'Europe/London',
12}

Payload Parameters

The payload parameters are the same as forge.servers.create().

Example Response

1{
2 "server": {
3 "id": 16,
4 "credential_id": 1,
5 "name": "test-via-api",
6 "size": "512MB",
7 "region": "Amsterdam 2",
8 "php_version": "php71",
9 "ip_address": null,
10 "private_ip_address": null,
11 "blackfire_status": null,
12 "papertrail_status": null,
13 "revoked": false,
14 "created_at": "2016-12-15 15:04:05",
15 "is_ready": false,
16 "network":[
17 2,
18 3
19 ]
20 }
21}

Delete a Server

Method

forge.servers.delete(server_id)

Usage

1const forge = new Forge('API_TOKEN');
2
3await forge.servers.delete(server_id);

Update Database Password

This method updates Forge's copy of the primary database password which should be used to authenticate the creation of new databases and database users. This is typically only needed if you are working with a Forge server that was built before database administration was added to Forge.

Method

forge.servers.updateDbPassword(server_id)

Usage

1const forge = new Forge('API_TOKEN');
2
3await forge.servers.updateDbPassword(server_id, payload);

Payload

1{
2 password: 'new_password',
3}

Payload Parameters

KeyDescription
passwordThe new password

Reboot a Server

Method

forge.servers.reboot(server_id)

Usage

1const forge = new Forge('API_TOKEN');
2
3await forge.servers.reboot(server_id);

Revoke Forge Access to a Server

Method

forge.servers.revoke(server_id)

Usage

1const forge = new Forge('API_TOKEN');
2
3await forge.servers.revoke(server_id);

Reconnect a Revoked Server

This method will return an SSH key which you will need to add to the server. Once the key has been added to the server, you may "reactivate" it.

Method

forge.servers.reconnect(server_id)

Usage

1const forge = new Forge('API_TOKEN');
2
3const server = await forge.servers.reconnect(server_id);

Example Response

1{
2 "public_key": "CONTENT_OF_THE_PUBLIC_KEY"
3}

Reactivate a Revoked Server

Method

forge.servers.reactivate(server_id)

Usage

1const forge = new Forge('API_TOKEN');
2
3await forge.servers.reactivate(server_id);

Get Recent Events

Method

forge.servers.events([server_id])

Usage

1const forge = new Forge('API_TOKEN');
2
3const events = forge.servers.events();

Optionally, you can pass a server_id to get recent events for only that server:

1const forge = new Forge('API_TOKEN');
2
3const events = forge.servers.events(server_id);

Example Response

1[
2 {
3 "server_id": 18,
4 "ran_as": "forge",
5 "server_name": "billowing-cliff",
6 "description": "Deploying PHP Info Page.",
7 "created_at": "2017-04-28 18:08:44"
8 }
9]
Edit this page on GitHub