Introducing Forge API 0:00As Forge is a service that is targeted at developers, it comes to no surprise that Forge also provides an API. So with this API, you have basically access to all the actions that you can do manually in the Forge admin interface, but you can do them using this API. So the API documentation is very good and here you can see everything that you can do, like creating servers, creating sites, creating databases, deleting databases, users, etc. So pretty much everything from the admin interface. Now the Forge API works by using REST requests to the API endpoint, but what I want to show you is how we can use this API in a PHP application. So Mohammed Saeed, one of the employees of Forge, has created a Forge SDK, Installing the Forge SDK 0:52but what I want to show you is how we can use this API in a PHP application. So Mohammed Saeed, one of the employees of Forge, has created a Forge SDK, which is open source on GitHub, and this SDK allows us to create servers, sites, etc. So everything that you see in the API documentation, we can do this by code. So let's take a look at it and go through different scenarios and take a look at what we can achieve with the API. So the first thing we need to do is we need to install the SDK. We can do this using Composer. Okay, and I already created a simple index.php file, which just loads the Composer autoloader, and what we can do next is Creating API Token 1:48Okay, and I already created a simple index.php file, which just loads the Composer autoloader, and what we can do next is create a new instance of the SDK. So as you can see, we need to obtain a token for the API, and we can do this in the Forge admin interface. So if I go to my account and API, I can then create new tokens. So let's just call it Forge demo and create a new token. Here it is. So we copy it. Here it is. So we copy it. And just paste it in here. Listing Available Servers 2:30Here it is. So we copy it. And just paste it in here. Okay, now I want to retrieve a list of my available servers. To do this with the SDK, when we look at the documentation, we can just call the servers method. So servers equals to Forge servers. And now let's just loop over the servers that we have, and for each server, we will echo the name and maybe the region of the server. So to do this, we can just do a for each servers as server,and maybe the region of the server. So to do this, we can just do a for each servers as server, servers as server, echo server name, and server region, and a line break. And now if we run the script, we can see that we have our two servers, which are located in Frankfurt. Yeah, we have our two application servers, which are located in Frankfurt,Yeah, we have our two application servers, which are located in Frankfurt, and we have the load balancer, which is located in Frankfurt as well. So if you wonder which properties you can access using the Forge SDK, those are the exact same properties that we have in the API documentation. So if we take a look at the server, you can see from the response that a server has an ID, Creating a Site via SDK 4:12So if we take a look at the server, you can see from the response that a server has an ID, a credential ID, the name, the size, the region, et cetera. So the next thing I want to do is I want to create a site on one of my servers using the SDK. And this could become very handy if you, for example, want to automatically create a site on one of your development machines that is managed by Forge every time you create a repository in GitLab, for example.that is managed by Forge every time you create a repository in GitLab, for example. So then you could just create a custom GitLab hook, which calls a script that you wrote with the Forge SDK, and then you can automatically create a new site on your development machine. So to do this, if we go back to the SDK documentation, we can see that we can create a site. It needs the server ID and then the site parameters, which you can see when you look at the API documentation.It needs the server ID and then the site parameters, which you can see when you look at the API documentation. So if we go to sites, create site, you can see that the payload to create a site is the domain, the project type, and the directory that will be used as the public directory. So in order to create a new site on, let's just say the first server that we have, all we need to do is call forge create site, then just use the first server and use its ID.all we need to do is call forge create site, then just use the first server and use its ID. And the payload is going to be, the domain will be api.beyond-code.org. The project type will be php. And the directory is going to be public. And as a third parameter, we can pass a Boolean false, which indicates that we will not want to wait for the create site response. So if we now go back to our browserfor the create site response. So if we now go back to our browser and go to the server that we will use to create the site on, and then call our index.php script, and reload the browser, we can now see that the site api.beyond-code.org is being created by Forge, great. And as I mentioned, there are a lot of different methods that you can use, some server related, site related, et cetera. Automating Tasks with API 6:55there are a lot of different methods that you can use, some server related, site related, et cetera. So using the Forge SDK, you can customize your own Forge setup and pretty much do everything that you can also do in the admin interface with code. And as I said, this could be extremely useful to automate tasks. For example, when a good repository gets created, I wrote myself a chat botFor example, when a good repository gets created, I wrote myself a chat bot so that I can create new sites and servers using Slack. Things like that are extremely powerful with Forge in combination with the API.