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": 1736627572797,
"type": "type",
"redeemType": "redeemType",
"value": 30.7,
"note": "note",
"userRef": "0425aa7a5136c0e661955675",
"id": "08a16b83-9094-4e89-8c05-2ccadd5c1c7e",
"startDate": 1748868628364,
"spendingLimit": 42
}
Response
{
"voucherCreate": [
{
"_id": "447275dd5af94ee94899f793",
"type": "coupon",
"id": "example",
"value": 1.23,
"originalValue": 1.23,
"redeemType": "value",
"redeemed": true,
"isInRange": true,
"singleSpending": true,
"unlimited": true,
"spendings": [
{
"orderId": "example",
"orderRef": "5a5617d27179dd16679f03e5",
"amount": 29.99,
"origin": "example",
"date": 1732296963892
}
],
"spendingLimit": 42,
"startDate": 1761022433363,
"expires": 1746314672809,
"resourcePath": "example",
"user": {
"type": "example",
"name": "example",
"email": "email@example.com",
"ref": "9cb78dcb9f89b82774741176"
},
"created": 1710911370434,
"createdBy": {
"type": "example",
"name": "example",
"email": "email@example.com",
"ref": "ffde5d2f66a8e37499cfb9b7"
},
"note": {
"date": 1711506036589,
"content": "example"
},
"logs": [
{
"action": "example",
"description": "example",
"date": 1761292003070,
"ip": "example"
}
],
"recipients": [
{
"recipient": "example",
"date": 1707973402948
}
],
"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!]!