批次匯入訂閱
curl --request POST \
--url https://api.zangsho.com/v1/subscriptions/batch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"subscriptions": [
{
"customer_id": 123,
"mrr": "990.00",
"started_at": "2023-11-07T05:31:56Z",
"current_period_start": "2023-11-07T05:31:56Z",
"plan_name": "Pro Plan"
}
],
"on_conflict": "skip"
}
'import requests
url = "https://api.zangsho.com/v1/subscriptions/batch"
payload = {
"subscriptions": [
{
"customer_id": 123,
"mrr": "990.00",
"started_at": "2023-11-07T05:31:56Z",
"current_period_start": "2023-11-07T05:31:56Z",
"plan_name": "Pro Plan"
}
],
"on_conflict": "skip"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
subscriptions: [
{
customer_id: 123,
mrr: '990.00',
started_at: '2023-11-07T05:31:56Z',
current_period_start: '2023-11-07T05:31:56Z',
plan_name: 'Pro Plan'
}
],
on_conflict: 'skip'
})
};
fetch('https://api.zangsho.com/v1/subscriptions/batch', 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.zangsho.com/v1/subscriptions/batch",
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([
'subscriptions' => [
[
'customer_id' => 123,
'mrr' => '990.00',
'started_at' => '2023-11-07T05:31:56Z',
'current_period_start' => '2023-11-07T05:31:56Z',
'plan_name' => 'Pro Plan'
]
],
'on_conflict' => 'skip'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.zangsho.com/v1/subscriptions/batch"
payload := strings.NewReader("{\n \"subscriptions\": [\n {\n \"customer_id\": 123,\n \"mrr\": \"990.00\",\n \"started_at\": \"2023-11-07T05:31:56Z\",\n \"current_period_start\": \"2023-11-07T05:31:56Z\",\n \"plan_name\": \"Pro Plan\"\n }\n ],\n \"on_conflict\": \"skip\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.zangsho.com/v1/subscriptions/batch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"subscriptions\": [\n {\n \"customer_id\": 123,\n \"mrr\": \"990.00\",\n \"started_at\": \"2023-11-07T05:31:56Z\",\n \"current_period_start\": \"2023-11-07T05:31:56Z\",\n \"plan_name\": \"Pro Plan\"\n }\n ],\n \"on_conflict\": \"skip\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.zangsho.com/v1/subscriptions/batch")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"subscriptions\": [\n {\n \"customer_id\": 123,\n \"mrr\": \"990.00\",\n \"started_at\": \"2023-11-07T05:31:56Z\",\n \"current_period_start\": \"2023-11-07T05:31:56Z\",\n \"plan_name\": \"Pro Plan\"\n }\n ],\n \"on_conflict\": \"skip\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"total": 123,
"created": 123,
"updated": 123,
"skipped": 123,
"failed": 123,
"results": {
"created": [
{
"index": 123,
"id": 123,
"identifier": "<string>"
}
],
"updated": [
{
"index": 123,
"id": 123,
"identifier": "<string>"
}
],
"skipped": [
{
"index": 123,
"reason": "duplicate_email",
"identifier": "<string>"
}
],
"failed": [
{
"index": 123,
"reason": "validation_error",
"message": "<string>",
"identifier": "<string>"
}
]
}
}
}{
"message": "Unauthenticated."
}{
"message": "The given data was invalid.",
"errors": {
"email": [
"The email field is required.",
"The email must be a valid email address."
]
}
}訂閱 Subscriptions
批次匯入訂閱
批次建立多筆訂閱。
來源優先順序
api>inferred- API 來源的訂閱可覆蓋系統推導的訂閱
POST
/
subscriptions
/
batch
批次匯入訂閱
curl --request POST \
--url https://api.zangsho.com/v1/subscriptions/batch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"subscriptions": [
{
"customer_id": 123,
"mrr": "990.00",
"started_at": "2023-11-07T05:31:56Z",
"current_period_start": "2023-11-07T05:31:56Z",
"plan_name": "Pro Plan"
}
],
"on_conflict": "skip"
}
'import requests
url = "https://api.zangsho.com/v1/subscriptions/batch"
payload = {
"subscriptions": [
{
"customer_id": 123,
"mrr": "990.00",
"started_at": "2023-11-07T05:31:56Z",
"current_period_start": "2023-11-07T05:31:56Z",
"plan_name": "Pro Plan"
}
],
"on_conflict": "skip"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
subscriptions: [
{
customer_id: 123,
mrr: '990.00',
started_at: '2023-11-07T05:31:56Z',
current_period_start: '2023-11-07T05:31:56Z',
plan_name: 'Pro Plan'
}
],
on_conflict: 'skip'
})
};
fetch('https://api.zangsho.com/v1/subscriptions/batch', 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.zangsho.com/v1/subscriptions/batch",
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([
'subscriptions' => [
[
'customer_id' => 123,
'mrr' => '990.00',
'started_at' => '2023-11-07T05:31:56Z',
'current_period_start' => '2023-11-07T05:31:56Z',
'plan_name' => 'Pro Plan'
]
],
'on_conflict' => 'skip'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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.zangsho.com/v1/subscriptions/batch"
payload := strings.NewReader("{\n \"subscriptions\": [\n {\n \"customer_id\": 123,\n \"mrr\": \"990.00\",\n \"started_at\": \"2023-11-07T05:31:56Z\",\n \"current_period_start\": \"2023-11-07T05:31:56Z\",\n \"plan_name\": \"Pro Plan\"\n }\n ],\n \"on_conflict\": \"skip\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.zangsho.com/v1/subscriptions/batch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"subscriptions\": [\n {\n \"customer_id\": 123,\n \"mrr\": \"990.00\",\n \"started_at\": \"2023-11-07T05:31:56Z\",\n \"current_period_start\": \"2023-11-07T05:31:56Z\",\n \"plan_name\": \"Pro Plan\"\n }\n ],\n \"on_conflict\": \"skip\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.zangsho.com/v1/subscriptions/batch")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"subscriptions\": [\n {\n \"customer_id\": 123,\n \"mrr\": \"990.00\",\n \"started_at\": \"2023-11-07T05:31:56Z\",\n \"current_period_start\": \"2023-11-07T05:31:56Z\",\n \"plan_name\": \"Pro Plan\"\n }\n ],\n \"on_conflict\": \"skip\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"total": 123,
"created": 123,
"updated": 123,
"skipped": 123,
"failed": 123,
"results": {
"created": [
{
"index": 123,
"id": 123,
"identifier": "<string>"
}
],
"updated": [
{
"index": 123,
"id": 123,
"identifier": "<string>"
}
],
"skipped": [
{
"index": 123,
"reason": "duplicate_email",
"identifier": "<string>"
}
],
"failed": [
{
"index": 123,
"reason": "validation_error",
"message": "<string>",
"identifier": "<string>"
}
]
}
}
}{
"message": "Unauthenticated."
}{
"message": "The given data was invalid.",
"errors": {
"email": [
"The email field is required.",
"The email must be a valid email address."
]
}
}Authorizations
使用 Laravel Sanctum Token 進行認證。
Token 可在商家後台的「API 設定」頁面取得。
Body
application/json
Response
批次匯入結果
Show child attributes
Show child attributes
⌘I