Create coupon
Route
POST
/api/v1/coupons
Usage
- Curl
- Python
- Ruby
- Node.js
- Go
- C#
- PHP
LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"
curl --location --request POST "$LAGO_URL/api/v1/coupons" \
--header "Authorization: Bearer $API_KEY" \
--header 'Content-Type: application/json' \
--data-raw '{
"coupon": {
"name": "coupon_name",
"code": "coupon_code",
"amount_cents": 5000,
"amount_currency": "USD",
"coupon_type": "fixed_amount",
"reusable": true,
"frequency": "recurring",
"frequency_duration": 3,
"expiration": "time_limit",
"expiration_at": "2022-08-08T23:59:59Z",
"applies_to": {
"plan_codes": ["code1"]
}
}
}'
from lago_python_client import Client
from lago_python_client.models import Coupon
client = Client(api_key='__YOUR_API_KEY__')
coupon = Coupon(
name='name',
code='code_first',
amount_cents=1000,
amount_currency='EUR',
coupon_type='fixed_amount',
frequency='recurring',
frequency_duration=3,
reusable=True
expiration='time_limit',
expiration_at='2022-08-08T23:59:59Z',
applies_to=LimitationConfiguration(plan_codes=['plan1'])
)
client.coupons().create(coupon)
require 'lago-ruby-client'
client = Lago::Api::Client.new({api_key: '__YOUR_API_KEY__'})
coupon = {
name: 'coupon name',
code: 'code',
expiration: 'time_limit',
expiration_at: '2022-08-08T23:59:59Z',
amount_cents: 100,
amount_currency: 'EUR',
coupon_type: 'fixed_amount',
reusable: true,
frequency: 'recurring',
frequency_duration: 3,
applies_to: {
plan_codes: ['code1']
}
}
client.coupons.create(coupon)
import Coupon from 'lago-nodejs-client/coupon'
let client = new Client('__API_KEY__')
let coupon = new Coupon({
name: 'name1',
code: 'code1',
expiration: 'time_limit',
expirationAt: '2022-08-08T23:59:59Z',
amountCents: 10000,
amountCurrency: 'USD',
couponType: 'fixed_amount',
reusable: true,
frequency: 'recurring',
frequencyDuration: 3,
appliesTo: new CouponLimitationConfiguration({
planCodes: ['plan1']
})
})
await client.createCoupon(coupon);
import "fmt"
import "github.com/getlago/lago-go-client"
func main() {
lagoClient := lago.New().
SetApiKey("__YOUR_API_KEY__")
limitationInput := &lago.LimitationInput{
PlanCodes: []string{"code1"}
}
couponInput := &lago.CouponInput{
Name: "Coupon",
Code: "coupon",
AmountCents: 1500,
AmountCurrency: lago.EUR,
Reusable: true,
Expiration: lago.CouponExpirationTimeLimit,
ExpirationAt: "2022-08-08T23:59:59Z",
CouponType: lago.CouponTypeFixedAmount,
Frequency: lago.CouponFrequencyRecurring,
FrequencyDuration: 3,
AppliesTo limitationInput
}
coupon, err := lagoClient.Coupon().Create(couponInput)
if err != nil {
// Error is *lago.Error
panic(err)
}
// coupon is *lago.Coupon
fmt.Println(coupon)
}
using System.Collections.Generic;
using System.Diagnostics;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Model;
namespace Example
{
public class CreateCouponExample
{
public static void Main()
{
Configuration.Default.BasePath = "https://api.getlago.com/api/v1";
// Configure HTTP bearer authorization: bearerAuth
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";
var apiInstance = new CouponsApi(Configuration.Default);
var couponInput = new CouponInput(); // CouponInput | Coupon payload
try
{
// Create a new coupon
Coupon result = apiInstance.CreateCoupon(couponInput);
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling CouponsApi.CreateCoupon: " + e.Message );
Debug.Print("Status Code: "+ e.ErrorCode);
Debug.Print(e.StackTrace);
}
}
}
}
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure Bearer authorization: bearerAuth
$config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
$apiInstance = new OpenAPI\Client\Api\CouponsApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$coupon_input = new \OpenAPI\Client\Model\CouponInput(); // \OpenAPI\Client\Model\CouponInput | Coupon payload
try {
$result = $apiInstance->createCoupon($coupon_input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling CouponsApi->createCoupon: ', $e->getMessage(), PHP_EOL;
}
Arguments
{
"coupon": {
"name": "coupon_name",
"code": "coupon_code",
"amount_cents": 5000,
"amount_currency": "USD",
"expiration": "time_limit",
"expiration_at": "2022-08-08T23:59:59Z",
"coupon_type": "fixed_amount",
"reusable": true,
"frequency": "recurring",
"frequency_duration": 3,
"applies_to": {
"plan_codes": ["code1"]
}
}
}
Attributes | Type | Description |
---|---|---|
name | String Required | Coupon name |
code | String Required | Code identifying the coupon |
amount_cents | Integer Optional (required only for fixed_amount type) | Amount of the coupon |
amount_currency | String Optional (required only for fixed_amount type) | Currency of the amount |
reusable | Boolean Optional | Field specifying if coupon is reusable or not. |
expiration | String Required | Expiration type. It can be time_limit or no_expiration |
expiration_at | String Optional (required only for time_limit type)ISO 8601 datetime in UTC | Expiration date and time of the coupon. |
coupon_type | String Required | Coupon type. It can be fixed_amount or percentage |
frequency | String Required | Frequency type. It can be once or recurring |
frequency_duration | String Optional (required only for recurring frequency type) | This field determines the number of billing periods to which the coupon applies. |
percentage_rate | Float Optional (required only for percentage coupon type) | Rate of the coupon. |
applies_to | Object Optional | Settings with coupon limitations |
Deprecated attributes
Attributes | Type | Description |
---|---|---|
expiration_date | String Optional (required only for time_limit type) | Expiration date of the coupon. Replaced by expiration_at. Value will be converted to "end_of_day" |
Responses
- HTTP 200
- HTTP 400
- HTTP 401
- HTTP 422
The coupon was created
Returns a coupon object.
{
"status": 400,
"error": "Bad Request"
}
The coupon
json root is not present in the request body.
{
"status": 401,
"error": "Unauthorized"
}
Access to the API endpoint is unhautorized.
Possible reasons are:
- The
Authorization
header is missing - The
Authorization
header does not contain the API key - The Api key is invalid or expired
{
"status": 422,
"error": "Unprocessable entity",
"code": "validation_errors",
"error_details": {
"field": ["error"]
}
}
Possible errors:
field | error | description |
---|---|---|
name | value_is_mandatory | name is missing |
code | value_already_exists | code value is already used for another coupon |
amount_cents | value_is_out_of_range | amount_cents value is not a positive integer |
amount_currency | value_is_invalid | Provided currency value is invalid |
expiration_at | invalid_date | Field does not have a valid ISO 8601 datetime format |
expiration_duration | value_is_out_of_range | expiration_duration is not a positive integer |