Create a product
curl --request POST \
--url https://merchant-api-prod.anyway.sh/v1/product \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--header 'X-API-Key: <api-key>' \
--data '
{
"name": "<string>",
"currency": "<string>",
"description": "<string>",
"pricing": "<string>",
"minAmount": 123,
"maxAmount": 123,
"pricingName": "<string>",
"billingIntervalCount": 123,
"status": "PUBLISHED"
}
'import requests
url = "https://merchant-api-prod.anyway.sh/v1/product"
payload = {
"name": "<string>",
"currency": "<string>",
"description": "<string>",
"pricing": "<string>",
"minAmount": 123,
"maxAmount": 123,
"pricingName": "<string>",
"billingIntervalCount": 123,
"status": "PUBLISHED"
}
headers = {
"Idempotency-Key": "<idempotency-key>",
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Idempotency-Key': '<idempotency-key>',
'X-API-Key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: '<string>',
currency: '<string>',
description: '<string>',
pricing: '<string>',
minAmount: 123,
maxAmount: 123,
pricingName: '<string>',
billingIntervalCount: 123,
status: 'PUBLISHED'
})
};
fetch('https://merchant-api-prod.anyway.sh/v1/product', 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://merchant-api-prod.anyway.sh/v1/product",
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([
'name' => '<string>',
'currency' => '<string>',
'description' => '<string>',
'pricing' => '<string>',
'minAmount' => 123,
'maxAmount' => 123,
'pricingName' => '<string>',
'billingIntervalCount' => 123,
'status' => 'PUBLISHED'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>",
"X-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://merchant-api-prod.anyway.sh/v1/product"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"currency\": \"<string>\",\n \"description\": \"<string>\",\n \"pricing\": \"<string>\",\n \"minAmount\": 123,\n \"maxAmount\": 123,\n \"pricingName\": \"<string>\",\n \"billingIntervalCount\": 123,\n \"status\": \"PUBLISHED\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("X-API-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://merchant-api-prod.anyway.sh/v1/product")
.header("Idempotency-Key", "<idempotency-key>")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"currency\": \"<string>\",\n \"description\": \"<string>\",\n \"pricing\": \"<string>\",\n \"minAmount\": 123,\n \"maxAmount\": 123,\n \"pricingName\": \"<string>\",\n \"billingIntervalCount\": 123,\n \"status\": \"PUBLISHED\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://merchant-api-prod.anyway.sh/v1/product")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"currency\": \"<string>\",\n \"description\": \"<string>\",\n \"pricing\": \"<string>\",\n \"minAmount\": 123,\n \"maxAmount\": 123,\n \"pricingName\": \"<string>\",\n \"billingIntervalCount\": 123,\n \"status\": \"PUBLISHED\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"createdAt": "<string>",
"description": "<string>",
"id": "<string>",
"name": "<string>",
"orgId": "<string>",
"paymentLinks": [
{
"amount": 123,
"createdAt": "<string>",
"currency": "<string>",
"flexibleAmount": true,
"isActive": true,
"name": "<string>",
"paymentLinkUrl": "<string>",
"pricingId": "<string>",
"pricingType": "<string>",
"provider": "<string>",
"title": "<string>",
"description": "<string>",
"minAmount": 123,
"maxAmount": 123,
"successUrl": "<string>"
}
],
"productId": "<string>",
"status": "<string>",
"updatedAt": "<string>",
"pricing": {
"pricingId": "<string>",
"currency": "<string>",
"pricing": 123,
"minAmount": 123,
"maxAmount": 123,
"pricingType": "SUBSCRIPTION",
"billingInterval": "DAY",
"billingIntervalCount": 123,
"pricingName": "<string>"
}
},
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}Merchant API 端点
创建产品
创建一个产品及其一个价格。
POST
/
v1
/
product
Create a product
curl --request POST \
--url https://merchant-api-prod.anyway.sh/v1/product \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--header 'X-API-Key: <api-key>' \
--data '
{
"name": "<string>",
"currency": "<string>",
"description": "<string>",
"pricing": "<string>",
"minAmount": 123,
"maxAmount": 123,
"pricingName": "<string>",
"billingIntervalCount": 123,
"status": "PUBLISHED"
}
'import requests
url = "https://merchant-api-prod.anyway.sh/v1/product"
payload = {
"name": "<string>",
"currency": "<string>",
"description": "<string>",
"pricing": "<string>",
"minAmount": 123,
"maxAmount": 123,
"pricingName": "<string>",
"billingIntervalCount": 123,
"status": "PUBLISHED"
}
headers = {
"Idempotency-Key": "<idempotency-key>",
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Idempotency-Key': '<idempotency-key>',
'X-API-Key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: '<string>',
currency: '<string>',
description: '<string>',
pricing: '<string>',
minAmount: 123,
maxAmount: 123,
pricingName: '<string>',
billingIntervalCount: 123,
status: 'PUBLISHED'
})
};
fetch('https://merchant-api-prod.anyway.sh/v1/product', 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://merchant-api-prod.anyway.sh/v1/product",
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([
'name' => '<string>',
'currency' => '<string>',
'description' => '<string>',
'pricing' => '<string>',
'minAmount' => 123,
'maxAmount' => 123,
'pricingName' => '<string>',
'billingIntervalCount' => 123,
'status' => 'PUBLISHED'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>",
"X-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://merchant-api-prod.anyway.sh/v1/product"
payload := strings.NewReader("{\n \"name\": \"<string>\",\n \"currency\": \"<string>\",\n \"description\": \"<string>\",\n \"pricing\": \"<string>\",\n \"minAmount\": 123,\n \"maxAmount\": 123,\n \"pricingName\": \"<string>\",\n \"billingIntervalCount\": 123,\n \"status\": \"PUBLISHED\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("X-API-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://merchant-api-prod.anyway.sh/v1/product")
.header("Idempotency-Key", "<idempotency-key>")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"currency\": \"<string>\",\n \"description\": \"<string>\",\n \"pricing\": \"<string>\",\n \"minAmount\": 123,\n \"maxAmount\": 123,\n \"pricingName\": \"<string>\",\n \"billingIntervalCount\": 123,\n \"status\": \"PUBLISHED\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://merchant-api-prod.anyway.sh/v1/product")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"currency\": \"<string>\",\n \"description\": \"<string>\",\n \"pricing\": \"<string>\",\n \"minAmount\": 123,\n \"maxAmount\": 123,\n \"pricingName\": \"<string>\",\n \"billingIntervalCount\": 123,\n \"status\": \"PUBLISHED\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"createdAt": "<string>",
"description": "<string>",
"id": "<string>",
"name": "<string>",
"orgId": "<string>",
"paymentLinks": [
{
"amount": 123,
"createdAt": "<string>",
"currency": "<string>",
"flexibleAmount": true,
"isActive": true,
"name": "<string>",
"paymentLinkUrl": "<string>",
"pricingId": "<string>",
"pricingType": "<string>",
"provider": "<string>",
"title": "<string>",
"description": "<string>",
"minAmount": 123,
"maxAmount": 123,
"successUrl": "<string>"
}
],
"productId": "<string>",
"status": "<string>",
"updatedAt": "<string>",
"pricing": {
"pricingId": "<string>",
"currency": "<string>",
"pricing": 123,
"minAmount": 123,
"maxAmount": 123,
"pricingType": "SUBSCRIPTION",
"billingInterval": "DAY",
"billingIntervalCount": 123,
"pricingName": "<string>"
}
},
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}请使用属于目标组织、且为全部权限或勾选了
products:products:write 权限的 API 密钥进行认证。只有 Owner 和 Admin 角色可以授予该权限。
- 参数与控制台中创建产品相同:一个产品,一个价格。
- 与控制台不同,该接口不会创建支付链接。如需可分享的链接,请为该产品创建支付链接,或通过结账会话销售该价格(见下文)。
- 必填请求头
Idempotency-Key(1–255 个 ASCII 字符,范围为0x21至0x7E,不允许空格),规则与结账会话相同。相同的键加相同的请求体,返回第一次创建的产品(201),不会重复创建。相同的键但请求体不同,返回409。如果该键创建的产品之后被删除,重试也会返回409,请换一个新的键。 pricingType为ONE_TIME或SUBSCRIPTION。pricing是以主单位表示的字符串,如"19.99"。不传pricing即为灵活的“自定义金额”价格,仅限ONE_TIME,此时minAmount和maxAmount可选。SUBSCRIPTION价格必须提供billingInterval(DAY、MONTH或YEAR)。billingIntervalCount可选,默认为1。status为PUBLISHED(默认)、DRAFT或ARCHIVED。DRAFT状态的产品之后无法发布或归档。如果暂时不想上架,请以ARCHIVED状态创建,准备好后再发布。- 未知字段会被拒绝,返回
400。 - 销售固定价格时,请将返回的
pricing.pricingId作为pricingId传给创建结账会话。结账会话不支持灵活金额;灵活金额请创建支付链接。
| 状态码 | 错误码 | 含义 |
|---|---|---|
400 | 校验失败:货币无效、订阅缺少计费周期、灵活价格的订阅、金额小于或等于 0、未知字段,或缺少 Idempotency-Key 或其无效。 | |
401 | API 密钥缺失或无效。 | |
403 | INSUFFICIENT_SCOPE | 密钥缺少 products:products:write。 |
409 | PRODUCT_CONFLICT | Idempotency-Key 已用于不同的请求体,或它创建的产品已被删除。 |
413 | PAYLOAD_TOO_LARGE | 请求体超过 64 KB。 |
授权
Merchant API key (format: ak_BASE64)
请求头
Unique creation request key: 1-255 ASCII characters in the range 0x21-0x7E (no spaces or control characters)
Required string length:
1 - 255请求体
application/json
Product and price
Product name
可用选项:
SUBSCRIPTION, ONE_TIME Currency code, for example USD
Price in major units, for example "19.99". Omit for a flexible (pay what you want) price, which is ONE_TIME only.
Optional minimum for a flexible price (ONE_TIME only)
Optional maximum for a flexible price (ONE_TIME only)
Name of the price
可用选项:
DAY, MONTH, YEAR Number of intervals between charges (SUBSCRIPTION). Defaults to 1.
可用选项:
PUBLISHED, DRAFT, ARCHIVED