# 位置与租期

`GET /account/api/v1/catalog`

## 授权

`Authorization: Bearer YOUR_ARNPROXY_API_KEY`

`Accept: application/json`

所需权限: `read`

## 参数

| 名称 | 类型 | 必填 / 条件必填 | 默认值 | 说明 |
|---|---|---|---|---|
| `product_id` (query) | integer | 必填 | — | products 返回的产品 ID，1–2147483647。 |

## 更多使用示例

ID 和价格仅供示例，请使用目录及同一次报价中的实际值。JSON ID 和 expected_total_minor 必须是数字。示例刻意保留 terms=false；只有客户明确同意实际付费操作后才应发送 terms=true。

### 使用用途：只需选择子用途

标准订单不应让客户选择两次。请在 catalog.purposes 中找到 id=201，并仅展示其 children。purchase 中的 purpose_id 固定为整数 201，subpurpose_id 为所选子项的 ID。保留层级结构是为了兼容现有集成。

```javascript
const response = await fetch(
  'https://www.arnproxy.com/account/api/v1/catalog?product_id=' + productId,
  { headers: { Authorization: 'Bearer ' + apiKey } }
);
const catalog = await response.json();
if (!response.ok || !catalog.ok) throw new Error('Catalog request failed');
const purposeGroup = catalog.data.purposes.find(group => group.id === 201);
if (!purposeGroup) throw new Error('Purpose group 201 is not available');
const purposeOptions = purposeGroup.children.map(({ id, name }) => ({ id, name }));
// Show only purposeOptions. The customer selects selectedSubpurposeId.
const purchaseLine = {
  location_id: selectedLocationId,
  time_id: selectedTimeId,
  quantity: selectedQuantity,
  purpose_id: 201,
  subpurpose_id: selectedSubpurposeId
};
// Add other_purpose (1–30 characters) only when selectedSubpurposeId === -1.
// No purchase is sent by this example.
```

### 使用用途：只需选择子用途

标准订单不应让客户选择两次。请在 catalog.purposes 中找到 id=201，并仅展示其 children。purchase 中的 purpose_id 固定为整数 201，subpurpose_id 为所选子项的 ID。保留层级结构是为了兼容现有集成。

```python
import json
import urllib.request

request = urllib.request.Request(
    'https://www.arnproxy.com/account/api/v1/catalog?product_id=' + str(product_id),
    headers={'Authorization': 'Bearer ' + api_key}
)
with urllib.request.urlopen(request, timeout=20) as response:
    catalog = json.load(response)
if not catalog.get('ok'):
    raise RuntimeError('Catalog request failed')
purpose_group = next((g for g in catalog['data']['purposes'] if g['id'] == 201), None)
if purpose_group is None:
    raise RuntimeError('Purpose group 201 is not available')
purpose_options = [{'id': p['id'], 'name': p['name']} for p in purpose_group['children']]
# Display only purpose_options; the customer selects selected_subpurpose_id.
purchase_line = {
    'location_id': selected_location_id,
    'time_id': selected_time_id,
    'quantity': selected_quantity,
    'purpose_id': 201,
    'subpurpose_id': selected_subpurpose_id,
}
# For Other (-1), also set other_purpose to 1–30 characters.
# This example does not submit a purchase.
```

## 请求示例

### 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 \
    'https://www.arnproxy.com/account/api/v1/catalog?product_id=FROM_PRODUCTS'
```

### python

```python
import os, requests

headers = {"Authorization": "Bearer " + os.environ["ARNPROXY_API_KEY"]}
response = requests.get(
    "https://www.arnproxy.com/account/api/v1/catalog?product_id=FROM_PRODUCTS",
    headers=headers,
    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 response = await fetch("https://www.arnproxy.com/account/api/v1/catalog?product_id=FROM_PRODUCTS", {
  method: 'GET', headers, redirect: 'error',
  signal: AbortSignal.timeout(30000)
});
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')];
$ch = curl_init('https://www.arnproxy.com/account/api/v1/catalog?product_id=FROM_PRODUCTS');
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,
]);
$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
  req, err := http.NewRequest("GET", "https://www.arnproxy.com/account/api/v1/catalog?product_id=FROM_PRODUCTS", body)
  if err != nil { panic(err) }
  req.Header.Set("Authorization", "Bearer "+os.Getenv("ARNPROXY_API_KEY"))
  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.Get,
    "https://www.arnproxy.com/account/api/v1/catalog?product_id=FROM_PRODUCTS");
request.Headers.Authorization = new AuthenticationHeaderValue(
    "Bearer", Environment.GetEnvironmentVariable("ARNPROXY_API_KEY"));
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/catalog?product_id=FROM_PRODUCTS"))
    .header("Authorization", "Bearer " + System.getenv("ARNPROXY_API_KEY"))
    .header("Accept", "application/json")
    .GET()
    .build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode());
```

## 响应 · HTTP 200

```json
{
  "ok": true,
  "data": {
    "product": {
      "id": 5,
      "name": "IPv4 Proxy",
      "minimum_quantity": 1
    },
    "currency": "TRY",
    "locations": [
      {
        "id": 10,
        "name": "Example country",
        "periods": [
          {
            "id": 101,
            "name": "7 days",
            "days": 7,
            "base_unit_price": "10.0000"
          }
        ]
      }
    ],
    "purposes": [
      {
        "id": 201,
        "name": "Purpose",
        "children": [
          {
            "id": 202,
            "name": "Example purpose"
          }
        ]
      }
    ],
    "discount_scope": "country",
    "stock_checked": false,
    "purchase_available": true
  },
  "meta": {
    "request_id": "000000000000000000000001",
    "phase": "public_v1",
    "source": "arnproxy_records"
  }
}
```

| 名称 | 类型 | 条件必填 | 说明 |
|---|---|---|---|
| `ok` | boolean | — | 成功标志；为 false 时请检查 error.code。 |
| `data` | object | — | 操作特定结果；示例均为演示用合成数据。 |
| `data.product` | object | — | product 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.product.id` | integer | — | 相关 ARNPROXY 记录 ID，请勿替换为上游内部 ID。 |
| `data.product.name` | string | — | name 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.product.minimum_quantity` | integer | — | 此产品每条订单行的最小数量。 |
| `data.currency` | string | — | 账户交易币种：TRY 或 USD。 |
| `data.locations` | array | — | locations 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.locations[]` | object | — | locations 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.locations[].id` | integer | — | 相关 ARNPROXY 记录 ID，请勿替换为上游内部 ID。 |
| `data.locations[].name` | string | — | name 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.locations[].periods` | array | — | periods 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.locations[].periods[]` | object | — | periods 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.locations[].periods[].id` | integer | — | 相关 ARNPROXY 记录 ID，请勿替换为上游内部 ID。 |
| `data.locations[].periods[].name` | string | — | name 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.locations[].periods[].days` | integer | — | 方案天数，与 GB 方案流量数量分开。 |
| `data.locations[].periods[].base_unit_price` | string | — | base unit price 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.purposes` | array | — | purposes 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.purposes[]` | object | — | purposes 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.purposes[].id` | integer | — | 相关 ARNPROXY 记录 ID，请勿替换为上游内部 ID。 |
| `data.purposes[].name` | string | — | name 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.purposes[].children` | array | — | children 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.purposes[].children[]` | object | — | children 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.purposes[].children[].id` | integer | — | 相关 ARNPROXY 记录 ID，请勿替换为上游内部 ID。 |
| `data.purposes[].children[].name` | string | — | name 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.discount_scope` | string | — | discount scope 的操作特定值。请保留返回类型并查阅行为说明。 |
| `data.stock_checked` | boolean | — | 仅凭价格/本地结果不能保证上游可用性或库存。 |
| `data.purchase_available` | boolean | — | 根据响应条件/权限确定的可用性，不代表库存或上游可用性保证。 |
| `meta` | object | — | 请求关联与数据来源元信息。 |
| `meta.request_id` | string | — | 此 HTTP 请求的跟踪 ID，不是操作键或订单 ID。 |
| `meta.phase` | string | — | phase 的操作特定值。请保留返回类型并查阅行为说明。 |
| `meta.source` | string | — | 数据来源；本地记录与实时上游查询属于不同证据。 |

## 行为与重要说明

- 从 products/catalog 获取 ID。quote 行仅含 location_id、time_id、quantity。purchase 行还必须有 purpose_id=201 和所选 subpurpose_id。
- 标准订单不应让客户选择两次。请在 catalog.purposes 中找到 id=201，并仅展示其 children。purchase 中的 purpose_id 固定为整数 201，subpurpose_id 为所选子项的 ID。保留层级结构是为了兼容现有集成。
- 选择“其他”时，发送 subpurpose_id=-1 和包含 1–30 个字符的 other_purpose。其他选项无需 other_purpose。purpose_id 仍为 201。

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

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