Coupons
A coupon describes a discount that can be applied to invoices, line items, and subscriptions.
Coupon Object
Attributes
{
"created_at": 1477415090,
"currency": null,
"exclusive": false,
"expiration_date": null,
"id": "S8L47J",
"is_percent": true,
"max_redemptions": 0,
"metadata": [],
"name": "Non-profit Discount",
"object": "coupon",
"updated_at": 1477415090,
"value": 20
}
Parameter | Type | Description |
---|---|---|
id | string | The coupon's unique ID |
object | string | Object type, coupon |
name | string | Coupon name |
currency | string | 3-letter ISO code |
value | number | Amount |
is_percent | boolean | When true the value is a % |
exclusive | boolean | When true no other coupons can be used simultaneously |
expiration_date | timestamp | Date coupon expires |
max_redemptions | integer | Max number of times coupon can be used |
created_at | timestamp | Timestamp when created |
updated_at | timestamp | Timestamp when updated |
metadata | object | A hash of key/value pairs that can store additional information about this object. |
Create a coupon
curl "https://api.invoiced.com/coupons" \
-u {API_KEY}: \
-d id="S8L47J" \
-d name="Non-profit Discount" \
-d value=20 \
invoiced.Coupon.create(
:id => "S8L47J",
:name => "Non-profit Discount",
:value => 20
)
<?php
$invoiced->Coupon->create([
'id' => "S8L47J",
'name' => "Non-profit Discount",
'value' => 20
]);
client.Coupon.create(
id="S8L47J",
name="Non-profit Discount",
value=20
)
Coupon coupon = invoiced.newCoupon();
coupon.id = "S8L47J";
coupon.name = "Non-profit Discount";
coupon.value = 20;
coupon.create();
var coupon = invoiced.NewCoupon();
coupon.Id = "S8L47J";
coupon.Name = "Non-profit Discount";
coupon.Value = 20;
coupon.Create();
coupon, err := client.Coupon.Create(&invoiced.CouponRequest{
Id: invoiced.String("S8L47J"),
Name: invoiced.String("Non-profit Discount"),
Value: invoiced.Float64(20)
})
The above command returns JSON structured like this:
{
"created_at": 1477415090,
"currency": null,
"exclusive": false,
"expiration_date": null,
"id": "S8L47J",
"is_percent": true,
"max_redemptions": 0,
"metadata": [],
"name": "Non-profit Discount",
"object": "coupon",
"updated_at": 1477415090,
"value": 20
}
Create a new coupon with this endpoint.
HTTP Request
POST /coupons
Attributes
Parameter | Type | Description |
---|---|---|
id | string | The coupon's unique ID. Auto-generated by default. |
name | string | Coupon name |
currency | string | 3-letter ISO code |
value | number | Amount |
is_percent | boolean | When true the value is a % |
exclusive | boolean | When true no other coupons can be used simultaneously |
expiration_date | timestamp | Date coupon expires |
max_redemptions | integer | Max number of times coupon can be used |
metadata | object | A hash of key/value pairs that can store additional information about this object. |
Retrieve a coupon
curl "https://api.invoiced.com/coupons/:id" \
-u {API_KEY}:
coupon = invoiced.Coupon.retrieve("{COUPON_ID}")
<?php
$coupon = $invoiced->Coupon->retrieve("{COUPON_ID}");
coupon = client.Coupon.retrieve("{COUPON_ID}")
Coupon coupon = invoiced.newCoupon().retrieve({COUPON_ID});
var coupon = invoiced.NewCoupon().Retrieve({COUPON_ID});
coupon, err := client.Coupon.Retrieve({COUPON_ID})
The above command returns JSON structured like this:
{
"created_at": 1477415090,
"currency": null,
"exclusive": false,
"expiration_date": null,
"id": "S8L47J",
"is_percent": true,
"max_redemptions": 0,
"metadata": [],
"name": "Non-profit Discount",
"object": "coupon",
"updated_at": 1477415090,
"value": 20
}
This endpoint retrieves a specific coupon.
HTTP Request
GET /coupons/:id
Update a coupon
curl "https://api.invoiced.com/coupons/:id" \
-u {API_KEY}: \
-X PATCH \
-d name="Nonprofits"
coupon.name = "Nonprofits"
coupon.save
<?php
$coupon->name = "Nonprofits";
$coupon->save();
coupon.name = "Nonprofits"
coupon.save()
coupon.name = "Nonprofits";
coupon.save();
coupon.Name = "Nonprofits";
coupon.SaveAll();
err := client.Coupon.Update({COUPON_ID}, &invoiced.CouponRequest{
Name: invoiced.String("Nonprofits")
})
The above command returns JSON structured like this:
{
"created_at": 1477415090,
"currency": null,
"exclusive": false,
"expiration_date": null,
"id": "S8L47J",
"is_percent": true,
"max_redemptions": 0,
"metadata": [],
"name": "Nonprofits",
"object": "coupon",
"updated_at": 1477415090,
"value": 20
}
Use this endpoint to update a coupon.
The properties that can be updated via this endpoint are limited. For other updates, it is necessary to delete and recreate the coupon.
HTTP Request
PATCH /coupons/:id
Attributes
Parameter | Type | Description |
---|---|---|
name | string | Coupon name |
metadata | object | A hash of key/value pairs that can store additional information about this object. |
Delete a coupon
curl "https://api.invoiced.com/coupons/:id" \
-u {API_KEY}: \
-X DELETE
coupon.delete
<?php
$coupon->delete();
coupon.delete()
coupon.delete();
coupon.Delete();
err := client.Coupon.Delete({COUPON_ID})
The above command returns
204 No Content
This endpoint deletes a specific coupon.
HTTP Request
DELETE /coupons/:id
List all coupons
curl "https://api.invoiced.com/coupons" \
-u {API_KEY}:
coupons, metadata = invoiced.Coupon.list(:per_page => 3)
<?php
list($coupon, $metadata) = $invoiced->Coupon->all(['per_page' => 3]);
coupons, metadata = client.Coupon.list(per_page=3)
EntityList<Coupon> coupon = conn.newCoupon().listAll();
var coupons = invoiced.NewCoupon().ListAll();
coupons, err := client.Coupon.ListAll(nil, nil)
The above command returns JSON structured like this:
[
{
"created_at": 1477415090,
"currency": null,
"exclusive": false,
"expiration_date": null,
"id": "S8L47J",
"is_percent": true,
"max_redemptions": 0,
"metadata": [],
"name": "Non-profit Discount",
"object": "coupon",
"updated_at": 1477415090,
"value": 20
}
]
This endpoint retrieves all coupons.
HTTP Request
GET /coupons
Query Parameters
Parameter | Description |
---|---|
sort string | Column to sort by, i.e. name asc |
filter object | Filter object |
updated_after timestamp | Only gets records updated after the given timestamp |