# 生成定向会话连接

`POST /account/api/v1/residential/sessions/export`

## 授权

`Authorization: Bearer YOUR_ARNPROXY_API_KEY`

`Accept: application/json`

所需权限: `credentials`

`Content-Type: application/json`

## 参数

| 名称 | 类型 | 必填 / 条件必填 | 默认值 | 说明 |
|---|---|---|---|---|
| `list_id` (body) | integer | 必填 | — | 自己的 ARNPROXY 连接列表记录 ID，不是上游列表 ID。 |
| `country` (body) | string | 可选 | — | 两个大写字母的国家代码，例如 US。 |
| `subdivision` (body) | integer | 可选 | — | 正整数地区代码；必须提供 country。 |
| `city` (body) | string | 可选 | — | 需要 country；最多 80 字节字母/数字，仅用单个空格/连字符分隔。 |
| `isp_id` (body) | integer | 可选 | — | residential_isp_codes 返回的 ID，1–2147483647。 |
| `asn` (body) | integer | 可选 | — | ASN 范围 1–4294967295。 |
| `zip` (body) | string | 可选 | — | 1–16 个字母/数字/连字符；需要 country。 |
| `session` (body) | string | 可选 | — | 1–64 个 ASCII 字母/数字。 |
| `ttl` (body) | string | 可选 | — | 正数加 s/m/h，例如 15m；最多 86400 秒，需要 session。 |
| `format` (body) | string | 可选 | `"uri"` | uri \| host_port_user_pass \| user_pass_host_port。含凭据需 credentials 权限，也支持 csv \| custom。 |
| `protocol` (body) | string | 可选 | `"http"` | http 或 socks5，仅控制 uri 输出的前缀。 |
| `offset` (body) | integer | 可选 | `0` | 0–999，且小于端口数量。 |
| `limit` (body) | integer | 可选 | `10` | 1–1000；默认 10。 |
| `columns` (body) | string[] | 条件必填 | — | 仅 CSV：id、endpoint、ip、port、login、password。默认 ["id","endpoint"]。login/password 需 credentials 权限。 |
| `template` (body) | string | 条件必填 | — | custom 必填，最多 200 字符。占位符：%endpoint%、%ip%、%port%、%id%、%login%、%username%、%password%、%login_url%、%password_url%。不接受控制字符或未知占位符。 |

## 请求体

请用相应目录、报价或范围中的值替换 YOUR_/FROM_。示例中的确认值为 false；只有明确同意真实操作时才确认。

```json
{
  "list_id": "YOUR_SPECIAL_LIST_ID",
  "session": "Example001",
  "ttl": "15m",
  "format": "uri",
  "limit": 1
}
```

## 请求示例

### curl

```curl
printf 'Authorization: Bearer %s\n' "$ARNPROXY_API_KEY" |
  curl --silent --show-error --header @- \
    --header 'Accept: application/json' \
    --connect-timeout 10 --max-time 30 \
    --request POST --header 'Content-Type: application/json' \
    --data-binary @request.json \
    'https://www.arnproxy.com/account/api/v1/residential/sessions/export'
```

### python

```python
import os, requests

headers = {"Authorization": "Bearer " + os.environ["ARNPROXY_API_KEY"]}
import json
with open("request.json", encoding="utf-8") as f:
    payload = json.load(f)
response = requests.post(
    "https://www.arnproxy.com/account/api/v1/residential/sessions/export",
    headers=headers, json=payload,
    timeout=(10, 30), allow_redirects=False
)
print(response.status_code, response.text)
# No automatic write retry.
```

### javascript

```javascript
const headers = { Authorization: `Bearer ${process.env.ARNPROXY_API_KEY}` };
const { readFile } = await import('node:fs/promises');
headers['Content-Type'] = 'application/json';
const body = await readFile('request.json', 'utf8');
const response = await fetch("https://www.arnproxy.com/account/api/v1/residential/sessions/export", {
  method: 'POST', headers, redirect: 'error',
  signal: AbortSignal.timeout(30000), body
});
console.log(response.status, await response.text());
// A write timeout is ambiguous; query its saved operation.
```

### php

```php
<?php
$headers = ['Accept: application/json',
    'Authorization: Bearer '.getenv('ARNPROXY_API_KEY')];
$headers[] = 'Content-Type: application/json';
$ch = curl_init('https://www.arnproxy.com/account/api/v1/residential/sessions/export');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_FOLLOWLOCATION => false,
    CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2,
    CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 30,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => file_get_contents('request.json'),
]);
$result = curl_exec($ch);
if ($result === false) {
    // Do not repeat a write; use the original operation key.
    throw new RuntimeException('Transport result unknown');
}
echo curl_getinfo($ch, CURLINFO_HTTP_CODE).PHP_EOL.$result;
curl_close($ch);
```

### go

```go
package main

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

func main() {
  client := &http.Client{Timeout: 30*time.Second,
    CheckRedirect: func(req *http.Request, via []*http.Request) error {
      return http.ErrUseLastResponse
    }}
  var body io.Reader
  file, err := os.Open("request.json"); if err != nil { panic(err) }
  defer file.Close(); body = file
  req, err := http.NewRequest("POST", "https://www.arnproxy.com/account/api/v1/residential/sessions/export", body)
  if err != nil { panic(err) }
  req.Header.Set("Authorization", "Bearer "+os.Getenv("ARNPROXY_API_KEY"))
  req.Header.Set("Content-Type", "application/json")
  res, err := client.Do(req); if err != nil { panic(err) }
  defer res.Body.Close()
  data, err := io.ReadAll(res.Body); if err != nil { panic(err) }
  fmt.Println(res.StatusCode, string(data))
}
```

### csharp

```csharp
using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;

using var handler = new HttpClientHandler { AllowAutoRedirect = false };
using var client = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(30) };
using var request = new HttpRequestMessage(HttpMethod.Post,
    "https://www.arnproxy.com/account/api/v1/residential/sessions/export");
request.Headers.Authorization = new AuthenticationHeaderValue(
    "Bearer", Environment.GetEnvironmentVariable("ARNPROXY_API_KEY"));
request.Content = new StringContent(
    await File.ReadAllTextAsync("request.json"), Encoding.UTF8, "application/json");
using var response = await client.SendAsync(request);
Console.WriteLine((int)response.StatusCode);
Console.WriteLine(await response.Content.ReadAsStringAsync());
// Never automatically retry an ambiguous write.
```

### java

```java
import java.net.URI;
import java.net.http.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;

// Inside your application method:
var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder(URI.create("https://www.arnproxy.com/account/api/v1/residential/sessions/export"))
    .header("Authorization", "Bearer " + System.getenv("ARNPROXY_API_KEY"))
    .header("Accept", "application/json")
    .header("Content-Type", "application/json")
    .POST(HttpRequest.BodyPublishers.ofString(
        Files.readString(Path.of("request.json"), StandardCharsets.UTF_8)))
    .build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode());
```

## 响应 · HTTP 200

```json
{
  "ok": true,
  "data": {
    "list_id": 30002,
    "package_id": 20001,
    "format": "uri",
    "protocol": "http",
    "items": [
      "http://ExampleUser_s_Example001_ttl_15m:ExamplePassword@res.arnproxy.com:10000"
    ],
    "count": 1,
    "next_offset": 1,
    "session": "Example001",
    "ttl": "15m",
    "credentials_included": true,
    "provider_requests": 0,
    "database_changes": 0,
    "proxy_connections_tested": false,
    "connection_success_guaranteed": false,
    "snapshot": {
      "source": "arnproxy_records",
      "observed_at": "2030-01-01T12:00:00+00:00",
      "fresh": true,
      "max_age_seconds": 3600,
      "reason": null
    },
    "source": "arnproxy_records"
  },
  "meta": {
    "request_id": "000000000000000000000001",
    "phase": "public_v1",
    "source": "arnproxy_records"
  }
}
```

| 名称 | 类型 | 条件必填 | 说明 |
|---|---|---|---|
| `ok` | boolean | — | 成功标志；为 false 时请检查 error.code。 |
| `data` | object | — | 操作特定结果；示例均为演示用合成数据。 |
| `data.list_id` | integer | — | 相关 ARNPROXY 记录 ID，请勿替换为上游内部 ID。 |
| `data.package_id` | integer | — | 相关 ARNPROXY 记录 ID，请勿替换为上游内部 ID。 |
| `data.format` | string | — | format 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.protocol` | string | — | protocol 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.items` | array | — | 此页记录或格式化连接字符串；空列表也可能是有效结果。 |
| `data.items[]` | string | — | 此页记录或格式化连接字符串；空列表也可能是有效结果。 |
| `data.count` | integer | — | 此结果可见记录数或生成的连接数。 |
| `data.next_offset` | integer | — | 连接输出的下一偏移量，完成时为 null。 |
| `data.session` | string | — | session 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.ttl` | string | — | ttl 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.credentials_included` | boolean | — | 此结果/密钥是否包含或允许访问敏感凭据。 |
| `data.provider_requests` | integer | — | provider requests 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.database_changes` | integer | — | database changes 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.proxy_connections_tested` | boolean | — | proxy connections tested 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.connection_success_guaranteed` | boolean | — | connection success guaranteed 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.snapshot` | object | — | 套餐快照来源、时间及新鲜度；过期快照不授予管理权限。 |
| `data.snapshot.source` | string | — | 数据来源；本地记录与实时上游查询属于不同证据。 |
| `data.snapshot.observed_at` | string | — | API 返回格式的时间戳；示例日期为合成数据。 |
| `data.snapshot.fresh` | boolean | — | 观测是否在允许的新鲜度时间窗口内。 |
| `data.snapshot.max_age_seconds` | integer | — | 允许判定为新鲜观测的最大秒数。 |
| `data.snapshot.reason` | string|null | — | 固定原因代码或 null，不返回原始上游错误文本。 |
| `data.source` | string | — | 数据来源；本地记录与实时上游查询属于不同证据。 |
| `meta` | object | — | 请求关联与数据来源元信息。 |
| `meta.request_id` | string | — | 此 HTTP 请求的跟踪 ID，不是操作键或订单 ID。 |
| `meta.phase` | string | — | phase 的操作特定值。请保留返回类型并查阅行为说明。 |
| `meta.source` | string | — | 数据来源；本地记录与实时上游查询属于不同证据。 |

## 行为与重要说明

- 套餐和列表 ID 均为 ARNPROXY 记录 ID，不是上游键值。过期快照不能授予访问；必要时使用 residential_package_refresh。
- 会话后缀仅适用于独立创建并验证的专用列表。TTL 需要 1–64 字母/数字的 session，正数 s/m/h 最多 24 小时。生成文本不会连接，实际使用会消耗流量。
- 包含凭据的输出需要 credentials 权限。不要记录或向支持团队发送返回的连接字符串、密码或 Authorization 请求头。

身份验证和参数校验可能在执行前拒绝请求。请查阅错误参考，联系支持时保留 request_id。切勿发送密钥或密码。

[错误与限制](https://docs.arnproxy.com/zh/api-v1/errors)
