> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.xapi.to/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.xapi.to/_mcp/server.

# 全部 REST API 与测试

> **Warning**
>
> Test 与 Production Gateway 都会连接真实供应商并产生真实费用。执行创建接口前先获取报价
> 并设置预算上限；保存实例 ID，并始终在 `finally` 中调用终止接口。

#### [发现与报价](#发现与报价)

3 个接口：规格、环境与报价。

#### [实例生命周期](#实例生命周期)

6 个接口：列表、创建、详情、暂停、恢复与终止。

#### [执行与制品](#执行与制品)

6 个接口：Shell、文件、目录、端口与扩展。

#### [审计与历史](#审计与历史)

2 个接口：实例历史与四类审计流。

每个组件都包含方法、地址、路径参数、查询参数、请求体和发送按钮。使用接口上方的
**Production / Test** 标签，可在 `https://sandbox.xapi.to` 与
`https://sandbox.test.xapi.to` 之间切换；默认选择 Production，任一接口切换后，
本页其他接口会同步到相同环境。
需要身份的接口在组件内填写与所选环境对应的 `XAPI-Key`，测试 Key 与生产 Key 不要混用。

## Sandbox API 端到端测试流程

#### 无费用连通性检查

展开 **列出可用规格**，点击 **Try it → Send request**。预期 HTTP `200`，并确认目标
offering 的 `capabilities.exec=true`。这一步无需 Key，也不会创建资源。

#### 获取报价

展开 **获取 Sandbox 报价**，在 API Explorer 中填写 `XAPI-Key`，将
`requirements.capabilities` 设为 `exec, files`，并设置
`maxEstimatedHourlyUsd=0.20`。预期 HTTP `201`；复制响应中的 `quoteId`、
`expiresAt` 和 `estimatedHourlyUsd`。报价本身不创建实例。

#### 创建并保存实例 ID

展开 **创建 Sandbox 实例**，把上一步的 `quoteId` 填入 `selection.quoteId`，并把
`idempotencyKey` 改成你本次测试唯一的值，例如
`manual-browser-20260813-001`。预期 HTTP `202`；立即保存响应中的 `id`。
此时 `observedState=PROVISIONING` 仍不可执行任务。

#### 等待 RUNNING 并执行 marker

用 **查询实例详情** 每 2 秒查询同一个 `id`，直到 `observedState=RUNNING`。随后在
**执行 Shell 命令** 中执行 `printf 'MANUAL_TEST_OK=42\n'`。HTTP 应为 `201`，且
响应同时满足 `exitCode=0`、`stdout` 包含 `MANUAL_TEST_OK=42`。

#### 无论成功失败都终止

在 **销毁实例** 中填写相同实例 `id` 和新的动作幂等键。提交后继续查询详情，直到
`observedState=TERMINATED` 或终态 `FAILED`。关闭网页不能代替终止实例。

#### 检查审计、费用和残留

查询四类审计流：`operations` 中 CREATE/EXEC/TERMINATE 应成功，`events` 应覆盖
RUNNING 与终态，`usageSegments` 不应有开放段，`billingPeriods` 应全部结算。
最后以 `state=ACTIVE` 查询历史，确认没有本次活动实例。**账户实例快照**会保留
`TERMINATED` / `FAILED` 终态记录，不能用“列表非空”判断仍有资源运行。

> **Tip**
>
> API Explorer 里的 Key 只填在凭证输入框，不要写入请求 body、metadata、截图或文档源码。
> 发请求前再次核对 URL：页面默认使用 `https://sandbox.xapi.to`；只有明确执行测试验收时，
> 才切换到 `https://sandbox.test.xapi.to`。两个环境都会申请真实供应商资源并产生实际费用。

### 本地新版 CLI 一键验收

如果只想最快确认真实链路，当前未发布的新版 CLI 可从本地源码运行。它会自动执行
`quote → create → wait → exec → terminate → cost`：

```bash
cd /Users/daxiongya/Desktop/Projects/web3/x402/bsc/xapi-workspace/xapi-cli
npm run build

node dist/index.js sandbox run \
  --host sandbox.xapi.to \
  --capabilities exec,files \
  --max-hourly-usd 0.20 \
  --command 'printf "MANUAL_TEST_OK=42\n"' \
  --format pretty
```

通过时重点看：`readyState=RUNNING`、`result.exitCode=0`、marker 出现在 `stdout`、
`cleanup.state=TERMINATED`、`finalState=TERMINATED`，并记录服务端返回的 `totalCost`。

## 发现与报价

### 列出可用规格

无副作用、无需鉴权。用于查看当前资源、能力、生命周期和价格。

#### Production

### Request

GET [https://sandbox.xapi.to/v1/offerings](https://sandbox.xapi.to/v1/offerings)

```curl
curl https://sandbox.xapi.to/v1/offerings
```

```python
import requests

url = "https://sandbox.xapi.to/v1/offerings"

response = requests.get(url)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/offerings';
const options = {method: 'GET'};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/offerings"

	req, _ := http.NewRequest("GET", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/offerings")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://sandbox.xapi.to/v1/offerings")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://sandbox.xapi.to/v1/offerings');

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/offerings");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/offerings")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

#### Test

### Request

GET [https://sandbox.xapi.to/v1/offerings](https://sandbox.xapi.to/v1/offerings)

```curl
curl https://sandbox.xapi.to/v1/offerings
```

```python
import requests

url = "https://sandbox.xapi.to/v1/offerings"

response = requests.get(url)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/offerings';
const options = {method: 'GET'};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/offerings"

	req, _ := http.NewRequest("GET", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/offerings")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://sandbox.xapi.to/v1/offerings")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://sandbox.xapi.to/v1/offerings');

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/offerings");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/offerings")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 列出预置环境

无副作用、无需鉴权。返回当前可售 Offering 明确声明的运行时预置，用于选择
`requirements.environmentId`。返回 `[]` 表示当前没有服务商发布稳定的环境预置，
不是接口故障；此时省略 `environmentId`，改用 `capabilities`、CPU、内存、GPU 与区域选型。

#### Production

### Request

GET [https://sandbox.xapi.to/v1/environments](https://sandbox.xapi.to/v1/environments)

**`当前没有环境预置`**

```curl 当前没有环境预置
curl https://sandbox.xapi.to/v1/environments
```

**`当前没有环境预置`**

```python 当前没有环境预置
import requests

url = "https://sandbox.xapi.to/v1/environments"

response = requests.get(url)

print(response.json())
```

**`当前没有环境预置`**

```javascript 当前没有环境预置
const url = 'https://sandbox.xapi.to/v1/environments';
const options = {method: 'GET'};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**`当前没有环境预置`**

```go 当前没有环境预置
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/environments"

	req, _ := http.NewRequest("GET", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

**`当前没有环境预置`**

```ruby 当前没有环境预置
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/environments")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)

response = http.request(request)
puts response.read_body
```

**`当前没有环境预置`**

```java 当前没有环境预置
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://sandbox.xapi.to/v1/environments")
  .asString();
```

**`当前没有环境预置`**

```php 当前没有环境预置
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://sandbox.xapi.to/v1/environments');

echo $response->getBody();
```

**`当前没有环境预置`**

```csharp 当前没有环境预置
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/environments");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
```

**`当前没有环境预置`**

```swift 当前没有环境预置
import Foundation

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/environments")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

#### Test

### Request

GET [https://sandbox.xapi.to/v1/environments](https://sandbox.xapi.to/v1/environments)

**`当前没有环境预置`**

```curl 当前没有环境预置
curl https://sandbox.xapi.to/v1/environments
```

**`当前没有环境预置`**

```python 当前没有环境预置
import requests

url = "https://sandbox.xapi.to/v1/environments"

response = requests.get(url)

print(response.json())
```

**`当前没有环境预置`**

```javascript 当前没有环境预置
const url = 'https://sandbox.xapi.to/v1/environments';
const options = {method: 'GET'};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**`当前没有环境预置`**

```go 当前没有环境预置
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/environments"

	req, _ := http.NewRequest("GET", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

**`当前没有环境预置`**

```ruby 当前没有环境预置
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/environments")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)

response = http.request(request)
puts response.read_body
```

**`当前没有环境预置`**

```java 当前没有环境预置
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://sandbox.xapi.to/v1/environments")
  .asString();
```

**`当前没有环境预置`**

```php 当前没有环境预置
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://sandbox.xapi.to/v1/environments');

echo $response->getBody();
```

**`当前没有环境预置`**

```csharp 当前没有环境预置
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/environments");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
```

**`当前没有环境预置`**

```swift 当前没有环境预置
import Foundation

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/environments")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 获取 Sandbox 报价

需要鉴权，但不会创建实例。先设置 `maxEstimatedHourlyUsd`，保存返回的 `quoteId`。

#### Production

### Request

POST [https://sandbox.xapi.to/v1/quotes](https://sandbox.xapi.to/v1/quotes)

```curl
curl -X POST https://sandbox.xapi.to/v1/quotes \
     -H "XAPI-Key: <apiKey>" \
     -H "Content-Type: application/json" \
     -d '{
  "requirements": {
    "cpu": {
      "min": 1
    },
    "memoryGiB": {
      "min": 1
    },
    "capabilities": [
      "exec",
      "files"
    ]
  },
  "maxEstimatedHourlyUsd": "0.20"
}'
```

```python
import requests

url = "https://sandbox.xapi.to/v1/quotes"

payload = {
    "requirements": {
        "cpu": { "min": 1 },
        "memoryGiB": { "min": 1 },
        "capabilities": ["exec", "files"]
    },
    "maxEstimatedHourlyUsd": "0.20"
}
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/quotes';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"requirements":{"cpu":{"min":1},"memoryGiB":{"min":1},"capabilities":["exec","files"]},"maxEstimatedHourlyUsd":"0.20"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/quotes"

	payload := strings.NewReader("{\n  \"requirements\": {\n    \"cpu\": {\n      \"min\": 1\n    },\n    \"memoryGiB\": {\n      \"min\": 1\n    },\n    \"capabilities\": [\n      \"exec\",\n      \"files\"\n    ]\n  },\n  \"maxEstimatedHourlyUsd\": \"0.20\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/quotes")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"requirements\": {\n    \"cpu\": {\n      \"min\": 1\n    },\n    \"memoryGiB\": {\n      \"min\": 1\n    },\n    \"capabilities\": [\n      \"exec\",\n      \"files\"\n    ]\n  },\n  \"maxEstimatedHourlyUsd\": \"0.20\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/quotes")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"requirements\": {\n    \"cpu\": {\n      \"min\": 1\n    },\n    \"memoryGiB\": {\n      \"min\": 1\n    },\n    \"capabilities\": [\n      \"exec\",\n      \"files\"\n    ]\n  },\n  \"maxEstimatedHourlyUsd\": \"0.20\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/quotes', [
  'body' => '{
  "requirements": {
    "cpu": {
      "min": 1
    },
    "memoryGiB": {
      "min": 1
    },
    "capabilities": [
      "exec",
      "files"
    ]
  },
  "maxEstimatedHourlyUsd": "0.20"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/quotes");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"requirements\": {\n    \"cpu\": {\n      \"min\": 1\n    },\n    \"memoryGiB\": {\n      \"min\": 1\n    },\n    \"capabilities\": [\n      \"exec\",\n      \"files\"\n    ]\n  },\n  \"maxEstimatedHourlyUsd\": \"0.20\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "requirements": [
    "cpu": ["min": 1],
    "memoryGiB": ["min": 1],
    "capabilities": ["exec", "files"]
  ],
  "maxEstimatedHourlyUsd": "0.20"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/quotes")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

#### Test

### Request

POST [https://sandbox.xapi.to/v1/quotes](https://sandbox.xapi.to/v1/quotes)

```curl
curl -X POST https://sandbox.xapi.to/v1/quotes \
     -H "XAPI-Key: <apiKey>" \
     -H "Content-Type: application/json" \
     -d '{
  "requirements": {
    "cpu": {
      "min": 1
    },
    "memoryGiB": {
      "min": 1
    },
    "capabilities": [
      "exec",
      "files"
    ]
  },
  "maxEstimatedHourlyUsd": "0.20"
}'
```

```python
import requests

url = "https://sandbox.xapi.to/v1/quotes"

payload = {
    "requirements": {
        "cpu": { "min": 1 },
        "memoryGiB": { "min": 1 },
        "capabilities": ["exec", "files"]
    },
    "maxEstimatedHourlyUsd": "0.20"
}
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/quotes';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"requirements":{"cpu":{"min":1},"memoryGiB":{"min":1},"capabilities":["exec","files"]},"maxEstimatedHourlyUsd":"0.20"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/quotes"

	payload := strings.NewReader("{\n  \"requirements\": {\n    \"cpu\": {\n      \"min\": 1\n    },\n    \"memoryGiB\": {\n      \"min\": 1\n    },\n    \"capabilities\": [\n      \"exec\",\n      \"files\"\n    ]\n  },\n  \"maxEstimatedHourlyUsd\": \"0.20\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/quotes")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"requirements\": {\n    \"cpu\": {\n      \"min\": 1\n    },\n    \"memoryGiB\": {\n      \"min\": 1\n    },\n    \"capabilities\": [\n      \"exec\",\n      \"files\"\n    ]\n  },\n  \"maxEstimatedHourlyUsd\": \"0.20\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/quotes")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"requirements\": {\n    \"cpu\": {\n      \"min\": 1\n    },\n    \"memoryGiB\": {\n      \"min\": 1\n    },\n    \"capabilities\": [\n      \"exec\",\n      \"files\"\n    ]\n  },\n  \"maxEstimatedHourlyUsd\": \"0.20\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/quotes', [
  'body' => '{
  "requirements": {
    "cpu": {
      "min": 1
    },
    "memoryGiB": {
      "min": 1
    },
    "capabilities": [
      "exec",
      "files"
    ]
  },
  "maxEstimatedHourlyUsd": "0.20"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/quotes");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"requirements\": {\n    \"cpu\": {\n      \"min\": 1\n    },\n    \"memoryGiB\": {\n      \"min\": 1\n    },\n    \"capabilities\": [\n      \"exec\",\n      \"files\"\n    ]\n  },\n  \"maxEstimatedHourlyUsd\": \"0.20\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "requirements": [
    "cpu": ["min": 1],
    "memoryGiB": ["min": 1],
    "capabilities": ["exec", "files"]
  ],
  "maxEstimatedHourlyUsd": "0.20"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/quotes")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

## 实例生命周期

> **Warning**
>
> 从本组开始会读取或改变账户资源。创建后必须记录实例 ID，并在所有成功、失败和中断路径中终止。

### 列出账户实例快照

返回账户全部实例，包括终态记录。零残留检查请使用下方历史接口的 `state=ACTIVE`。

#### Production

### Request

GET [https://sandbox.xapi.to/v1/sandboxes](https://sandbox.xapi.to/v1/sandboxes)

```curl
curl https://sandbox.xapi.to/v1/sandboxes \
     -H "XAPI-Key: <apiKey>"
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes"

headers = {"XAPI-Key": "<apiKey>"}

response = requests.get(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes';
const options = {method: 'GET', headers: {'XAPI-Key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("XAPI-Key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["XAPI-Key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://sandbox.xapi.to/v1/sandboxes")
  .header("XAPI-Key", "<apiKey>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://sandbox.xapi.to/v1/sandboxes', [
  'headers' => [
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes");
var request = new RestRequest(Method.GET);
request.AddHeader("XAPI-Key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["XAPI-Key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

#### Test

### Request

GET [https://sandbox.xapi.to/v1/sandboxes](https://sandbox.xapi.to/v1/sandboxes)

```curl
curl https://sandbox.xapi.to/v1/sandboxes \
     -H "XAPI-Key: <apiKey>"
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes"

headers = {"XAPI-Key": "<apiKey>"}

response = requests.get(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes';
const options = {method: 'GET', headers: {'XAPI-Key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("XAPI-Key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["XAPI-Key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://sandbox.xapi.to/v1/sandboxes")
  .header("XAPI-Key", "<apiKey>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://sandbox.xapi.to/v1/sandboxes', [
  'headers' => [
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes");
var request = new RestRequest(Method.GET);
request.AddHeader("XAPI-Key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["XAPI-Key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 创建 Sandbox 实例

返回 `202` 只代表请求已接受。重试同一创建必须复用 `idempotencyKey`。

#### Production

### Request

POST [https://sandbox.xapi.to/v1/sandboxes](https://sandbox.xapi.to/v1/sandboxes)

**`使用 quoteId 创建（推荐）`**

```curl 使用 quoteId 创建（推荐）
curl -X POST https://sandbox.xapi.to/v1/sandboxes \
     -H "XAPI-Key: <apiKey>" \
     -H "Content-Type: application/json" \
     -d '{
  "selection": {
    "quoteId": "REPLACE_WITH_QUOTE_ID"
  },
  "idempotencyKey": "docs-create-quote-20260813-001",
  "policy": {
    "resumeOnAccess": false
  },
  "metadata": {
    "client": "fern-docs",
    "purpose": "sandbox-api-test"
  }
}'
```

**`使用 quoteId 创建（推荐）`**

```python 使用 quoteId 创建（推荐）
import requests

url = "https://sandbox.xapi.to/v1/sandboxes"

payload = {
    "selection": { "quoteId": "REPLACE_WITH_QUOTE_ID" },
    "idempotencyKey": "docs-create-quote-20260813-001",
    "policy": { "resumeOnAccess": False },
    "metadata": {
        "client": "fern-docs",
        "purpose": "sandbox-api-test"
    }
}
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

**`使用 quoteId 创建（推荐）`**

```javascript 使用 quoteId 创建（推荐）
const url = 'https://sandbox.xapi.to/v1/sandboxes';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"selection":{"quoteId":"REPLACE_WITH_QUOTE_ID"},"idempotencyKey":"docs-create-quote-20260813-001","policy":{"resumeOnAccess":false},"metadata":{"client":"fern-docs","purpose":"sandbox-api-test"}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**`使用 quoteId 创建（推荐）`**

```go 使用 quoteId 创建（推荐）
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes"

	payload := strings.NewReader("{\n  \"selection\": {\n    \"quoteId\": \"REPLACE_WITH_QUOTE_ID\"\n  },\n  \"idempotencyKey\": \"docs-create-quote-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"sandbox-api-test\"\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

**`使用 quoteId 创建（推荐）`**

```ruby 使用 quoteId 创建（推荐）
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"selection\": {\n    \"quoteId\": \"REPLACE_WITH_QUOTE_ID\"\n  },\n  \"idempotencyKey\": \"docs-create-quote-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"sandbox-api-test\"\n  }\n}"

response = http.request(request)
puts response.read_body
```

**`使用 quoteId 创建（推荐）`**

```java 使用 quoteId 创建（推荐）
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/sandboxes")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"selection\": {\n    \"quoteId\": \"REPLACE_WITH_QUOTE_ID\"\n  },\n  \"idempotencyKey\": \"docs-create-quote-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"sandbox-api-test\"\n  }\n}")
  .asString();
```

**`使用 quoteId 创建（推荐）`**

```php 使用 quoteId 创建（推荐）
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/sandboxes', [
  'body' => '{
  "selection": {
    "quoteId": "REPLACE_WITH_QUOTE_ID"
  },
  "idempotencyKey": "docs-create-quote-20260813-001",
  "policy": {
    "resumeOnAccess": false
  },
  "metadata": {
    "client": "fern-docs",
    "purpose": "sandbox-api-test"
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

**`使用 quoteId 创建（推荐）`**

```csharp 使用 quoteId 创建（推荐）
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"selection\": {\n    \"quoteId\": \"REPLACE_WITH_QUOTE_ID\"\n  },\n  \"idempotencyKey\": \"docs-create-quote-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"sandbox-api-test\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

**`使用 quoteId 创建（推荐）`**

```swift 使用 quoteId 创建（推荐）
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "selection": ["quoteId": "REPLACE_WITH_QUOTE_ID"],
  "idempotencyKey": "docs-create-quote-20260813-001",
  "policy": ["resumeOnAccess": false],
  "metadata": [
    "client": "fern-docs",
    "purpose": "sandbox-api-test"
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

#### Test

### Request

POST [https://sandbox.xapi.to/v1/sandboxes](https://sandbox.xapi.to/v1/sandboxes)

**`使用 quoteId 创建（推荐）`**

```curl 使用 quoteId 创建（推荐）
curl -X POST https://sandbox.xapi.to/v1/sandboxes \
     -H "XAPI-Key: <apiKey>" \
     -H "Content-Type: application/json" \
     -d '{
  "selection": {
    "quoteId": "REPLACE_WITH_QUOTE_ID"
  },
  "idempotencyKey": "docs-create-quote-20260813-001",
  "policy": {
    "resumeOnAccess": false
  },
  "metadata": {
    "client": "fern-docs",
    "purpose": "sandbox-api-test"
  }
}'
```

**`使用 quoteId 创建（推荐）`**

```python 使用 quoteId 创建（推荐）
import requests

url = "https://sandbox.xapi.to/v1/sandboxes"

payload = {
    "selection": { "quoteId": "REPLACE_WITH_QUOTE_ID" },
    "idempotencyKey": "docs-create-quote-20260813-001",
    "policy": { "resumeOnAccess": False },
    "metadata": {
        "client": "fern-docs",
        "purpose": "sandbox-api-test"
    }
}
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

**`使用 quoteId 创建（推荐）`**

```javascript 使用 quoteId 创建（推荐）
const url = 'https://sandbox.xapi.to/v1/sandboxes';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"selection":{"quoteId":"REPLACE_WITH_QUOTE_ID"},"idempotencyKey":"docs-create-quote-20260813-001","policy":{"resumeOnAccess":false},"metadata":{"client":"fern-docs","purpose":"sandbox-api-test"}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**`使用 quoteId 创建（推荐）`**

```go 使用 quoteId 创建（推荐）
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes"

	payload := strings.NewReader("{\n  \"selection\": {\n    \"quoteId\": \"REPLACE_WITH_QUOTE_ID\"\n  },\n  \"idempotencyKey\": \"docs-create-quote-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"sandbox-api-test\"\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

**`使用 quoteId 创建（推荐）`**

```ruby 使用 quoteId 创建（推荐）
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"selection\": {\n    \"quoteId\": \"REPLACE_WITH_QUOTE_ID\"\n  },\n  \"idempotencyKey\": \"docs-create-quote-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"sandbox-api-test\"\n  }\n}"

response = http.request(request)
puts response.read_body
```

**`使用 quoteId 创建（推荐）`**

```java 使用 quoteId 创建（推荐）
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/sandboxes")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"selection\": {\n    \"quoteId\": \"REPLACE_WITH_QUOTE_ID\"\n  },\n  \"idempotencyKey\": \"docs-create-quote-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"sandbox-api-test\"\n  }\n}")
  .asString();
```

**`使用 quoteId 创建（推荐）`**

```php 使用 quoteId 创建（推荐）
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/sandboxes', [
  'body' => '{
  "selection": {
    "quoteId": "REPLACE_WITH_QUOTE_ID"
  },
  "idempotencyKey": "docs-create-quote-20260813-001",
  "policy": {
    "resumeOnAccess": false
  },
  "metadata": {
    "client": "fern-docs",
    "purpose": "sandbox-api-test"
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

**`使用 quoteId 创建（推荐）`**

```csharp 使用 quoteId 创建（推荐）
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"selection\": {\n    \"quoteId\": \"REPLACE_WITH_QUOTE_ID\"\n  },\n  \"idempotencyKey\": \"docs-create-quote-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"sandbox-api-test\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

**`使用 quoteId 创建（推荐）`**

```swift 使用 quoteId 创建（推荐）
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "selection": ["quoteId": "REPLACE_WITH_QUOTE_ID"],
  "idempotencyKey": "docs-create-quote-20260813-001",
  "policy": ["resumeOnAccess": false],
  "metadata": [
    "client": "fern-docs",
    "purpose": "sandbox-api-test"
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 查询实例详情

轮询到 `observedState=RUNNING` 后再执行命令或文件操作。

#### Production

### Request

GET [https://sandbox.xapi.to/v1/sandboxes/\{id}](https://sandbox.xapi.to/v1/sandboxes/\{id})

```curl
curl https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333 \
     -H "XAPI-Key: <apiKey>"
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333"

headers = {"XAPI-Key": "<apiKey>"}

response = requests.get(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333';
const options = {method: 'GET', headers: {'XAPI-Key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("XAPI-Key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["XAPI-Key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333")
  .header("XAPI-Key", "<apiKey>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333', [
  'headers' => [
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333");
var request = new RestRequest(Method.GET);
request.AddHeader("XAPI-Key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["XAPI-Key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

#### Test

### Request

GET [https://sandbox.xapi.to/v1/sandboxes/\{id}](https://sandbox.xapi.to/v1/sandboxes/\{id})

```curl
curl https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333 \
     -H "XAPI-Key: <apiKey>"
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333"

headers = {"XAPI-Key": "<apiKey>"}

response = requests.get(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333';
const options = {method: 'GET', headers: {'XAPI-Key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("XAPI-Key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["XAPI-Key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333")
  .header("XAPI-Key", "<apiKey>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333', [
  'headers' => [
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333");
var request = new RestRequest(Method.GET);
request.AddHeader("XAPI-Key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["XAPI-Key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 暂停实例

仅在 offering 声明支持 suspension 时使用。

#### Production

### Request

POST [https://sandbox.xapi.to/v1/sandboxes/\{id}/suspend](https://sandbox.xapi.to/v1/sandboxes/\{id}/suspend)

```curl
curl -X POST https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/suspend \
     -H "XAPI-Key: <apiKey>" \
     -H "Content-Type: application/json" \
     -d '{
  "idempotencyKey": "docs-suspend-example"
}'
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/suspend"

payload = { "idempotencyKey": "docs-suspend-example" }
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/suspend';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"idempotencyKey":"docs-suspend-example"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/suspend"

	payload := strings.NewReader("{\n  \"idempotencyKey\": \"docs-suspend-example\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/suspend")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"idempotencyKey\": \"docs-suspend-example\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/suspend")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"idempotencyKey\": \"docs-suspend-example\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/suspend', [
  'body' => '{
  "idempotencyKey": "docs-suspend-example"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/suspend");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"idempotencyKey\": \"docs-suspend-example\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["idempotencyKey": "docs-suspend-example"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/suspend")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

#### Test

### Request

POST [https://sandbox.xapi.to/v1/sandboxes/\{id}/suspend](https://sandbox.xapi.to/v1/sandboxes/\{id}/suspend)

```curl
curl -X POST https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/suspend \
     -H "XAPI-Key: <apiKey>" \
     -H "Content-Type: application/json" \
     -d '{
  "idempotencyKey": "docs-suspend-example"
}'
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/suspend"

payload = { "idempotencyKey": "docs-suspend-example" }
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/suspend';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"idempotencyKey":"docs-suspend-example"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/suspend"

	payload := strings.NewReader("{\n  \"idempotencyKey\": \"docs-suspend-example\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/suspend")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"idempotencyKey\": \"docs-suspend-example\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/suspend")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"idempotencyKey\": \"docs-suspend-example\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/suspend', [
  'body' => '{
  "idempotencyKey": "docs-suspend-example"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/suspend");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"idempotencyKey\": \"docs-suspend-example\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["idempotencyKey": "docs-suspend-example"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/suspend")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 恢复实例

恢复后继续查询详情，直到实例重新进入 `RUNNING`。

#### Production

### Request

POST [https://sandbox.xapi.to/v1/sandboxes/\{id}/resume](https://sandbox.xapi.to/v1/sandboxes/\{id}/resume)

```curl
curl -X POST https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/resume \
     -H "XAPI-Key: <apiKey>" \
     -H "Content-Type: application/json" \
     -d '{
  "idempotencyKey": "docs-resume-example"
}'
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/resume"

payload = { "idempotencyKey": "docs-resume-example" }
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/resume';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"idempotencyKey":"docs-resume-example"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/resume"

	payload := strings.NewReader("{\n  \"idempotencyKey\": \"docs-resume-example\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/resume")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"idempotencyKey\": \"docs-resume-example\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/resume")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"idempotencyKey\": \"docs-resume-example\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/resume', [
  'body' => '{
  "idempotencyKey": "docs-resume-example"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/resume");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"idempotencyKey\": \"docs-resume-example\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["idempotencyKey": "docs-resume-example"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/resume")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

#### Test

### Request

POST [https://sandbox.xapi.to/v1/sandboxes/\{id}/resume](https://sandbox.xapi.to/v1/sandboxes/\{id}/resume)

```curl
curl -X POST https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/resume \
     -H "XAPI-Key: <apiKey>" \
     -H "Content-Type: application/json" \
     -d '{
  "idempotencyKey": "docs-resume-example"
}'
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/resume"

payload = { "idempotencyKey": "docs-resume-example" }
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/resume';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"idempotencyKey":"docs-resume-example"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/resume"

	payload := strings.NewReader("{\n  \"idempotencyKey\": \"docs-resume-example\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/resume")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"idempotencyKey\": \"docs-resume-example\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/resume")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"idempotencyKey\": \"docs-resume-example\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/resume', [
  'body' => '{
  "idempotencyKey": "docs-resume-example"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/resume");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"idempotencyKey\": \"docs-resume-example\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["idempotencyKey": "docs-resume-example"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/resume")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 终止实例

放入 `finally`，提交后继续等待 `TERMINATED` 或供应商终态 `FAILED`。

#### Production

### Request

POST [https://sandbox.xapi.to/v1/sandboxes/\{id}/terminate](https://sandbox.xapi.to/v1/sandboxes/\{id}/terminate)

```curl
curl -X POST https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/terminate \
     -H "XAPI-Key: <apiKey>" \
     -H "Content-Type: application/json" \
     -d '{
  "idempotencyKey": "docs-terminate-example"
}'
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/terminate"

payload = { "idempotencyKey": "docs-terminate-example" }
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/terminate';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"idempotencyKey":"docs-terminate-example"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/terminate"

	payload := strings.NewReader("{\n  \"idempotencyKey\": \"docs-terminate-example\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/terminate")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"idempotencyKey\": \"docs-terminate-example\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/terminate")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"idempotencyKey\": \"docs-terminate-example\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/terminate', [
  'body' => '{
  "idempotencyKey": "docs-terminate-example"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/terminate");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"idempotencyKey\": \"docs-terminate-example\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["idempotencyKey": "docs-terminate-example"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/terminate")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

#### Test

### Request

POST [https://sandbox.xapi.to/v1/sandboxes/\{id}/terminate](https://sandbox.xapi.to/v1/sandboxes/\{id}/terminate)

```curl
curl -X POST https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/terminate \
     -H "XAPI-Key: <apiKey>" \
     -H "Content-Type: application/json" \
     -d '{
  "idempotencyKey": "docs-terminate-example"
}'
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/terminate"

payload = { "idempotencyKey": "docs-terminate-example" }
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/terminate';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"idempotencyKey":"docs-terminate-example"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/terminate"

	payload := strings.NewReader("{\n  \"idempotencyKey\": \"docs-terminate-example\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/terminate")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"idempotencyKey\": \"docs-terminate-example\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/terminate")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"idempotencyKey\": \"docs-terminate-example\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/terminate', [
  'body' => '{
  "idempotencyKey": "docs-terminate-example"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/terminate");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"idempotencyKey\": \"docs-terminate-example\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["idempotencyKey": "docs-terminate-example"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/terminate")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

## 执行与制品

### 执行 Shell 命令

HTTP 成功并不等于命令成功；还必须检查 `exitCode=0`。

需要启动 Web 服务等长驻进程时，先确认 Offering 返回
`capabilities.backgroundExec=true`，再传 `background=true`。这会创建供应商托管的后台会话；
普通命令不要开启。后台响应只证明会话已接受，仍需轮询应用健康地址确认服务真正就绪。

#### Production

### Request

POST [https://sandbox.xapi.to/v1/sandboxes/\{id}/commands](https://sandbox.xapi.to/v1/sandboxes/\{id}/commands)

**`验证 Shell 输出`**

```curl 验证 Shell 输出
curl -X POST https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/commands \
     -H "XAPI-Key: <apiKey>" \
     -H "Content-Type: application/json" \
     -d '{
  "command": "python3 -c \"print('\''XAPI_SANDBOX_OK=42'\'')\"",
  "timeoutSeconds": 60
}'
```

**`验证 Shell 输出`**

```python 验证 Shell 输出
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/commands"

payload = {
    "command": "python3 -c \"print('XAPI_SANDBOX_OK=42')\"",
    "timeoutSeconds": 60
}
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

**`验证 Shell 输出`**

```javascript 验证 Shell 输出
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/commands';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"command":"python3 -c \"print(\'XAPI_SANDBOX_OK=42\')\"","timeoutSeconds":60}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**`验证 Shell 输出`**

```go 验证 Shell 输出
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/commands"

	payload := strings.NewReader("{\n  \"command\": \"python3 -c \\\"print('XAPI_SANDBOX_OK=42')\\\"\",\n  \"timeoutSeconds\": 60\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

**`验证 Shell 输出`**

```ruby 验证 Shell 输出
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/commands")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"command\": \"python3 -c \\\"print('XAPI_SANDBOX_OK=42')\\\"\",\n  \"timeoutSeconds\": 60\n}"

response = http.request(request)
puts response.read_body
```

**`验证 Shell 输出`**

```java 验证 Shell 输出
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/commands")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"command\": \"python3 -c \\\"print('XAPI_SANDBOX_OK=42')\\\"\",\n  \"timeoutSeconds\": 60\n}")
  .asString();
```

**`验证 Shell 输出`**

```php 验证 Shell 输出
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/commands', [
  'body' => '{
  "command": "python3 -c \\"print(\'XAPI_SANDBOX_OK=42\')\\"",
  "timeoutSeconds": 60
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

**`验证 Shell 输出`**

```csharp 验证 Shell 输出
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/commands");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"command\": \"python3 -c \\\"print('XAPI_SANDBOX_OK=42')\\\"\",\n  \"timeoutSeconds\": 60\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

**`验证 Shell 输出`**

```swift 验证 Shell 输出
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "command": "python3 -c \"print('XAPI_SANDBOX_OK=42')\"",
  "timeoutSeconds": 60
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/commands")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

#### Test

### Request

POST [https://sandbox.xapi.to/v1/sandboxes/\{id}/commands](https://sandbox.xapi.to/v1/sandboxes/\{id}/commands)

**`验证 Shell 输出`**

```curl 验证 Shell 输出
curl -X POST https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/commands \
     -H "XAPI-Key: <apiKey>" \
     -H "Content-Type: application/json" \
     -d '{
  "command": "python3 -c \"print('\''XAPI_SANDBOX_OK=42'\'')\"",
  "timeoutSeconds": 60
}'
```

**`验证 Shell 输出`**

```python 验证 Shell 输出
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/commands"

payload = {
    "command": "python3 -c \"print('XAPI_SANDBOX_OK=42')\"",
    "timeoutSeconds": 60
}
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

**`验证 Shell 输出`**

```javascript 验证 Shell 输出
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/commands';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"command":"python3 -c \"print(\'XAPI_SANDBOX_OK=42\')\"","timeoutSeconds":60}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**`验证 Shell 输出`**

```go 验证 Shell 输出
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/commands"

	payload := strings.NewReader("{\n  \"command\": \"python3 -c \\\"print('XAPI_SANDBOX_OK=42')\\\"\",\n  \"timeoutSeconds\": 60\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

**`验证 Shell 输出`**

```ruby 验证 Shell 输出
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/commands")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"command\": \"python3 -c \\\"print('XAPI_SANDBOX_OK=42')\\\"\",\n  \"timeoutSeconds\": 60\n}"

response = http.request(request)
puts response.read_body
```

**`验证 Shell 输出`**

```java 验证 Shell 输出
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/commands")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"command\": \"python3 -c \\\"print('XAPI_SANDBOX_OK=42')\\\"\",\n  \"timeoutSeconds\": 60\n}")
  .asString();
```

**`验证 Shell 输出`**

```php 验证 Shell 输出
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/commands', [
  'body' => '{
  "command": "python3 -c \\"print(\'XAPI_SANDBOX_OK=42\')\\"",
  "timeoutSeconds": 60
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

**`验证 Shell 输出`**

```csharp 验证 Shell 输出
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/commands");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"command\": \"python3 -c \\\"print('XAPI_SANDBOX_OK=42')\\\"\",\n  \"timeoutSeconds\": 60\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

**`验证 Shell 输出`**

```swift 验证 Shell 输出
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "command": "python3 -c \"print('XAPI_SANDBOX_OK=42')\"",
  "timeoutSeconds": 60
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/commands")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 写入文件

#### Production

### Request

POST [https://sandbox.xapi.to/v1/sandboxes/\{id}/files](https://sandbox.xapi.to/v1/sandboxes/\{id}/files)

```curl
curl -X POST https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files \
     -H "XAPI-Key: <apiKey>" \
     -H "Content-Type: application/json" \
     -d '{
  "path": "input.txt",
  "content": "Hello from the xAPI Sandbox API Explorer.",
  "encoding": "utf8"
}'
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files"

payload = {
    "path": "input.txt",
    "content": "Hello from the xAPI Sandbox API Explorer.",
    "encoding": "utf8"
}
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"path":"input.txt","content":"Hello from the xAPI Sandbox API Explorer.","encoding":"utf8"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files"

	payload := strings.NewReader("{\n  \"path\": \"input.txt\",\n  \"content\": \"Hello from the xAPI Sandbox API Explorer.\",\n  \"encoding\": \"utf8\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"path\": \"input.txt\",\n  \"content\": \"Hello from the xAPI Sandbox API Explorer.\",\n  \"encoding\": \"utf8\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"path\": \"input.txt\",\n  \"content\": \"Hello from the xAPI Sandbox API Explorer.\",\n  \"encoding\": \"utf8\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files', [
  'body' => '{
  "path": "input.txt",
  "content": "Hello from the xAPI Sandbox API Explorer.",
  "encoding": "utf8"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"path\": \"input.txt\",\n  \"content\": \"Hello from the xAPI Sandbox API Explorer.\",\n  \"encoding\": \"utf8\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "path": "input.txt",
  "content": "Hello from the xAPI Sandbox API Explorer.",
  "encoding": "utf8"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

#### Test

### Request

POST [https://sandbox.xapi.to/v1/sandboxes/\{id}/files](https://sandbox.xapi.to/v1/sandboxes/\{id}/files)

```curl
curl -X POST https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files \
     -H "XAPI-Key: <apiKey>" \
     -H "Content-Type: application/json" \
     -d '{
  "path": "input.txt",
  "content": "Hello from the xAPI Sandbox API Explorer.",
  "encoding": "utf8"
}'
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files"

payload = {
    "path": "input.txt",
    "content": "Hello from the xAPI Sandbox API Explorer.",
    "encoding": "utf8"
}
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"path":"input.txt","content":"Hello from the xAPI Sandbox API Explorer.","encoding":"utf8"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files"

	payload := strings.NewReader("{\n  \"path\": \"input.txt\",\n  \"content\": \"Hello from the xAPI Sandbox API Explorer.\",\n  \"encoding\": \"utf8\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"path\": \"input.txt\",\n  \"content\": \"Hello from the xAPI Sandbox API Explorer.\",\n  \"encoding\": \"utf8\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"path\": \"input.txt\",\n  \"content\": \"Hello from the xAPI Sandbox API Explorer.\",\n  \"encoding\": \"utf8\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files', [
  'body' => '{
  "path": "input.txt",
  "content": "Hello from the xAPI Sandbox API Explorer.",
  "encoding": "utf8"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"path\": \"input.txt\",\n  \"content\": \"Hello from the xAPI Sandbox API Explorer.\",\n  \"encoding\": \"utf8\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "path": "input.txt",
  "content": "Hello from the xAPI Sandbox API Explorer.",
  "encoding": "utf8"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 读取文件

#### Production

### Request

GET [https://sandbox.xapi.to/v1/sandboxes/\{id}/files](https://sandbox.xapi.to/v1/sandboxes/\{id}/files)

```curl
curl -G https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files \
     -H "XAPI-Key: <apiKey>" \
     -d encoding=utf8 \
     -d path=result.txt
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files"

querystring = {"encoding":"utf8","path":"result.txt"}

headers = {"XAPI-Key": "<apiKey>"}

response = requests.get(url, headers=headers, params=querystring)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files?encoding=utf8&path=result.txt';
const options = {method: 'GET', headers: {'XAPI-Key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files?encoding=utf8&path=result.txt"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("XAPI-Key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files?encoding=utf8&path=result.txt")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["XAPI-Key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files?encoding=utf8&path=result.txt")
  .header("XAPI-Key", "<apiKey>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files?encoding=utf8&path=result.txt', [
  'headers' => [
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files?encoding=utf8&path=result.txt");
var request = new RestRequest(Method.GET);
request.AddHeader("XAPI-Key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["XAPI-Key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files?encoding=utf8&path=result.txt")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

#### Test

### Request

GET [https://sandbox.xapi.to/v1/sandboxes/\{id}/files](https://sandbox.xapi.to/v1/sandboxes/\{id}/files)

```curl
curl -G https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files \
     -H "XAPI-Key: <apiKey>" \
     -d encoding=utf8 \
     -d path=result.txt
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files"

querystring = {"encoding":"utf8","path":"result.txt"}

headers = {"XAPI-Key": "<apiKey>"}

response = requests.get(url, headers=headers, params=querystring)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files?encoding=utf8&path=result.txt';
const options = {method: 'GET', headers: {'XAPI-Key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files?encoding=utf8&path=result.txt"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("XAPI-Key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files?encoding=utf8&path=result.txt")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["XAPI-Key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files?encoding=utf8&path=result.txt")
  .header("XAPI-Key", "<apiKey>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files?encoding=utf8&path=result.txt', [
  'headers' => [
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files?encoding=utf8&path=result.txt");
var request = new RestRequest(Method.GET);
request.AddHeader("XAPI-Key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["XAPI-Key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files?encoding=utf8&path=result.txt")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 列出文件

#### Production

### Request

GET [https://sandbox.xapi.to/v1/sandboxes/\{id}/files/list](https://sandbox.xapi.to/v1/sandboxes/\{id}/files/list)

```curl
curl -G https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files/list \
     -H "XAPI-Key: <apiKey>" \
     -d depth=2 \
     -d path=.
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files/list"

querystring = {"depth":"2","path":"."}

headers = {"XAPI-Key": "<apiKey>"}

response = requests.get(url, headers=headers, params=querystring)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files/list?depth=2&path=.';
const options = {method: 'GET', headers: {'XAPI-Key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files/list?depth=2&path=."

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("XAPI-Key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files/list?depth=2&path=.")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["XAPI-Key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files/list?depth=2&path=.")
  .header("XAPI-Key", "<apiKey>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files/list?depth=2&path=.', [
  'headers' => [
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files/list?depth=2&path=.");
var request = new RestRequest(Method.GET);
request.AddHeader("XAPI-Key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["XAPI-Key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files/list?depth=2&path=.")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

#### Test

### Request

GET [https://sandbox.xapi.to/v1/sandboxes/\{id}/files/list](https://sandbox.xapi.to/v1/sandboxes/\{id}/files/list)

```curl
curl -G https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files/list \
     -H "XAPI-Key: <apiKey>" \
     -d depth=2 \
     -d path=.
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files/list"

querystring = {"depth":"2","path":"."}

headers = {"XAPI-Key": "<apiKey>"}

response = requests.get(url, headers=headers, params=querystring)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files/list?depth=2&path=.';
const options = {method: 'GET', headers: {'XAPI-Key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files/list?depth=2&path=."

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("XAPI-Key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files/list?depth=2&path=.")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["XAPI-Key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files/list?depth=2&path=.")
  .header("XAPI-Key", "<apiKey>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files/list?depth=2&path=.', [
  'headers' => [
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files/list?depth=2&path=.");
var request = new RestRequest(Method.GET);
request.AddHeader("XAPI-Key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["XAPI-Key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/files/list?depth=2&path=.")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 获取端口访问地址

实例内服务必须使用 `background=true` 启动并监听 `0.0.0.0`，且 Offering 同时声明
`backgroundExec` 与 `ports`。取得 URL 后仍要带返回的 headers（如有）从外部请求 marker，
不能把“拿到 URL”当成应用就绪。

#### Production

### Request

GET [https://sandbox.xapi.to/v1/sandboxes/\{id}/ports/\{port}](https://sandbox.xapi.to/v1/sandboxes/\{id}/ports/\{port})

```curl
curl https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/ports/8080 \
     -H "XAPI-Key: <apiKey>"
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/ports/8080"

headers = {"XAPI-Key": "<apiKey>"}

response = requests.get(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/ports/8080';
const options = {method: 'GET', headers: {'XAPI-Key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/ports/8080"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("XAPI-Key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/ports/8080")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["XAPI-Key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/ports/8080")
  .header("XAPI-Key", "<apiKey>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/ports/8080', [
  'headers' => [
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/ports/8080");
var request = new RestRequest(Method.GET);
request.AddHeader("XAPI-Key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["XAPI-Key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/ports/8080")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

#### Test

### Request

GET [https://sandbox.xapi.to/v1/sandboxes/\{id}/ports/\{port}](https://sandbox.xapi.to/v1/sandboxes/\{id}/ports/\{port})

```curl
curl https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/ports/8080 \
     -H "XAPI-Key: <apiKey>"
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/ports/8080"

headers = {"XAPI-Key": "<apiKey>"}

response = requests.get(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/ports/8080';
const options = {method: 'GET', headers: {'XAPI-Key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/ports/8080"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("XAPI-Key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/ports/8080")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["XAPI-Key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/ports/8080")
  .header("XAPI-Key", "<apiKey>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/ports/8080', [
  'headers' => [
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/ports/8080");
var request = new RestRequest(Method.GET);
request.AddHeader("XAPI-Key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["XAPI-Key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/ports/8080")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 调用供应商扩展

只调用 offering 明确声明的扩展，例如 `runpod.connection_info`。

#### Production

### Request

POST [https://sandbox.xapi.to/v1/sandboxes/\{id}/extensions/\{extensionId}](https://sandbox.xapi.to/v1/sandboxes/\{id}/extensions/\{extensionId})

```curl
curl -X POST https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/extensions/runpod.connection_info \
     -H "XAPI-Key: <apiKey>" \
     -H "Content-Type: application/json" \
     -d '{
  "input": {},
  "idempotencyKey": "docs-extension-example"
}'
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/extensions/runpod.connection_info"

payload = { "idempotencyKey": "docs-extension-example" }
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/extensions/runpod.connection_info';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"idempotencyKey":"docs-extension-example"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/extensions/runpod.connection_info"

	payload := strings.NewReader("{\n  \"idempotencyKey\": \"docs-extension-example\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/extensions/runpod.connection_info")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"idempotencyKey\": \"docs-extension-example\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/extensions/runpod.connection_info")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"idempotencyKey\": \"docs-extension-example\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/extensions/runpod.connection_info', [
  'body' => '{
  "idempotencyKey": "docs-extension-example"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/extensions/runpod.connection_info");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"idempotencyKey\": \"docs-extension-example\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["idempotencyKey": "docs-extension-example"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/extensions/runpod.connection_info")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

#### Test

### Request

POST [https://sandbox.xapi.to/v1/sandboxes/\{id}/extensions/\{extensionId}](https://sandbox.xapi.to/v1/sandboxes/\{id}/extensions/\{extensionId})

```curl
curl -X POST https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/extensions/runpod.connection_info \
     -H "XAPI-Key: <apiKey>" \
     -H "Content-Type: application/json" \
     -d '{
  "input": {},
  "idempotencyKey": "docs-extension-example"
}'
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/extensions/runpod.connection_info"

payload = { "idempotencyKey": "docs-extension-example" }
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/extensions/runpod.connection_info';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"idempotencyKey":"docs-extension-example"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/extensions/runpod.connection_info"

	payload := strings.NewReader("{\n  \"idempotencyKey\": \"docs-extension-example\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/extensions/runpod.connection_info")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"idempotencyKey\": \"docs-extension-example\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/extensions/runpod.connection_info")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"idempotencyKey\": \"docs-extension-example\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/extensions/runpod.connection_info', [
  'body' => '{
  "idempotencyKey": "docs-extension-example"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/extensions/runpod.connection_info");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"idempotencyKey\": \"docs-extension-example\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["idempotencyKey": "docs-extension-example"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/extensions/runpod.connection_info")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

## 审计与历史

### 查询实例历史

按状态、实例 ID、provider 和时间范围检索，用于清理门禁与费用核对。

#### Production

### Request

GET [https://sandbox.xapi.to/v1/sandbox-history](https://sandbox.xapi.to/v1/sandbox-history)

```curl
curl -G https://sandbox.xapi.to/v1/sandbox-history \
     -H "XAPI-Key: <apiKey>" \
     -d page=1 \
     -d pageSize=20 \
     -d state=HISTORY
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandbox-history"

querystring = {"page":"1","pageSize":"20","state":"HISTORY"}

headers = {"XAPI-Key": "<apiKey>"}

response = requests.get(url, headers=headers, params=querystring)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandbox-history?page=1&pageSize=20&state=HISTORY';
const options = {method: 'GET', headers: {'XAPI-Key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandbox-history?page=1&pageSize=20&state=HISTORY"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("XAPI-Key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandbox-history?page=1&pageSize=20&state=HISTORY")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["XAPI-Key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://sandbox.xapi.to/v1/sandbox-history?page=1&pageSize=20&state=HISTORY")
  .header("XAPI-Key", "<apiKey>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://sandbox.xapi.to/v1/sandbox-history?page=1&pageSize=20&state=HISTORY', [
  'headers' => [
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandbox-history?page=1&pageSize=20&state=HISTORY");
var request = new RestRequest(Method.GET);
request.AddHeader("XAPI-Key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["XAPI-Key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandbox-history?page=1&pageSize=20&state=HISTORY")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

#### Test

### Request

GET [https://sandbox.xapi.to/v1/sandbox-history](https://sandbox.xapi.to/v1/sandbox-history)

```curl
curl -G https://sandbox.xapi.to/v1/sandbox-history \
     -H "XAPI-Key: <apiKey>" \
     -d page=1 \
     -d pageSize=20 \
     -d state=HISTORY
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandbox-history"

querystring = {"page":"1","pageSize":"20","state":"HISTORY"}

headers = {"XAPI-Key": "<apiKey>"}

response = requests.get(url, headers=headers, params=querystring)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandbox-history?page=1&pageSize=20&state=HISTORY';
const options = {method: 'GET', headers: {'XAPI-Key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandbox-history?page=1&pageSize=20&state=HISTORY"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("XAPI-Key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandbox-history?page=1&pageSize=20&state=HISTORY")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["XAPI-Key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://sandbox.xapi.to/v1/sandbox-history?page=1&pageSize=20&state=HISTORY")
  .header("XAPI-Key", "<apiKey>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://sandbox.xapi.to/v1/sandbox-history?page=1&pageSize=20&state=HISTORY', [
  'headers' => [
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandbox-history?page=1&pageSize=20&state=HISTORY");
var request = new RestRequest(Method.GET);
request.AddHeader("XAPI-Key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["XAPI-Key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandbox-history?page=1&pageSize=20&state=HISTORY")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 查询实例审计流

分别选择 `operations`、`events`、`usageSegments` 或 `billingPeriods`。

#### Production

### Request

GET [https://sandbox.xapi.to/v1/sandboxes/\{id}/audit](https://sandbox.xapi.to/v1/sandboxes/\{id}/audit)

```curl
curl -G https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/audit \
     -H "XAPI-Key: <apiKey>" \
     -d kind=operations \
     -d page=1 \
     -d pageSize=100
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/audit"

querystring = {"kind":"operations","page":"1","pageSize":"100"}

headers = {"XAPI-Key": "<apiKey>"}

response = requests.get(url, headers=headers, params=querystring)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/audit?kind=operations&page=1&pageSize=100';
const options = {method: 'GET', headers: {'XAPI-Key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/audit?kind=operations&page=1&pageSize=100"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("XAPI-Key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/audit?kind=operations&page=1&pageSize=100")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["XAPI-Key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/audit?kind=operations&page=1&pageSize=100")
  .header("XAPI-Key", "<apiKey>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/audit?kind=operations&page=1&pageSize=100', [
  'headers' => [
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/audit?kind=operations&page=1&pageSize=100");
var request = new RestRequest(Method.GET);
request.AddHeader("XAPI-Key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["XAPI-Key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/audit?kind=operations&page=1&pageSize=100")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

#### Test

### Request

GET [https://sandbox.xapi.to/v1/sandboxes/\{id}/audit](https://sandbox.xapi.to/v1/sandboxes/\{id}/audit)

```curl
curl -G https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/audit \
     -H "XAPI-Key: <apiKey>" \
     -d kind=operations \
     -d page=1 \
     -d pageSize=100
```

```python
import requests

url = "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/audit"

querystring = {"kind":"operations","page":"1","pageSize":"100"}

headers = {"XAPI-Key": "<apiKey>"}

response = requests.get(url, headers=headers, params=querystring)

print(response.json())
```

```javascript
const url = 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/audit?kind=operations&page=1&pageSize=100';
const options = {method: 'GET', headers: {'XAPI-Key': '<apiKey>'}};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/audit?kind=operations&page=1&pageSize=100"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("XAPI-Key", "<apiKey>")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/audit?kind=operations&page=1&pageSize=100")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
request["XAPI-Key"] = '<apiKey>'

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/audit?kind=operations&page=1&pageSize=100")
  .header("XAPI-Key", "<apiKey>")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/audit?kind=operations&page=1&pageSize=100', [
  'headers' => [
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/audit?kind=operations&page=1&pageSize=100");
var request = new RestRequest(Method.GET);
request.AddHeader("XAPI-Key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["XAPI-Key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes/33333333-3333-4333-8333-333333333333/audit?kind=operations&page=1&pageSize=100")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

## 完成标准

#### 业务结果通过

HTTP 状态正确；Shell 同时满足 `exitCode=0`；文件和公开 URL 包含预期制品。

#### 实例进入终态

终止后继续查询，直到 `observedState=TERMINATED` 或供应商终态 `FAILED`。

#### 审计和费用完整

操作、事件、用量段和账期均可查询，费用使用服务端 `totalCost`。

#### 没有资源遗留

ACTIVE 历史中没有本次测试仍在计费的实例；账户实例快照仍保留终态记录属于正常现象。

> **Info**
>
> 需要生成语言代码和查看完整响应 Schema 时，可使用侧栏的
> **逐接口 API Reference**；日常浏览和试调直接留在本页即可。