订阅计划
将促销附加到计划
将现有促销附加到订阅计划,适用于一定的收费次数,以便该计划的订阅可以获得该促销
POST
/
subscriptions
/
plans
/
{plan_id}
/
promotions
将促销附加到计划
curl --request POST \
--url https://api-sandbox.y.uno/v1/subscriptions/plans/{plan_id}/promotions \
--header 'Content-Type: application/json' \
--header 'X-Account-Code: <x-account-code>' \
--header 'private-secret-key: <api-key>' \
--header 'public-api-key: <api-key>' \
--data '
{
"promotion_id": "8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10",
"cycles": 3
}
'import requests
url = "https://api-sandbox.y.uno/v1/subscriptions/plans/{plan_id}/promotions"
payload = {
"promotion_id": "8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10",
"cycles": 3
}
headers = {
"X-Account-Code": "<x-account-code>",
"public-api-key": "<api-key>",
"private-secret-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'X-Account-Code': '<x-account-code>',
'public-api-key': '<api-key>',
'private-secret-key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({promotion_id: '8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10', cycles: 3})
};
fetch('https://api-sandbox.y.uno/v1/subscriptions/plans/{plan_id}/promotions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-sandbox.y.uno/v1/subscriptions/plans/{plan_id}/promotions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'promotion_id' => '8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10',
'cycles' => 3
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Account-Code: <x-account-code>",
"private-secret-key: <api-key>",
"public-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-sandbox.y.uno/v1/subscriptions/plans/{plan_id}/promotions"
payload := strings.NewReader("{\n \"promotion_id\": \"8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10\",\n \"cycles\": 3\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Account-Code", "<x-account-code>")
req.Header.Add("public-api-key", "<api-key>")
req.Header.Add("private-secret-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-sandbox.y.uno/v1/subscriptions/plans/{plan_id}/promotions")
.header("X-Account-Code", "<x-account-code>")
.header("public-api-key", "<api-key>")
.header("private-secret-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"promotion_id\": \"8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10\",\n \"cycles\": 3\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-sandbox.y.uno/v1/subscriptions/plans/{plan_id}/promotions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Account-Code"] = '<x-account-code>'
request["public-api-key"] = '<api-key>'
request["private-secret-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"promotion_id\": \"8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10\",\n \"cycles\": 3\n}"
response = http.request(request)
puts response.read_body{
"promotion_id": "8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10",
"name": "Welcome 20% x3",
"type": "AUTOMATIC",
"status": "ENABLED",
"cycles": 3,
"attached_at": "2026-11-02T14:00:00Z",
"on_pause": "KEEP"
}{
"code": "PROMOTION_NOT_FOUND",
"messages": [
"Promotion not found."
]
}{
"code": "PROMOTION_ALREADY_ATTACHED",
"messages": [
"The promotion is already attached to this plan."
]
}{
"code": "PROMOTION_NOT_APPLICABLE",
"messages": [
"The promotion cannot be applied."
],
"reason": "EXPIRED"
}将现有促销附加到计划。之后,该计划上的订阅在创建或更新时即可获得该促销。附加关系决定折扣覆盖的收费次数(
请参阅订阅促销错误代码,了解所有原因。
cycles)以及暂停对其的影响(on_pause)。请参阅订阅计划促销。
响应以及计划 promotions 列表中的每个条目都会显示附加关系的 promotion_id、name、type、status、cycles、on_pause 和 attached_at。
type 是促销的兑换方式:AUTOMATIC(在该计划上创建订阅时自动应用)或 CODE(仅在商户发送其促销码时应用)。
附加关系不可编辑要更改
cycles 或 on_pause,请使用从计划中移除促销移除该附加关系,然后重新附加促销。移除附加关系不会改变已经拥有该促销的订阅。错误
| HTTP | code | 发生情况 |
|---|---|---|
404 | PROMOTION_NOT_FOUND | promotion_id 未知,或属于其他账户。 |
409 | PROMOTION_ALREADY_ATTACHED | 该计划已附加此促销。 |
422 | PROMOTION_NOT_APPLICABLE | 无法附加该促销。reason 说明原因,例如 EXPIRED,或在您的组织未开启促销时为 PROMOTIONS_NOT_ENABLED。 |
503 | PROMOTION_ENGINE_UNAVAILABLE | 促销引擎没有响应。 |
504 | PROMOTION_ENGINE_TIMEOUT | 促销引擎未在规定时间内响应。 |
授权
请求头
您的 Yuno Dashboard 中的 account_id(UUID)。必填:缺少该参数时返回 400 BAD_REQUEST("Invalid x-account-code header.")。
请求体
application/json
此页面对您有帮助吗?
⌘I
将促销附加到计划
curl --request POST \
--url https://api-sandbox.y.uno/v1/subscriptions/plans/{plan_id}/promotions \
--header 'Content-Type: application/json' \
--header 'X-Account-Code: <x-account-code>' \
--header 'private-secret-key: <api-key>' \
--header 'public-api-key: <api-key>' \
--data '
{
"promotion_id": "8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10",
"cycles": 3
}
'import requests
url = "https://api-sandbox.y.uno/v1/subscriptions/plans/{plan_id}/promotions"
payload = {
"promotion_id": "8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10",
"cycles": 3
}
headers = {
"X-Account-Code": "<x-account-code>",
"public-api-key": "<api-key>",
"private-secret-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'X-Account-Code': '<x-account-code>',
'public-api-key': '<api-key>',
'private-secret-key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({promotion_id: '8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10', cycles: 3})
};
fetch('https://api-sandbox.y.uno/v1/subscriptions/plans/{plan_id}/promotions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-sandbox.y.uno/v1/subscriptions/plans/{plan_id}/promotions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'promotion_id' => '8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10',
'cycles' => 3
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-Account-Code: <x-account-code>",
"private-secret-key: <api-key>",
"public-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-sandbox.y.uno/v1/subscriptions/plans/{plan_id}/promotions"
payload := strings.NewReader("{\n \"promotion_id\": \"8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10\",\n \"cycles\": 3\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Account-Code", "<x-account-code>")
req.Header.Add("public-api-key", "<api-key>")
req.Header.Add("private-secret-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-sandbox.y.uno/v1/subscriptions/plans/{plan_id}/promotions")
.header("X-Account-Code", "<x-account-code>")
.header("public-api-key", "<api-key>")
.header("private-secret-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"promotion_id\": \"8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10\",\n \"cycles\": 3\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-sandbox.y.uno/v1/subscriptions/plans/{plan_id}/promotions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Account-Code"] = '<x-account-code>'
request["public-api-key"] = '<api-key>'
request["private-secret-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"promotion_id\": \"8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10\",\n \"cycles\": 3\n}"
response = http.request(request)
puts response.read_body{
"promotion_id": "8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10",
"name": "Welcome 20% x3",
"type": "AUTOMATIC",
"status": "ENABLED",
"cycles": 3,
"attached_at": "2026-11-02T14:00:00Z",
"on_pause": "KEEP"
}{
"code": "PROMOTION_NOT_FOUND",
"messages": [
"Promotion not found."
]
}{
"code": "PROMOTION_ALREADY_ATTACHED",
"messages": [
"The promotion is already attached to this plan."
]
}{
"code": "PROMOTION_NOT_APPLICABLE",
"messages": [
"The promotion cannot be applied."
],
"reason": "EXPIRED"
}