Thư viện QueriesTạo hàng nghìn mã giảm giá cho AppSumo trong FluentCart
Tạo hàng nghìn mã giảm giá cho AppSumo trong FluentCart
Query này kết nối với FluentCart REST API và tạo một trăm mã giảm giá 100% chỉ trong một lần.
Thực thi query này nhiều lần để tạo ra 10.000 mã cần thiết để chạy một chiến dịch AppSumo.
Bạn cần cung cấp:
- Tên đăng nhập và mật khẩu ứng dụng để kết nối với FluentCart REST API, thông qua các biến
$wpUsernamevà$wpApplicationPassword - Tên miền của cửa hàng FluentCart, thông qua biến
$fluentCartDomain - Biến thể sản phẩm cần đổi thưởng bằng mã đó, thông qua biến
$productVariationIDs
Mã giảm giá được tạo ra sẽ là một chuỗi ngẫu nhiên. Bạn có thể thêm tiền tố vào mã (thông qua biến $codePrefix), chỉ định độ dài của mã (thông qua biến $codeLength), và tùy chỉnh tên của mã giảm giá (thông qua các biến $discountNamePrefix và $firstRecordNumber) để tìm kiếm trong bảng điều khiển FluentCart.
Thu thập tất cả các mã giảm giá mới được tạo bằng cách cung cấp $postId, sau đó tất cả các mã sẽ được thêm vào cuối bài đăng đó.
# Export FluentCart API config and build mutation inputs for creating coupons.
# FluentCart REST API: { fluentCartDomain }/wp-json/fluent-cart/v2
# Auth: WordPress Application Passwords (Basic auth: username + application_password)
# Create Coupon: POST /coupons — https://dev.fluentcart.com/restapi/operations/coupons/create-coupon
query ExportFluentCartAPIData(
$fluentCartDomain: String!,
$fluentCartBaseURL: String! = "wp-json/fluent-cart/v2",
$postId: ID,
) {
fluentCartCouponsURL: _sprintf(
string: "%s/%s/coupons",
values: [$fluentCartDomain, $fluentCartBaseURL]
)
@export(as: "fluentCartCouponsURL")
@remove
hasPostId: _notEmpty(value: $postId)
@export(as: "hasPostId")
}
query CreateMutationInputs(
$wpUsername: String!,
$wpApplicationPassword: String!,
$discountNamePrefix: String! = "AppSumo campaign",
$discountNotes: String! = "",
$codePrefix: String! = "",
$numberCodes: Int! = 100,
$codeLength: Int! = 16,
$firstRecordNumber: Int! = 1,
$productVariationIDs: [ID!],
)
@depends(on: "ExportFluentCartAPIData")
{
mutationInputs: _arrayPad(array: [], length: $numberCodes, value: null)
@underEachArrayItem(
passIndexOnwardsAs: "key"
affectDirectivesUnderPos: [1, 2, 3, 4, 5]
)
@applyField(
name: "_generateRandomString",
arguments: {
length: $codeLength,
characters: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
},
passOnwardsAs: "randomCode"
)
@applyField(
name: "_strAppend",
arguments: {
after: $codePrefix,
append: $randomCode,
},
passOnwardsAs: "discountCode"
)
@applyField(
name: "_intAdd",
arguments: {
add: $key,
to: $firstRecordNumber,
},
passOnwardsAs: "recordNumber"
)
@applyField(
name: "_sprintf",
arguments: {
string: "%s #%s",
values: [$discountNamePrefix, $recordNumber],
},
passOnwardsAs: "discountName"
)
@applyField(
name: "_echo",
arguments: {
value: {
url: $fluentCartCouponsURL,
method: POST,
options: {
auth: {
username: $wpUsername,
password: $wpApplicationPassword,
},
headers: [
{
name: "Content-Type",
value: "application/json",
},
],
json: {
title: $discountName,
code: $discountCode,
type: "percentage",
amount: 100,
status: "active",
stackable: "no",
show_on_checkout: "no",
priority: 0,
notes: $discountNotes,
conditions: {
max_uses: 1,
included_products: $productVariationIDs
}
}
}
}
},
setResultInResponse: true
)
@export(as: "mutationInputs")
@remove
}
query CreateCouponsInFluentCart
@depends(on: "CreateMutationInputs")
{
createCouponsInFluentCart: _sendJSONObjectItemHTTPRequests(inputs: $mutationInputs)
@underEachArrayItem
@underJSONObjectProperty(by: { path: "data.code" })
@export(as: "discountCodes")
}
query PrintDiscountCodesFromFluentCart
@depends(on: "CreateCouponsInFluentCart")
{
discountCodes: _echo(value: $discountCodes)
}
query GetPostWithDiscountCodes($postId: ID)
@depends(on: "CreateCouponsInFluentCart")
@include(if: $hasPostId)
{
post(by: { id: $postId }, status: any) {
title
postContent: rawContent
discountCodesAsContent: _arrayJoin(
array: $discountCodes,
separator: "\n"
)
updatedPostContent: _sprintf(
string: "%s\n%s"
values: [$__postContent, $__discountCodesAsContent]
)
@export(as: "updatedPostContent")
}
}
mutation UpdatePostWithDiscountCodes($postId: ID)
@depends(on: "GetPostWithDiscountCodes")
@include(if: $hasPostId)
{
updatePost(input: {
id: $postId,
contentAs: { html: $updatedPostContent },
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
title
rawContent
}
}
}...truyền các biến sau:
{
"fluentCartDomain": "{ fluentCartDomain }",
"wpUsername": "{ username }",
"wpApplicationPassword": "{ appPassword }",
"codeLength": 24,
"codePrefix": "APS2V1T1",
"discountNamePrefix": "AppSumo campaign@2",
"postId": "{ postId }",
"discountNotes": "AppSumo campaign #2, starting on 26/03/2026",
"productVariationIDs": [ "{ productVariationID }" ]
}