# 订单

{% hint style="info" %}
诸如**product\_id、location\_id**等选项可以使用**产品**端点进行检索。

[产品](/cn/dai-li/jing-tai-zhu-zhai-dai-li/api/chan-pin.md)
{% endhint %}

## 获取多个订单

<mark style="color:green;">`GET`</mark> `/orders`

**查询参数**

<table><thead><tr><th>名称</th><th>类型</th><th>描述</th><th>可用选项</th></tr></thead><tbody><tr><td>product_id</td><td>整型</td><td>产品ID</td><td></td></tr><tr><td>page</td><td>整型</td><td>页数</td><td></td></tr><tr><td>per_page</td><td>整型</td><td>每页获取的订单数</td><td></td></tr><tr><td>location_id</td><td>整型</td><td>位置ID</td><td></td></tr><tr><td>status</td><td>字符串</td><td>订单状态</td><td><p></p><pre><code>unpaid
in-progress
confirmed
refunded
expired
</code></pre></td></tr><tr><td>note_search</td><td>字符串</td><td>要搜索的订单备注字段中的短语</td><td></td></tr><tr><td>order_ids</td><td>数组</td><td>目标订单的ID</td><td></td></tr></tbody></table>

**响应案例：**

{% tabs %}
{% tab title="cURL" %}

```
curl -X GET "https://apid.iproyal.com/v1/reseller/orders?product_id=123&page=1&per_page=10&location_id=456&status=in-progress&note_search=example%20note&order_ids=789,1011" \
     -H "X-Access-Token: <your_access_token>" \
     -H "Content-Type: application/json"
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$api_token = '<your_access_token>';

$params = [
    'product_id' => 123,
    'page' => 1,
    'per_page' => 10,
    'location_id' => 456,
    'status' => 'in-progress',
    'note_search' => 'example note',
    'order_ids' => [789, 1011]
];

$query = http_build_query($params);
$url = "https://apid.iproyal.com/v1/reseller/orders?$query";

$options = [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        "X-Access-Token: $api_token",
        'Content-Type: application/json'
    ]
];

$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
} else {
    echo $response;
}

curl_close($ch);
?>
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

api_token = '<your_access_token>'
params = {
    'product_id': 123,
    'page': 1,
    'per_page': 10,
    'location_id': 456,
    'status': 'in-progress',
    'note_search': 'example note',
    'order_ids': '789,1011'
}

url = 'https://apid.iproyal.com/v1/reseller/orders'
headers = {
    'X-Access-Token': api_token,
    'Content-Type': 'application/json'
}

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

print(response.status_code)
print(response.json())
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const https = require('https');

const api_token = '<your_access_token>';

const params = new URLSearchParams({
  product_id: 123,
  page: 1,
  per_page: 10,
  location_id: 456,
  status: 'in-progress',
  note_search: 'example note',
  order_ids: [789, 1011].join(',')
}).toString();

const options = {
  hostname: 'apid.iproyal.com',
  path: `/v1/reseller/orders?${params}`,
  method: 'GET',
  headers: {
    'X-Access-Token': api_token,
    'Content-Type': 'application/json'
  }
};

const req = https.request(options, (res) => {
  let responseData = '';

  res.on('data', (chunk) => {
    responseData += chunk;
  });

  res.on('end', () => {
    console.log(responseData);
  });
});

req.on('error', (error) => {
  console.error('Error:', error.message);
});

req.end();
```

{% endtab %}

{% tab title="Java" %}

```java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Map;

public class ApiRequest {
    public static void main(String[] args) {
        String apiToken = "<your_access_token>";
        String urlString = "https://apid.iproyal.com/v1/reseller/orders";

        Map<String, String> params = Map.of(
            "product_id", "123",
            "page", "1",
            "per_page", "10",
            "location_id", "456",
            "status", "in-progress",
            "note_search", "example note",
            "order_ids", "789,1011"
        );

        StringBuilder queryParams = new StringBuilder();
        try {
            for (Map.Entry<String, String> entry : params.entrySet()) {
                if (queryParams.length() > 0) {
                    queryParams.append("&");
                }
                queryParams.append(URLEncoder.encode(entry.getKey(), "UTF-8"))
                           .append("=")
                           .append(URLEncoder.encode(entry.getValue(), "UTF-8"));
            }

            URL url = new URL(urlString + "?" + queryParams.toString());
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setRequestProperty("X-Access-Token", apiToken);
            connection.setRequestProperty("Content-Type", "application/json");

            int responseCode = connection.getResponseCode();
            System.out.println("Response Code: " + responseCode);

            if (responseCode == HttpURLConnection.HTTP_OK) {
                BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                String inputLine;
                StringBuilder content = new StringBuilder();

                while ((inputLine = in.readLine()) != null) {
                    content.append(inputLine);
                }
                in.close();

                System.out.println("Response Body: " + content.toString());
            } else {
                System.out.println("GET request failed. Response Code: " + responseCode);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"net/url"
	"io"
)

const (
	apiToken = "<your_access_token>"
	baseURL  = "https://apid.iproyal.com/v1/reseller/orders"
)

func main() {
	params := url.Values{}
	params.Add("product_id", "123")
	params.Add("page", "1")
	params.Add("per_page", "10")
	params.Add("location_id", "456")
	params.Add("status", "in-progress")
	params.Add("note_search", "example note")
	params.Add("order_ids", "789,1011")

	fullURL := fmt.Sprintf("%s?%s", baseURL, params.Encode())

	req, err := http.NewRequest(http.MethodGet, fullURL, nil)
	if err != nil {
		log.Fatal("Error creating request:", err)
	}

	req.Header.Set("X-Access-Token", apiToken)
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal("Error making request:", err)
	}
	defer resp.Body.Close()

	fmt.Println("Status Code:", resp.StatusCode)

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		log.Fatal("Error reading response body:", err)
	}

	var jsonResponse map[string]interface{}
	err = json.Unmarshal(responseBody, &jsonResponse)
	if err != nil {
		log.Fatal("Error unmarshaling JSON:", err)
	}

	fmt.Printf("%+v\n", jsonResponse)
}
```

{% endtab %}

{% tab title="C#" %}

```csharp
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text.Json;

class Program
{
    static async Task Main(string[] args)
    {
        string apiToken = "<your_access_token>";
        string url = "https://apid.iproyal.com/v1/reseller/orders";

        var queryParams = new Dictionary<string, string>
        {
            { "product_id", "123" },
            { "page", "1" },
            { "per_page", "10" },
            { "location_id", "456" },
            { "status", "in-progress" },
            { "note_search", "example note" },
            { "order_ids", "789,1011" }
        };

        using (HttpClient client = new HttpClient())
        {
            client.DefaultRequestHeaders.Add("X-Access-Token", apiToken);

            var urlWithParams = new UriBuilder(url) { Query = await new FormUrlEncodedContent(queryParams).ReadAsStringAsync() }.ToString();

            HttpResponseMessage response = await client.GetAsync(urlWithParams);

            Console.WriteLine((int)response.StatusCode);

            string responseText = await response.Content.ReadAsStringAsync();
            var jsonResponse = JsonSerializer.Deserialize<JsonElement>(responseText);
            Console.WriteLine(jsonResponse);
        }
    }
}
```

{% endtab %}
{% endtabs %}

**响应示例：**

```json
{
    "data": [
        {
            "id": 420,
            "note": null,
            "product_name": "Static Residential",
            "plan_name": "30 Days",
            "expire_date": "2024-04-20 10:25:12",
            "status": "confirmed",
            "location": "United States",
            "quantity": 5,
            "questions_answers": [
                {
                    "question": "Extra requirements (if you have any):",
                    "answer": "I need 128.158.97"
                }
            ],
            "proxy_data": {
                "ports": {
                    "socks5": 12324,
                    "http|https": 12323
                },
                "proxies": []
            },
            "auto_extend_settings": null,
            "extended_history": []
        },
        ...
    ],
    "meta": {
        "current_page": 1,
        "from": 1,
        "last_page": 2,
        "path": "https://apid.iproyal.com/v1/reseller/orders",
        "per_page": 10,
        "to": 10,
        "total": 14
    }
}
```

## 获取订单

<mark style="color:green;">`GET`</mark>  `/orders/{order_id}`

**响应案例：**

{% tabs %}
{% tab title="cURL" %}

```
curl -X GET "https://apid.iproyal.com/v1/reseller/orders/12345" \
     -H "X-Access-Token: <your_access_token>" \
     -H "Content-Type: application/json"
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$api_token = '<your_access_token>';
$order_id = 12345;

$url = "https://apid.iproyal.com/v1/reseller/orders/$order_id";

$options = [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        "X-Access-Token: $api_token",
        'Content-Type: application/json'
    ]
];

$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
} else {
    echo $response;
}

curl_close($ch);
?>

```

{% endtab %}

{% tab title="Python" %}

```python
import requests

api_token = '<your_access_token>'
order_id = 12345

url = f'https://apid.iproyal.com/v1/reseller/orders/{order_id}'
headers = {
    'X-Access-Token': api_token,
    'Content-Type': 'application/json'
}

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

print(response.status_code)
print(response.json())
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const https = require('https');

const api_token = '<your_access_token>';
const order_id = 12345;

const options = {
  hostname: 'apid.iproyal.com',
  path: `/v1/reseller/orders/${order_id}`,
  method: 'GET',
  headers: {
    'X-Access-Token': api_token,
    'Content-Type': 'application/json'
  }
};

const req = https.request(options, (res) => {
  let responseData = '';

  res.on('data', (chunk) => {
    responseData += chunk;
  });

  res.on('end', () => {
    console.log(responseData);
  });
});

req.on('error', (error) => {
  console.error('Error:', error.message);
});

req.end();
```

{% endtab %}

{% tab title="Java" %}

```java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class ApiRequest {
    public static void main(String[] args) {
        String apiToken = "<your_access_token>";
        int orderId = 12345;
        String urlString = String.format("https://apid.iproyal.com/v1/reseller/orders/%d", orderId);

        try {
            URL url = new URL(urlString);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setRequestProperty("X-Access-Token", apiToken);
            connection.setRequestProperty("Content-Type", "application/json");

            int responseCode = connection.getResponseCode();
            System.out.println("Response Code: " + responseCode);

            if (responseCode == HttpURLConnection.HTTP_OK) {
                BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                String inputLine;
                StringBuilder content = new StringBuilder();

                while ((inputLine = in.readLine()) != null) {
                    content.append(inputLine);
                }
                in.close();

                System.out.println("Response Body: " + content.toString());
            } else {
                System.out.println("GET request failed. Response Code: " + responseCode);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"encoding/json"
	"fmt"
	"io"
	"log"
	"net/http"
)

const (
	apiToken = "<your_access_token>"
	orderID  = 12345
)

func main() {
	url := fmt.Sprintf("https://apid.iproyal.com/v1/reseller/orders/%d", orderID)

	req, err := http.NewRequest(http.MethodGet, url, nil)
	if err != nil {
		log.Fatal("Error creating request:", err)
	}

	req.Header.Set("X-Access-Token", apiToken)
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal("Error making request:", err)
	}
	defer resp.Body.Close()

	fmt.Println("Status Code:", resp.StatusCode)

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		log.Fatal("Error reading response body:", err)
	}

	var jsonResponse map[string]interface{}
	err = json.Unmarshal(responseBody, &jsonResponse)
	if err != nil {
		log.Fatal("Error unmarshaling JSON:", err)
	}

	fmt.Printf("%+v\n", jsonResponse)
}
```

{% endtab %}

{% tab title="C#" %}

```csharp
using System;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        string apiToken = "<your_access_token>";
        int orderId = 12345;
        string url = $"https://apid.iproyal.com/v1/reseller/orders/{orderId}";

        using (HttpClient client = new HttpClient())
        {
            client.DefaultRequestHeaders.Add("X-Access-Token", apiToken);

            HttpResponseMessage response = await client.GetAsync(url);

            Console.WriteLine((int)response.StatusCode);

            string responseText = await response.Content.ReadAsStringAsync();
            var jsonResponse = JsonSerializer.Deserialize<JsonElement>(responseText);
            Console.WriteLine(jsonResponse);
        }
    }
}
```

{% endtab %}
{% endtabs %}

**响应示例：**

```json
{
    "id": 420,
    "note": null,
    "product_name": "Static Residential",
    "plan_name": "30 Days",
    "expire_date": "2024-04-20 10:25:12",
    "status": "expired",
    "location": "Canada",
    "quantity": 5,
    "questions_answers": [],
    "proxy_data": {
        "ports": {
            "socks5": 12324,
            "http|https": 12323
        },
        "proxies": []
    },
    "auto_extend_settings": null,
    "extended_history": []
}
```

## 计算价格

<mark style="color:green;">`GET`</mark>  `/orders/calculate-pricing`

**查询参数**

<table><thead><tr><th width="257">名称</th><th width="114">类型</th><th>描述</th></tr></thead><tbody><tr><td>product_id</td><td>整型</td><td>产品ID</td></tr><tr><td>product_plan_id</td><td>整型</td><td>产品套餐ID</td></tr><tr><td>product_location_id</td><td>整型</td><td>产品地理位置ID</td></tr><tr><td>quantity</td><td>整型</td><td>代理数量</td></tr><tr><td>coupon_code</td><td>字符串</td><td>优惠码</td></tr></tbody></table>

**响应案例：**

{% tabs %}
{% tab title="cURL" %}

```
curl -X GET "https://apid.iproyal.com/v1/reseller/orders/calculate-pricing?product_id=123&product_plan_id=456&product_location_id=789&quantity=10&coupon_code=DISCOUNT2024" \
     -H "X-Access-Token: <your_access_token>" \
     -H "Content-Type: application/json"
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$api_token = '<your_access_token>';

$params = [
    'product_id' => 123,
    'product_plan_id' => 456,
    'product_location_id' => 789,
    'quantity' => 10,
    'coupon_code' => 'DISCOUNT2024'
];

$query = http_build_query($params);
$url = "https://apid.iproyal.com/v1/reseller/orders/calculate-pricing?$query";

$options = [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        "X-Access-Token: $api_token",
        'Content-Type: application/json'
    ]
];

$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
} else {
    echo $response;
}

curl_close($ch);
?>
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

api_token = '<your_access_token>'
params = {
    'product_id': 123,
    'product_plan_id': 456,
    'product_location_id': 789,
    'quantity': 10,
    'coupon_code': 'DISCOUNT2024'
}

url = 'https://apid.iproyal.com/v1/reseller/orders/calculate-pricing'
headers = {
    'X-Access-Token': api_token,
    'Content-Type': 'application/json'
}

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

print(response.status_code)
print(response.json())
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const https = require('https');

const api_token = '<your_access_token>';

const params = new URLSearchParams({
  product_id: 123,
  product_plan_id: 456,
  product_location_id: 789,
  quantity: 10,
  coupon_code: 'DISCOUNT2024'
}).toString();

const options = {
  hostname: 'apid.iproyal.com',
  path: `/v1/reseller/orders/calculate-pricing?${params}`,
  method: 'GET',
  headers: {
    'X-Access-Token': api_token,
    'Content-Type': 'application/json'
  }
};

const req = https.request(options, (res) => {
  let responseData = '';

  res.on('data', (chunk) => {
    responseData += chunk;
  });

  res.on('end', () => {
    console.log(responseData);
  });
});

req.on('error', (error) => {
  console.error('Error:', error.message);
});

req.end();
```

{% endtab %}

{% tab title="Java" %}

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String accessToken = "<your_access_token>";
        String url = "https://apid.iproyal.com/v1/reseller/orders/calculate-pricing" +
                "?product_id=123&product_plan_id=456&product_location_id=789&quantity=10&coupon_code=DISCOUNT2024";

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .header("Content-Type", "application/json")
                .header("X-Access-Token", accessToken)
                .GET()
                .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

        System.out.println("Response Code: " + response.statusCode());
        System.out.println("Response Body: " + response.body());
    }
}
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"encoding/json"
	"fmt"
	"io"
	"log"
	"net/http"
	"net/url"
)

const (
	apiToken = "<your_access_token>"
	baseURL  = "https://apid.iproyal.com/v1/reseller/orders/calculate-pricing"
)

func main() {
	params := url.Values{}
	params.Add("product_id", fmt.Sprintf("%d", 123))
	params.Add("product_plan_id", fmt.Sprintf("%d", 456))
	params.Add("product_location_id", fmt.Sprintf("%d", 789))
	params.Add("quantity", fmt.Sprintf("%d", 10))
	params.Add("coupon_code", "DISCOUNT2024")

	fullURL := fmt.Sprintf("%s?%s", baseURL, params.Encode())

	req, err := http.NewRequest(http.MethodGet, fullURL, nil)
	if err != nil {
		log.Fatal("Error creating request:", err)
	}

	req.Header.Set("X-Access-Token", apiToken)
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal("Error making request:", err)
	}
	defer resp.Body.Close()

	fmt.Println("Status Code:", resp.StatusCode)

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		log.Fatal("Error reading response body:", err)
	}

	var jsonResponse map[string]interface{}
	err = json.Unmarshal(responseBody, &jsonResponse)
	if err != nil {
		log.Fatal("Error unmarshaling JSON:", err)
	}

	fmt.Printf("%+v\n", jsonResponse)
}
```

{% endtab %}

{% tab title="C#" %}

```csharp
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text.Json;

class Program
{
    static async Task Main(string[] args)
    {
        string apiToken = "<your_access_token>";
        string url = "https://apid.iproyal.com/v1/reseller/orders/calculate-pricing";

        var queryParams = new Dictionary<string, string>
        {
            { "product_id", "123" },
            { "product_plan_id", "456" },
            { "product_location_id", "789" },
            { "quantity", "10" },
            { "coupon_code", "DISCOUNT2024" }
        };

        using (HttpClient client = new HttpClient())
        {
            client.DefaultRequestHeaders.Add("X-Access-Token", apiToken);

            var urlWithParams = new UriBuilder(url) { Query = await new FormUrlEncodedContent(queryParams).ReadAsStringAsync() }.ToString();

            HttpResponseMessage response = await client.GetAsync(urlWithParams);

            Console.WriteLine((int)response.StatusCode);

            string responseText = await response.Content.ReadAsStringAsync();
            var jsonResponse = JsonSerializer.Deserialize<JsonElement>(responseText);
            Console.WriteLine(jsonResponse);
        }
    }
}
```

{% endtab %}
{% endtabs %}

**示例响应:**

```json
{
    "pre_discount_price": 30,
    "price_with_vat": 30,
    "vat": null,
    "price": 30,
    "pre_discount_price_per_item": 3,
    "price_per_item": 3,
    "plan_discount_percent": 0,
    "location_discount_percent": 0,
    "coupon_discount_percent": 0,
    "quantity_discount_percent": 0,
    "total_discount_percent": 0,
    "quantity_required_for_next_discount": {
        "quantity": 90,
        "discount": 5
    },
    "message": null
}
```

## 创建订单

<mark style="color:blue;">`POST`</mark>  `/orders`

**正文参数**

<table><thead><tr><th width="257">名称</th><th width="114">类型</th><th>描述</th></tr></thead><tbody><tr><td>product_id</td><td>整型</td><td>产品ID</td></tr><tr><td>product_plan_id</td><td>整型</td><td>产品套餐ID</td></tr><tr><td>product_location_id</td><td>整型</td><td>产品地理位置ID</td></tr><tr><td>quantity</td><td>整型</td><td>代理数量</td></tr><tr><td>coupon_code</td><td>字符串</td><td>优惠码</td></tr><tr><td>auto_extend</td><td>布尔值</td><td>订单是否会自动续期</td></tr><tr><td>product_question_answers</td><td>数组</td><td><p>问题解答</p><pre><code>{ question_id: answer, ... }
</code></pre></td></tr></tbody></table>

**响应案例：**

{% tabs %}
{% tab title="cURL" %}

```
curl -X POST "https://apid.iproyal.com/v1/reseller/orders" \
     -H "X-Access-Token: <your_access_token>" \
     -H "Content-Type: application/json" \
     -d '{
           "product_id": 123,
           "product_plan_id": 456,
           "product_location_id": 789,
           "quantity": 10,
           "coupon_code": "DISCOUNT2024",
           "auto_extend": true,
           "product_question_answers": {
               "question_id_1": "answer_1",
               "question_id_2": "answer_2"
           }
         }'
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$api_token = '<your_access_token>';

$url = "https://apid.iproyal.com/v1/reseller/orders";

$data = [
    'product_id' => 123,
    'product_plan_id' => 456,
    'product_location_id' => 789,
    'quantity' => 10,
    'coupon_code' => 'DISCOUNT2024',
    'auto_extend' => true,
    'product_question_answers' => [
        'question_id_1' => 'answer_1',
        'question_id_2' => 'answer_2'
    ]
];

$options = [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        "X-Access-Token: $api_token",
        'Content-Type: application/json'
    ],
    CURLOPT_POSTFIELDS => json_encode($data)
];

$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
} else {
    echo $response;
}

curl_close($ch);
?>

```

{% endtab %}

{% tab title="Python" %}

```python
import requests

api_token = '<your_access_token>'
url = 'https://apid.iproyal.com/v1/reseller/orders'

data = {
    'product_id': 123,
    'product_plan_id': 456,
    'product_location_id': 789,
    'quantity': 10,
    'coupon_code': 'DISCOUNT2024',
    'auto_extend': True,
    'product_question_answers': {
        'question_id_1': 'answer_1',
        'question_id_2': 'answer_2'
    }
}

headers = {
    'X-Access-Token': api_token,
    'Content-Type': 'application/json'
}

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

print(response.status_code)
print(response.json())
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const https = require('https');

const api_token = '<your_access_token>';
const data = JSON.stringify({
  product_id: 123,
  product_plan_id: 456,
  product_location_id: 789,
  quantity: 10,
  coupon_code: 'DISCOUNT2024',
  auto_extend: true,
  product_question_answers: {
    question_id_1: 'answer_1',
    question_id_2: 'answer_2'
  }
});

const options = {
  hostname: 'apid.iproyal.com',
  path: '/v1/reseller/orders',
  method: 'POST',
  headers: {
    'X-Access-Token': api_token,
    'Content-Type': 'application/json',
    'Content-Length': data.length
  }
};

const req = https.request(options, (res) => {
  let responseData = '';

  res.on('data', (chunk) => {
    responseData += chunk;
  });

  res.on('end', () => {
    console.log(responseData);
  });
});

req.on('error', (error) => {
  console.error('Error:', error.message);
});

req.write(data);
req.end();
```

{% endtab %}

{% tab title="Java" %}

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String accessToken = "<your_access_token>";
        String url = "https://apid.iproyal.com/v1/reseller/orders";

        String requestBody = """
            {
                "product_id": 123,
                "product_plan_id": 456,
                "product_location_id": 789,
                "quantity": 10,
                "coupon_code": "DISCOUNT2024",
                "auto_extend": true,
                "product_question_answers": {
                    "question_id_1": "answer_1",
                    "question_id_2": "answer_2"
                }
            }
        """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .header("Content-Type", "application/json")
                .header("X-Access-Token", accessToken)
                .POST(HttpRequest.BodyPublishers.ofString(requestBody))
                .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

        System.out.println("Response Code: " + response.statusCode());
        System.out.println("Response Body: " + response.body());
    }
}
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"log"
	"net/http"
)

const (
	apiToken = "<your_access_token>"
	url      = "https://apid.iproyal.com/v1/reseller/orders"
)

func main() {
	data := map[string]interface{}{
		"product_id":              123,
		"product_plan_id":         456,
		"product_location_id":     789,
		"quantity":                10,
		"coupon_code":             "DISCOUNT2024",
		"auto_extend":             true,
		"product_question_answers": map[string]string{
			"question_id_1": "answer_1",
			"question_id_2": "answer_2",
		},
	}

	jsonData, err := json.Marshal(data)
	if err != nil {
		log.Fatal("Error marshaling JSON:", err)
	}

	req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(jsonData))
	if err != nil {
		log.Fatal("Error creating request:", err)
	}

	req.Header.Set("X-Access-Token", apiToken)
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal("Error making request:", err)
	}
	defer resp.Body.Close()

	fmt.Println("Status Code:", resp.StatusCode)

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		log.Fatal("Error reading response body:", err)
	}

	var jsonResponse map[string]interface{}
	err = json.Unmarshal(responseBody, &jsonResponse)
	if err != nil {
		log.Fatal("Error unmarshaling JSON:", err)
	}

	fmt.Printf("%+v\n", jsonResponse)
}
```

{% endtab %}

{% tab title="C#" %}

```csharp
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        string apiToken = "<your_access_token>";
        string url = "https://apid.iproyal.com/v1/reseller/orders";

        var data = new
        {
            product_id = 123,
            product_plan_id = 456,
            product_location_id = 789,
            quantity = 10,
            coupon_code = "DISCOUNT2024",
            auto_extend = true,
            product_question_answers = new
            {
                question_id_1 = "answer_1",
                question_id_2 = "answer_2"
            }
        };

        using (HttpClient client = new HttpClient())
        {
            client.DefaultRequestHeaders.Add("X-Access-Token", apiToken);

            var jsonData = JsonSerializer.Serialize(data);
            var content = new StringContent(jsonData, Encoding.UTF8, "application/json");

            HttpResponseMessage response = await client.PostAsync(url, content);

            Console.WriteLine((int)response.StatusCode);

            string responseText = await response.Content.ReadAsStringAsync();
            var jsonResponse = JsonSerializer.Deserialize<JsonElement>(responseText);
            Console.WriteLine(jsonResponse);
        }
    }
}
```

{% endtab %}
{% endtabs %}

**响应示例：**

```json
{
    "id": 420,
    "note": null,
    "product_name": "Static Residential",
    "plan_name": "30 Days",
    "expire_date": "2024-04-20 10:25:12",
    "status": "expired",
    "location": "Canada",
    "quantity": 5,
    "questions_answers": [],
    "proxy_data": {
        "ports": {
            "socks5": 12324,
            "http|https": 12323
        },
        "proxies": []
    },
    "auto_extend_settings": null,
    "extended_history": []
}
```

## 续期订单

<mark style="color:blue;">`POST`</mark>  `/orders/{order_id}/extend`

**正文参数**

<table><thead><tr><th width="257">名称</th><th width="114">类型</th><th>描述</th></tr></thead><tbody><tr><td>product_plan_id</td><td>整型</td><td>产品套餐ID</td></tr></tbody></table>

**响应案例：**

{% tabs %}
{% tab title="cURL" %}

```
curl -X POST "https://apid.iproyal.com/v1/reseller/orders/12345/extend" \
     -H "X-Access-Token: <your_access_token>" \
     -H "Content-Type: application/json" \
     -d '{
           "product_plan_id": 678
         }'
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$api_token = '<your_access_token>';
$order_id = 12345;
$product_plan_id = 678;

$url = "https://apid.iproyal.com/v1/reseller/orders/$order_id/extend";

$data = [
    'product_plan_id' => $product_plan_id
];

$options = [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        "X-Access-Token: $api_token",
        'Content-Type: application/json'
    ],
    CURLOPT_POSTFIELDS => json_encode($data)
];

$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
} else {
    echo $response;
}

curl_close($ch);
?>

```

{% endtab %}

{% tab title="Python" %}

```python
import requests

api_token = '<your_access_token>'
order_id = 12345  # pakeiskite su tikru order_id
url = f'https://apid.iproyal.com/v1/reseller/orders/{order_id}/extend'

data = {
    'product_plan_id': 678  # pakeiskite su tikru product_plan_id
}

headers = {
    'X-Access-Token': api_token,
    'Content-Type': 'application/json'
}

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

print(response.status_code)
print(response.json())
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const https = require('https');

const api_token = '<your_access_token>';
const order_id = 12345;
const data = JSON.stringify({
  product_plan_id: 678
});

const options = {
  hostname: 'apid.iproyal.com',
  path: `/v1/reseller/orders/${order_id}/extend`,
  method: 'POST',
  headers: {
    'X-Access-Token': api_token,
    'Content-Type': 'application/json',
    'Content-Length': data.length
  }
};

const req = https.request(options, (res) => {
  let responseData = '';

  res.on('data', (chunk) => {
    responseData += chunk;
  });

  res.on('end', () => {
    console.log(responseData);
  });
});

req.on('error', (error) => {
  console.error('Error:', error.message);
});

req.write(data);
req.end();
```

{% endtab %}

{% tab title="Java" %}

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String accessToken = "<your_access_token>"; 
        String orderId = "12345";
        String url = "https://apid.iproyal.com/v1/reseller/orders/" + orderId + "/extend";

        String requestBody = """
            {
                "product_plan_id": 678
            }
        """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .header("Content-Type", "application/json")
                .header("X-Access-Token", accessToken)
                .POST(HttpRequest.BodyPublishers.ofString(requestBody))
                .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

        System.out.println("Response Code: " + response.statusCode());
        System.out.println("Response Body: " + response.body());
    }
}
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"log"
	"net/http"
)

const (
	apiToken = "<your_access_token>"
	orderID  = 12345
)

func main() {
	url := fmt.Sprintf("https://apid.iproyal.com/v1/reseller/orders/%d/extend", orderID)

	data := map[string]interface{}{
		"product_plan_id": 678,
	}

	jsonData, err := json.Marshal(data)
	if err != nil {
		log.Fatal("Error marshaling JSON:", err)
	}

	req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(jsonData))
	if err != nil {
		log.Fatal("Error creating request:", err)
	}

	req.Header.Set("X-Access-Token", apiToken)
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal("Error making request:", err)
	}
	defer resp.Body.Close()

	fmt.Println("Status Code:", resp.StatusCode)

	responseBody, err := io.ReadAll(resp.Body)
	if err != nil {
		log.Fatal("Error reading response body:", err)
	}

	var jsonResponse map[string]interface{}
	err = json.Unmarshal(responseBody, &jsonResponse)
	if err != nil {
		log.Fatal("Error unmarshaling JSON:", err)
	}

	fmt.Printf("%+v\n", jsonResponse)
}
```

{% endtab %}

{% tab title="C#" %}

```csharp
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        string apiToken = "<your_access_token>";
        int orderId = 12345;
        string url = $"https://apid.iproyal.com/v1/reseller/orders/{orderId}/extend";

        var data = new
        {
            product_plan_id = 678
        };

        using (HttpClient client = new HttpClient())
        {
            client.DefaultRequestHeaders.Add("X-Access-Token", apiToken);

            var jsonData = JsonSerializer.Serialize(data);
            var content = new StringContent(jsonData, Encoding.UTF8, "application/json");

            HttpResponseMessage response = await client.PostAsync(url, content);

            Console.WriteLine((int)response.StatusCode);

            string responseText = await response.Content.ReadAsStringAsync();
            var jsonResponse = JsonSerializer.Deserialize<JsonElement>(responseText);
            Console.WriteLine(jsonResponse);
        }
    }
}
```

{% endtab %}
{% endtabs %}

**响应示例：**

```json
{
    "id": 420,
    "note": null,
    "product_name": "Static Residential",
    "plan_name": "30 Days",
    "expire_date": "2024-04-20 10:25:12",
    "status": "expired",
    "location": "Canada",
    "quantity": 5,
    "questions_answers": [],
    "proxy_data": {
        "ports": {
            "socks5": 12324,
            "http|https": 12323
        },
        "proxies": []
    },
    "auto_extend_settings": null,
    "extended_history": []
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.iproyal.com/cn/dai-li/yun-dong-xie-shu-ju-zhong-xin-dai-li/api/ding-dan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
