Articles on: API Docs

Creating a Site

Creating a new site using APIs is simple but you need to know a couple of things.

When you create a new site, it may have 2 states:

Status = ready
Status = in progress

In the case of progress, you may need to query our task status API to see when the site will be ready. Lets understand this with examples:

Create Site



To create a site using APIs, you can call this endpoint:

<?php

require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://app.instawp.io/api/v2/sites', [
  'body' => '{"site_name":"xyzsitename"}',
  'headers' => [
    'authorization' => 'Bearer <api_key>',
    'content-type' => 'application/json',
  ],
]);

echo $response->getBody();


You will get something like this in the output:

{

   "status":true,
   "message":"Site installation work in progress, Wait for installation.",
   "data":{
      "message":"Site installation work in progress, Wait for installation.",
      "task_id":"d53a490af3cd",
      "status":1,
      "wp_url":"https:\/\/xyzsitename.instawp.xyz",
      "wp_username":"yuwehamebo0993",
      "wp_password":"q0ynLPB8jZMU3rG6DOl9",
      "id":98705,
      "s_hash":"$2y$10$movlRe2FG0R1agav\/prPF.YCCdpYjdoKphSUeF.js.zS3U4Dc0nYK",
      "token":null
   }
}


You can extract:

URL: https://xyzsitename.instawp.xyz
Username: yuwehamebo0993
Password: q0ynLPB8jZMU3rG6DOl9
Autologin Hash: $2y$10$movlRe2FG0R1agav\/prPF.YCCdpYjdoKphSUeF.js.zS3U4Dc0nYK

Check Progress



Also notice the task_id d53a490af3cd, which can now be used to get the status of the site installation progress.

$response = $client->request('GET', "https://app.instawp.io/api/v2/tasks/d53a490af3cd/status", [
  'headers' => [
    'authorization' => 'Bearer <token>',
  ],
]);


Response:

{
   "status":true,
   "message":"Task details retrived.",
   "data":{
      "id":148601,
      "team_id":1565,
      "user_id":1504,
      "type":"site_install",
      "comment":null,
      "cloud_task_id":"f42764a58ddd",
      "resource_id":98716,
      "resource_type":"App\\Models\\Site",
      "success_callback_fun":"successICSiteInstall",
      "error_callback_fun":"failedICSiteInstall",
      "percentage_complete":"0.00",
      "status":"progress",
      "timeout_at":"2022-12-14 11:25:43",
      "task_meta":null,
      "created_at":"2022-12-14T11:23:43.000000Z",
      "updated_at":"2022-12-14T11:23:43.000000Z"
   }
}


You can query the task status end point every X seconds till you have a complete site.

Complete code



<?php
require_once "vendor/autoload.php";

$client = new \GuzzleHttp\Client();
$token = "your token";

$response = $client->request("POST", "https://app.instawp.io/api/v2/sites", [
    "body" => '{"site_name":"xyzsitename1"}',
    "headers" => [
        "authorization" => "Bearer $token",
        "content-type" => "application/json",
    ],
]);

//echo $response->getBody();

$site = json_decode($response->getBody());

$task_id = $site->data->task_id;

while (true) {
    echo "[.] Waiting for the site to be created...\n";

    $response = $client->request(
        "GET",
        "https://app.instawp.io/api/v2/tasks/$task_id/status",
        [
            "headers" => [
                "authorization" =>
                    "Bearer $token",
            ],
        ]
    );

    $task = json_decode($response->getBody());

    if ($task->data->status != "progress") {
        echo "[+] Site Created : {$site->data->wp_url}\n";
        break;
    }

    sleep(2);
}





Github Actions
Add Deployment

Updated on: 21/09/2023

Was this article helpful?

Share your feedback

Cancel

Thank you!