voucherCreate Mutation
Description
Creates one or more vouchers. If a prefix is provided, a single voucher is created with that prefix as the ID. If no prefix is provided, a voucher code is generated. For gift cards, the ID cannot be manually specified. Returns an array of created vouchers.
mutation voucherCreate(
$amount: Int!
$prefix: String
$codeLength: Int
$singleSpending: Boolean
$unlimited: Boolean
$expires: Date
$type: String
$redeemType: String!
$value: Float
$note: String
$userRef: ID
$id: String
$startDate: Date
$spendingLimit: Int
) {
voucherCreate(
amount: $amount
prefix: $prefix
codeLength: $codeLength
singleSpending: $singleSpending
unlimited: $unlimited
expires: $expires
type: $type
redeemType: $redeemType
value: $value
note: $note
userRef: $userRef
id: $id
startDate: $startDate
spendingLimit: $spendingLimit
) {
_id
type
id
value
originalValue
redeemType
redeemed
isInRange
singleSpending
unlimited
spendings {
orderId
orderRef
amount
origin
date
}
spendingLimit
startDate
expires
resourcePath
user {
type
name
email
ref
}
created
createdBy {
type
name
email
ref
}
note {
date
content
}
logs {
action
description
date
ip
}
recipients {
recipient
date
}
pdf
}
}
Variables
{
"amount": 42,
"prefix": "prefix",
"codeLength": 42,
"singleSpending": true,
"unlimited": true,
"expires": 1761818238002,
"type": "type",
"redeemType": "redeemType",
"value": 30.7,
"note": "note",
"userRef": "0a45633d20f737e3cf1faadd",
"id": "08a16b83-9094-4e89-8c05-2ccadd5c1c7e",
"startDate": 1738236133104,
"spendingLimit": 42
}
Response
{
"voucherCreate": [
{
"_id": "a7cdb8df2036f9ad0b4e6552",
"type": "coupon",
"id": "example",
"value": 1.23,
"originalValue": 1.23,
"redeemType": "value",
"redeemed": true,
"isInRange": true,
"singleSpending": true,
"unlimited": true,
"spendings": [
{
"orderId": "example",
"orderRef": "1cefb7fac9d2fce60677991d",
"amount": 29.99,
"origin": "example",
"date": 1717327720133
}
],
"spendingLimit": 42,
"startDate": 1711462161994,
"expires": 1738060795863,
"resourcePath": "example",
"user": {
"type": "example",
"name": "example",
"email": "email@example.com",
"ref": "b25c2f2d28d2647a5fb14980"
},
"created": 1762620363087,
"createdBy": {
"type": "example",
"name": "example",
"email": "email@example.com",
"ref": "bf5ac5497312cb7dabaf3c42"
},
"note": {
"date": 1729819875723,
"content": "example"
},
"logs": [
{
"action": "example",
"description": "example",
"date": 1715971473209,
"ip": "example"
}
],
"recipients": [
{
"recipient": "example",
"date": 1734909877540
}
],
"pdf": "example"
}
]
}
Arguments
| Name | Type | Description |
|---|---|---|
amount | Int! | Number of vouchers to create. If prefix is provided, this is ignored and a single voucher is created. |
prefix | String | Prefix for the voucher code. If provided, must be at least 4 characters long and a single voucher is created with this prefix as the ID. If not provided, voucher codes are auto-generated. |
codeLength | Int | Length of the generated voucher code when prefix is not provided. Defaults to 6 if not specified. |
singleSpending | Boolean | Whether the voucher can only be used once. This field is deprecated; use spendingLimit instead. |
unlimited | Boolean | Whether the voucher can be used unlimited times. This field is deprecated; use spendingLimit instead. |
expires | Date | Expiration date for the voucher. Must be in the future if provided. If not provided, the voucher does not expire. |
type | String | Voucher type. Valid values include "coupon" for discount coupons or "giftCard" for gift cards. Defaults to "coupon" if not specified. |
redeemType | String! | Redemption type. Valid values include "value" for a fixed amount discount or "percentage" for a percentage discount. |
value | Float | Discount value. For "value" redeemType, this is the fixed amount in the shop's currency. For "percentage" redeemType, this is the percentage discount (e.g., 10 for 10%). Must be greater than 0. |
note | String | Optional note to attach to the voucher. |
userRef | ID | Reference ID of a specific buyer to associate the voucher with. If provided, the voucher is linked to this buyer. |
id | String | Manual voucher ID to use. Only valid for coupons; gift cards cannot have manually specified IDs. If provided and a prefix is also provided, the prefix takes precedence. |
startDate | Date | Start date when the voucher becomes valid. If provided, the voucher cannot be used before this date. If not provided, the voucher is valid immediately. |
spendingLimit | Int | Maximum number of times the voucher can be used. Defaults to 1 if not specified. Use a high number or null for unlimited usage. |
Returns
[Voucher!]!