Download OpenAPI specification:Download
Copyright SAKURA internet Inc.
「AppRun」が提供するAPIの利用方法とサンプルを公開しております。
APIを利用するためには、認証のための「APIキー」が必要です。事前にキーを発行しておきます。
APIキーは「ユーザーID」「パスワード」に相当する「トークン」と呼ばれる認証情報で構成されています。
| 項目名 | APIキー発行時の項目名 | このドキュメント内での例 | 
|---|---|---|
| ユーザーID | アクセストークン(UUID) | 01234567-89ab-cdef-0123-456789abcdef | 
| パスワード | アクセストークンシークレット | SAMPLETOKENSAMPLETOKENSAMPLETOKENSAM | 
APIの入力には送信先URLに対して、いくつかのヘッダーとAPIキーを送信します。
# 入力サンプル
curl -u '01234567-89ab-cdef-0123-456789abcdef:SAMPLETOKENSAMPLETOKENSAMPLETOKENSAM' \
     'https://secure.sakura.ad.jp/cloud/api/apprun/1.0/apprun/api/applications'
APIからの結果は、「応答コード(HTTPステータスコード)」と、「JSON形式(UTF-8)の結果」として出力されます。
応答コードは、リクエストが成功したのか、失敗したのか大まかな情報を判断することができるもので、例えば失敗したときには、なぜこのような結果になったのかなど、具体的な情報は応答コードと主に返された本文を見ることで把握することができます。
| 結果 | 応答コード/status | 
|---|---|
| 成功(要求を受け付けた) | 2xx | 
| 失敗(要求が受け付けられなかった) | 4xx, 5xx | 
# 出力結果サンプル(レスポンスヘッダー)
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 16 Nov 2021 12:39:48 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 443
Connection: keep-alive
Status: 200 OK
Pragma: no-cache
Cache-Control: no-cache
X-Sakura-Proxy-Microtime: 66245
X-Sakura-Proxy-Decode-Microtime: 62
X-Sakura-Content-Length: 443
X-Sakura-Serial: 86ab6c743f72aa5ea6f17e254fd5f803
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Frame-Options: DENY
X-Sakura-Encode-Microtime: 260
Vary: Accept-Encoding
# 出力結果サンプル(レスポンスボディー)
{
  "error": {
    "code": 401,
    "message": "Login Required",
    "errors": [
      {
        "domain": "global",
        "reason": "required",
        "message": "Login Required",
        "location_type": "header",
        "location": "Authorization"
      }
    ]
  }
}
AppRunの利用を開始するにはユーザーを作成します。
ユーザーとは、AppRunを利用するための独立したユーザーであり、ユーザー作成および削除による料金の発生はございません。
なお、すでにユーザーを作成済みの場合は、再度ユーザーの作成は不要です。
ユーザーを作成するには以下のような入力を行います。
# 入力サンプル
curl -u '01234567-89ab-cdef-0123-456789abcdef:SAMPLETOKENSAMPLETOKENSAMPLETOKENSAM' \
     -X POST \
     https://secure.sakura.ad.jp/cloud/api/apprun/1.0/apprun/api/user
ユーザーの作成が完了すると、
などの操作が可能になります。
ユーザーを作成後、アプリケーションの作成、更新、削除が可能になります。
アプリケーションを作成するには以下のような入力を行います。
# 入力サンプル
vi request_body.json
cat request_body.json
{
  "name": "Application",
  "timeout_seconds": 60,
  "port": 8080,
  "min_scale": 0,
  "max_scale": 1,
  "scale_target_concurrency": 100,
  "components": [
    {
      "name": "Component01",
      "max_cpu": "0.1",
      "max_memory": "256Mi",
      "deploy_source": {
        "container_registry": {
          "image": "my-app.sakuracr.jp/my-app:latest"
        }
      },
      "env": [
        {
          "key": "TARGET",
          "value": "World"
        }
      ],
      "probe": {
        "http_get": {
          "path": "/",
          "port": 8080,
          "headers": [
            {
              "name": "Custom-Header",
              "value": "Awesome"
            }
          ]
        }
      }
    }
  ]
}
curl -u '01234567-89ab-cdef-0123-456789abcdef:SAMPLETOKENSAMPLETOKENSAMPLETOKENSAM' \
     -X POST \
     -d '@request_body.json' \
     https://secure.sakura.ad.jp/cloud/api/apprun/1.0/apprun/api/applications
上記で作成したアプリケーションを取得するには以下のような入力を行います。
# 入力サンプル
curl -u '01234567-89ab-cdef-0123-456789abcdef:SAMPLETOKENSAMPLETOKENSAMPLETOKENSAM' \
     -X GET \
     https://secure.sakura.ad.jp/cloud/api/apprun/1.0/apprun/api/applications/{id}
上記で作成したアプリケーションを更新するには以下のような入力を行います。
# 入力サンプル
vi request_body.json
cat request_body.json
{
  "components": [
    {
      "name": "Component01 updated",
      "max_cpu": "0.1",
      "max_memory": "256Mi",
      "deploy_source": {
        "container_registry": {
          "image": "my-app.sakuracr.jp/my-app-v2:latest"
        }
      }
    }
  ],
  "all_traffic_available": true
}
curl -u '01234567-89ab-cdef-0123-456789abcdef:SAMPLETOKENSAMPLETOKENSAMPLETOKENSAM' \
     -X PATCH \
     -d '@request_body.json' \
     https://secure.sakura.ad.jp/cloud/api/apprun/1.0/apprun/api/applications/{id}
上記で作成したアプリケーションを削除するには以下のような入力を行います。
# 入力サンプル
curl -u '01234567-89ab-cdef-0123-456789abcdef:SAMPLETOKENSAMPLETOKENSAMPLETOKENSAM' \
     -X DELETE \
     https://secure.sakura.ad.jp/cloud/api/apprun/1.0/apprun/api/applications/{id}
アプリケーションを作成、更新した際、その設定情報をバージョンとして保存します。
バージョンを取得するには以下のような入力を行います。
# 入力サンプル
curl -u '01234567-89ab-cdef-0123-456789abcdef:SAMPLETOKENSAMPLETOKENSAMPLETOKENSAM' \
     -X GET \
     https://secure.sakura.ad.jp/cloud/api/apprun/1.0/apprun/api/applications/{id}/versions/{version_id}
上記で作成したバージョンを削除するには以下のような入力を行います。
# 入力サンプル
curl -u '01234567-89ab-cdef-0123-456789abcdef:SAMPLETOKENSAMPLETOKENSAMPLETOKENSAM' \
     -X DELETE \
     https://secure.sakura.ad.jp/cloud/api/apprun/1.0/apprun/api/applications/{id}/versions/{version_id}
アプリケーションは指定のバージョンへトラフィックを分散します。
トラフィック分散を確認するには以下のような入力を行います。
# 入力サンプル
curl -u '01234567-89ab-cdef-0123-456789abcdef:SAMPLETOKENSAMPLETOKENSAMPLETOKENSAM' \
     -X GET \
     https://secure.sakura.ad.jp/cloud/api/apprun/1.0/apprun/api/applications/{id}/traffics
トラフィック分散を変更するには以下のような入力を行います。
# 入力サンプル
vi request_body.json
cat request_body.json
[
  {
    "is_latest_version": true,
    "percent": 50
  },
  {
    "version_name": "Application-861850d6-8240-7c31-9b69-80ea4466918d-1726726814",
    "percent": 50
  }
]
curl -u '01234567-89ab-cdef-0123-456789abcdef:SAMPLETOKENSAMPLETOKENSAMPLETOKENSAM' \
     -X PUT \
     -d '@request_body.json' \
     https://secure.sakura.ad.jp/cloud/api/apprun/1.0/apprun/api/applications/{id}/traffics
アプリケーションに対してパケットフィルタを指定できます。
パケットフィルタを確認するには以下のような入力を行います。
# 入力サンプル
curl -u '01234567-89ab-cdef-0123-456789abcdef:SAMPLETOKENSAMPLETOKENSAMPLETOKENSAM' \
     -X GET \
     https://secure.sakura.ad.jp/cloud/api/apprun/1.0/apprun/api/applications/{id}/packet_filter
パケットフィルタを変更するには以下のような入力を行います。
# 入力サンプル
vi request_body.json
cat request_body.json
{
  "is_enabled": true,
  "settings": [
    {
      "from_ip": "198.51.100.2",
      "from_ip_prefix_length": 24
    }
  ]
}
curl -u '01234567-89ab-cdef-0123-456789abcdef:SAMPLETOKENSAMPLETOKENSAMPLETOKENSAM' \
     -X PATCH \
     -d '@request_body.json' \
     https://secure.sakura.ad.jp/cloud/api/apprun/1.0/apprun/api/applications/{id}/packet_filter
AppRunのアプリケーション一覧を取得します。
| page_num | integer  >= 1   Default:  1   Example:  page_num=20 表示したいページ番号  | 
| page_size | integer  [ 1 .. 100 ]   Default:  50   Example:  page_size=10 表示したい1ページあたりのサイズ  | 
| sort_field | string  Default:  "created_at"   Example:  sort_field=created_at ソートしたいフィールド名  | 
| sort_order | string  Default:  "desc"  Enum: "asc" "desc"    Example:  sort_order=asc ソート順(昇順、降順)  | 
{- "meta": {
- "page_num": 1,
 - "page_size": 100,
 - "object_total": 1000,
 - "sort_field": "created_at",
 - "sort_order": "asc"
 
}, - "data": [
- {
- "id": "u8FXIJ2LVM3wXVyzOEi",
 - "name": "アプリケーション1",
 - "status": "Healthy",
 - "created_at": "2019-08-24T14:15:22Z"
 
} 
] 
}AppRunにアプリケーションを作成します。
作成するアプリケーションの情報を入力します。
| name required  | string  [ 1 .. 255 ] characters   アプリケーション名  | 
| timeout_seconds required  | integer  [ 1 .. 300 ]   Default:  60  アプリケーションの公開URLにアクセスして、インスタンスが起動してからレスポンスが返るまでの時間制限  | 
| port required  | integer  [ 1 .. 65535 ]   アプリケーションがリクエストを待ち受けるポート番号。 ただし、8012, 8013, 8022, 9090, 9091, 8008 は予約済みのため設定不可。  | 
| min_scale required  | integer  [ 0 .. 10 ]   Default:  0  アプリケーション全体の最小スケール数  | 
| max_scale required  | integer  [ 1 .. 10 ]   Default:  10  アプリケーション全体の最大スケール数  | 
| scale_target_concurrency | integer  [ 50 .. 200 ]   Default:  100  アプリケーションのスケールの閾値の目安となる同時リクエスト数  | 
required  | Array of objects  アプリケーションのコンポーネント情報  | 
{- "name": "アプリケーション1",
 - "timeout_seconds": 60,
 - "port": 8080,
 - "min_scale": 0,
 - "max_scale": 2,
 - "scale_target_concurrency": 100,
 - "components": [
- {
- "name": "コンポーネント1",
 - "max_cpu": "0.1",
 - "max_memory": "256Mi",
 - "deploy_source": {
- "container_registry": {
- "image": "apprun-example.sakuracr.jp/helloworld:latest",
 - "server": "apprun-example.sakuracr.jp",
 - "username": "apprun",
 - "password": "apprun"
 
} 
}, - "env": [
- {
- "key": "MY_ENV",
 - "value": "my_value"
 
} 
], - "probe": {
- "http_get": {
- "path": "/healthz",
 - "port": 8080,
 - "headers": [
- {
- "name": "Custom-Header",
 - "value": "Awesome"
 
} 
] 
} 
} 
} 
] 
}{- "id": "u8FXIJ2LVM3wXVyzOEi",
 - "name": "アプリケーション1",
 - "timeout_seconds": 60,
 - "port": 8080,
 - "min_scale": 0,
 - "max_scale": 2,
 - "scale_target_concurrency": 100,
 - "components": [
- {
- "name": "コンポーネント1",
 - "max_cpu": "0.1",
 - "max_memory": "256Mi",
 - "deploy_source": {
- "container_registry": {
- "image": "apprun-example.sakuracr.jp/helloworld:latest",
 - "server": "apprun-example.sakuracr.jp",
 - "username": "apprun"
 
} 
}, - "env": [
- {
- "key": "MY_ENV",
 - "value": "my_value"
 
} 
], - "probe": {
- "http_get": {
- "path": "/healthz",
 - "port": 8080,
 - "headers": [
- {
- "name": "Custom-Header",
 - "value": "Awesome"
 
} 
] 
} 
} 
} 
], - "status": "Healthy",
 - "resource_id": "100000000000",
 - "created_at": "2019-08-24T14:15:22Z"
 
}{- "id": "u8FXIJ2LVM3wXVyzOEi",
 - "name": "アプリケーション1",
 - "timeout_seconds": 60,
 - "port": 8080,
 - "min_scale": 0,
 - "max_scale": 2,
 - "scale_target_concurrency": 100,
 - "components": [
- {
- "name": "コンポーネント1",
 - "max_cpu": "0.1",
 - "max_memory": "256Mi",
 - "deploy_source": {
- "container_registry": {
- "image": "apprun-example.sakuracr.jp/helloworld:latest",
 - "server": "apprun-example.sakuracr.jp",
 - "username": "apprun"
 
} 
}, - "env": [
- {
- "key": "MY_ENV",
 - "value": "my_value"
 
} 
], - "probe": {
- "http_get": {
- "path": "/healthz",
 - "port": 8080,
 - "headers": [
- {
- "name": "Custom-Header",
 - "value": "Awesome"
 
} 
] 
} 
} 
} 
], - "status": "Healthy",
 - "resource_id": "100000000000",
 - "created_at": "2019-08-24T14:15:22Z"
 
}AppRunのアプリケーションを部分的に変更します。
| id required  | string   | 
部分的に変更するアプリケーションの情報を入力します。
| timeout_seconds | integer  [ 1 .. 300 ]   アプリケーションの公開URLにアクセスして、インスタンスが起動してからレスポンスが返るまでの時間制限  | 
| port | integer  [ 1 .. 65535 ]   アプリケーションがリクエストを待ち受けるポート番号。 ただし、8012, 8013, 8022, 9090, 9091, 8008 は予約済みのため設定不可。  | 
| min_scale | integer  [ 0 .. 10 ]   アプリケーション全体の最小スケール数  | 
| max_scale | integer  [ 1 .. 10 ]   アプリケーション全体の最大スケール数  | 
| scale_target_concurrency | integer  [ 50 .. 200 ]   アプリケーションのスケールの閾値の目安となる同時リクエスト数  | 
Array of objects  アプリケーションのコンポーネント情報  | |
| all_traffic_available | boolean  アプリケーションを最新のバージョンにすべてのトラフィックを割り当てるかどうか  | 
{- "timeout_seconds": 60,
 - "port": 8080,
 - "min_scale": 0,
 - "max_scale": 2,
 - "scale_target_concurrency": 100,
 - "components": [
- {
- "name": "コンポーネント1",
 - "max_cpu": "0.1",
 - "max_memory": "256Mi",
 - "deploy_source": {
- "container_registry": {
- "image": "apprun-example.sakuracr.jp/helloworld:latest",
 - "server": "apprun-example.sakuracr.jp",
 - "username": "apprun",
 - "password": "apprun"
 
} 
}, - "env": [
- {
- "key": "MY_ENV",
 - "value": "my_value"
 
} 
], - "probe": {
- "http_get": {
- "path": "/healthz",
 - "port": 8080,
 - "headers": [
- {
- "name": "Custom-Header",
 - "value": "Awesome"
 
} 
] 
} 
} 
} 
], - "all_traffic_available": true
 
}{- "id": "u8FXIJ2LVM3wXVyzOEi",
 - "name": "アプリケーション1",
 - "timeout_seconds": 60,
 - "port": 8080,
 - "min_scale": 0,
 - "max_scale": 2,
 - "scale_target_concurrency": 100,
 - "components": [
- {
- "name": "コンポーネント1",
 - "max_cpu": "0.1",
 - "max_memory": "256Mi",
 - "deploy_source": {
- "container_registry": {
- "image": "apprun-example.sakuracr.jp/helloworld:latest",
 - "server": "apprun-example.sakuracr.jp",
 - "username": "apprun"
 
} 
}, - "env": [
- {
- "key": "MY_ENV",
 - "value": "my_value"
 
} 
], - "probe": {
- "http_get": {
- "path": "/healthz",
 - "port": 8080,
 - "headers": [
- {
- "name": "Custom-Header",
 - "value": "Awesome"
 
} 
] 
} 
} 
} 
], - "status": "Healthy",
 - "resource_id": "100000000000",
 - "updated_at": "2019-08-24T14:15:22Z"
 
}{- "error": {
- "code": 401,
 - "message": "Login Required",
 - "errors": [
- {
- "domain": "global",
 - "reason": "required",
 - "message": "Login Required",
 - "location_type": "header",
 - "location": "Authorization"
 
} 
] 
} 
}AppRunのアプリケーショントラフィック分散を変更します。
| id required  | string   | 
トラフィック分散の割合を入力します。 version_nameまたはis_latest_versionのどちらかを指定して何%の割合でトラフィックを転送するかを入力します。
| is_latest_version required  | boolean  最新バージョンかどうか  | 
| percent required  | integer  トラフィック分散の割合  | 
[- {
- "is_latest_version": true,
 - "percent": 0
 
} 
]{- "meta": null,
 - "data": [
- {
- "version_name": "Version1",
 - "is_latest_version": true,
 - "percent": 100
 
} 
] 
}AppRunのアプリケーションバージョン一覧を取得します。
| id required  | string   | 
| page_num | integer  >= 1   Default:  1   Example:  page_num=20 表示したいページ番号  | 
| page_size | integer  [ 1 .. 100 ]   Default:  50   Example:  page_size=10 表示したい1ページあたりのサイズ  | 
| sort_field | string  Default:  "created_at"   Example:  sort_field=created_at ソートしたいフィールド名  | 
| sort_order | string  Default:  "desc"  Enum: "asc" "desc"    Example:  sort_order=asc ソート順(昇順、降順)  | 
{- "meta": {
- "page_num": 1,
 - "page_size": 100,
 - "object_total": 1000,
 - "sort_field": "created_at",
 - "sort_order": "asc"
 
}, - "data": [
- {
- "id": "BIi7jHVWGjg7NaxcK",
 - "name": "version-001",
 - "status": "Healthy",
 - "created_at": "2019-08-24T14:15:22Z"
 
} 
] 
}AppRunのアプリケーションバージョン詳細を取得します。
| id required  | string   | 
| version_id required  | string   | 
{- "id": "BIi7jHVWGjg7NaxcK",
 - "name": "version-001",
 - "status": "Healthy",
 - "timeout_seconds": 60,
 - "port": 8080,
 - "min_scale": 0,
 - "max_scale": 2,
 - "scale_target_concurrency": 100,
 - "components": [
- {
- "name": "コンポーネント1",
 - "max_cpu": "0.1",
 - "max_memory": "256Mi",
 - "deploy_source": {
- "container_registry": {
- "image": "apprun-example.sakuracr.jp/helloworld:latest",
 - "server": "apprun-example.sakuracr.jp",
 - "username": "apprun"
 
} 
}, - "env": [
- {
- "key": "MY_ENV",
 - "value": "my_value"
 
} 
], - "probe": {
- "http_get": {
- "path": "/healthz",
 - "port": 8080,
 - "headers": [
- {
- "name": "Custom-Header",
 - "value": "Awesome"
 
} 
] 
} 
} 
} 
], - "created_at": "2019-08-24T14:15:22Z"
 
}AppRunのアプリケーションバージョンを削除します。
| id required  | string   | 
| version_id required  | string   | 
{- "error": {
- "code": 401,
 - "message": "Login Required",
 - "errors": [
- {
- "domain": "global",
 - "reason": "required",
 - "message": "Login Required",
 - "location_type": "header",
 - "location": "Authorization"
 
} 
] 
} 
}AppRunのパケットフィルタを部分的に変更します。
| id required  | string <uuid>    | 
部分的に変更するパケットフィルタの情報を入力します。
| is_enabled | boolean  有効フラグ  | 
Array of objects  <= 10 items    | 
{- "is_enabled": true,
 - "settings": [
- {
- "from_ip": "0.0.0.0",
 - "from_ip_prefix_length": 0
 
} 
] 
}{- "is_enabled": true,
 - "settings": [
- {
- "from_ip": "0.0.0.0",
 - "from_ip_prefix_length": 0
 
} 
] 
}