Examples

Once you have access to LayerOps, you can find the complete API documentation.

api documentation

Please refer to the documentation to authenticate.

In the following examples, we assume that an API key has been created with the correct rights, and here are the values:

Key ID: LYPFNN8BTS9GBQFRIXCHGWJXU
API Key secret: 789f7b2f-b1f4-456e-83da-56184a01c2d3

List projects

Request:

curl -X 'GET' \
  'https://api.layerops.io/v1/workspaces?includeEnvironmentAndProviders=true' \
  -H 'accept: application/json' \
  -H 'X-API-KEY: LYPFNN8BTS9GBQFRIXCHGWJXU:789f7b2f-b1f4-456e-83da-56184a01c2d3'

Response:

{
  "globalLimitEnvironmentNumber": 4,
  "totalAssociatedEnvironments": 4,
  "workspaces": [
    {
      "uuid": "ada681e6-b50e-434b-a6cf-4e9b4db2019a",
      "name": "Client A",
      "createdAt": "2023-09-12T10:17:58.000Z",
      "limitEnvironmentNumber": 4,
      "environments": [
        {
          "uuid": "e7b73b16-7931-4878-944f-bdb97c5b1d85",
          "name": "Prod",
          "deletedAt": null,
          "providers": [
            {
              "uuid": "d57b214f-ec43-41b9-8cf1-71329349093b",
              "platformName": "Azure",
              "platformIcon": "azure-icon.svg"
            },
            {
              "uuid": "62ae1fd9-b355-4d3c-a05e-3a0e23497855",
              "platformName": "Google Cloud Platform",
              "platformIcon": "gcp-icon.svg"
            },
            {
              "uuid": "8bd4754c-1392-4d79-b3d7-32eed491e90c",
              "platformName": "Scaleway",
              "platformIcon": "scaleway-icon.svg"
            }
          ]
        }
      ]
    }
  ]
}

List instance types for provider Azure

Request:

curl -X 'GET' \
  'https://api.layerops.io/v1/providers/d57b214f-ec43-41b9-8cf1-71329349093b/instancesTypes' \
  -H 'accept: application/json' \
  -H 'X-API-KEY: LYPFNN8BTS9GBQFRIXCHGWJXU:789f7b2f-b1f4-456e-83da-56184a01c2d3'

Response:

[
  {
    "uuid": "cc6d622a-5144-11ed-84a1-1b508e278eb5",
    "name": "B2s",
    "memory": 4,
    "vCPUs": 2,
    "ssd": 8,
    "storage": null,
    "onDemandCost": 472,
    "reservedCost": null,
    "priceFactor": 10000,
    "monthlyPrice": 339840
  },
  {
    "uuid": "cc6d6261-5144-11ed-84a1-1b508e278eb5",
    "name": "DS1 v2",
    "memory": 3.5,
    "vCPUs": 1,
    "ssd": 7,
    "storage": null,
    "onDemandCost": 877,
    "reservedCost": null,
    "priceFactor": 10000,
    "monthlyPrice": 631440
  },
  [...]
]

Create B2s instance pool on provider Azure

Request:

curl -X 'POST' \
  'https://api.layerops.io/v1/providers/d57b214f-ec43-41b9-8cf1-71329349093b/instancePools' \
  -H 'accept: application/json' \
  -H 'X-API-KEY: LYPFNN8BTS9GBQFRIXCHGWJXU:789f7b2f-b1f4-456e-83da-56184a01c2d3' \
  -H 'Content-Type: application/json' \
  -d '{
    "instanceTypeUuid": "cc6d622a-5144-11ed-84a1-1b508e278eb5",
    "name": "vmAzure",
    "tags": [
      "backend"
    ],
    "volumeSize": 0,
    "countMin": 1,
    "countMax": 10,
    "replaceInstanceDownMinutes": 5,
    "instanceUnusedMinutes": 10
  }'

Response:

{
  "uuid": "27d6c053-5eab-4838-bd14-040ed5d617d9",
  "name": "vmAzure"
}

Get instance pool status

Request:

curl -X 'GET' \
  'https://api.layerops.io/v1/instancePools/27d6c053-5eab-4838-bd14-040ed5d617d9/status?includeInstancesDistribution=false&includeMetrics=false&includeAlerts=false' \
  -H 'accept: application/json' \
  -H 'X-API-KEY: LYPFNN8BTS9GBQFRIXCHGWJXU:789f7b2f-b1f4-456e-83da-56184a01c2d3'

Response:

{
  "uuid": "27d6c053-5eab-4838-bd14-040ed5d617d9",
  "status": "DONE",
  "success": true,
  "alerts": [],
  "count": 1,
  "countRunning": 0,
  "totalCpuMhz": 0,
  "totalReservedCpuMhz": 0,
  "totalMemoryMB": 0,
  "totalReservedMemoryMB": 0,
  "deletedAt": null,
  "errorType": null,
  "errorCode": null
}

Create service

Request:

curl -X 'POST' \
  'https://api.layerops.io/v1/environments/e7b73b16-7931-4878-944f-bdb97c5b1d85/services/docker' \
  -H 'accept: application/json' \
  -H 'X-API-KEY: LYPFNN8BTS9GBQFRIXCHGWJXU:789f7b2f-b1f4-456e-83da-56184a01c2d3' \
  -H 'Content-Type: application/json' \
  -d '{
    "dockerConfiguration": {
      "image": "nginx",
      "imageVersion": "latest"
    },
    "name": "myservice",
    "countMin": 1,
    "countMax": 1,
    "ports": [
      {
        "healthCheckType": "HTTP",
        "healthCheckMethod": "GET",
        "listeningPort": 80,
        "loadBalancerRules": [
          {
            "publicPort": 443
          }
        ],
        "healthCheckEnabled": true,
        "healthCheckTimeoutSeconds": 30,
        "healthCheckPath": "/",
        "healthCheckIntervalSeconds": 60
      }
    ]
  }'

Response:

{
  "name": "myservice",
  "uuid": "e07550ad-cce6-4aca-ad56-fa085f388c6f",
  "environmentLbDns": "lb-02eae809.asendra.layerops.io",
  "ports": [
    {
      "uuid": "564b6913-18bc-4e21-a193-bd00d697a270",
      "listeningPort": 80,
      "loadBalancerRules": [
        {
          "uuid": "f1c2b635-ed60-4890-8437-fa483f8f23b6",
          "publicPort": 443,
          "domain": "myservice-80-e07550ad.e7b73b16.asendra.layerops.io",
          "isDefaultRule": true
        }
      ]
    }
  ]
}

Get service status

Request:

curl -X 'GET' \
  'https://api.layerops.io/v1/services/e07550ad-cce6-4aca-ad56-fa085f388c6f/status?includeInstancesDistribution=true&includeAlerts=false&includeStats=true&onlyStats=false' \
  -H 'accept: application/json' \
  -H 'X-API-KEY: LYPFNN8BTS9GBQFRIXCHGWJXU:789f7b2f-b1f4-456e-83da-56184a01c2d3'

Response:

{
  "uuid": "e07550ad-cce6-4aca-ad56-fa085f388c6f",
  "status": "DONE",
  "success": true,
  "alerts": [],
  "runningSuccess": "SUCCESS",
  "runHistory": [],
  "count": 1,
  "countRunning": 1,
  "totalUsedCpuMhz": 0,
  "totalReservedCpuMhz": 128,
  "totalUsedMemoryMB": 0,
  "totalReservedMemoryMB": 128,
  "instances": [
    {
      "serviceUuid": "e07550ad-cce6-4aca-ad56-fa085f388c6f",
      "uuid": "b727c4f2-8b2d-4234-ac66-992aeace0765",
      "totalCpuMhz": 5586,
      "totalMemoryMB": 3903,
      "serviceCount": 1,
      "isRunning": true,
      "totalReservedCpuMhz": 778,
      "totalReservedMemoryMB": 856,
      "instancePoolUuid": "27d6c053-5eab-4838-bd14-040ed5d617d9",
      "createdAt": "2023-10-16T15:33:56.000Z",
      "instancePoolName": "vmAzure",
      "provider": {
        "uuid": "d57b214f-ec43-41b9-8cf1-71329349093b",
        "platformIcon": "azure-icon.svg",
        "platformName": "Azure",
        "regionName": "France Central"
      }
    }
  ],
  "deletedAt": null,
  "pausedAt": null,
  "errorType": null,
  "dimensionExhausted": null,
  "placementFailure": false,
  "errorMessage": null
}