Coupons API

The Coupons API is an integral component of the core service. As a result, all requests should be directed to: https://api.subsbase.io/core/v2/graphql.

The core service expects 2 headers, the X-SITE-ID and Authorization so the request would be:

POST https://api.subsbase.io/core/v2/graphql
Authorization: Bearer {server token}
X-SITE-ID: {your site id}
Consuming the Coupons API requires that a server token is used to authenticate the request. The server token is expected in the Authorization header.

Queries

Coupons Query

query GetCoupons($siteId: null,$filter: FilterGQLInputType,$pagination: PaginationGQLInputType,$sorting: [SortingGQLInputType]) { 
    coupons (siteId: $siteId,filter: $filter,pagination: $pagination,sorting: $sorting) {
        isSuccess
        pagination
        data{
            id
            #All properties are found in the CouponGQLType
        }
        message
    } 
}
  • Request Variables Sample:
{"siteId":"","filter":"","pagination":"","sorting":""}

Coupon Query

query GetCoupon($siteId: String!,$couponId: String!) { 
    coupon (siteId: $siteId,couponId: $couponId) {
        siteId
        id
        name
        value
        #All properties are found in the CouponGQLType
    }
  • Request Variables Sample:
{"siteId":"","couponId":""}

Coupon Mutations/Operations

Create Coupon

  • To create a coupon, you need to use the following Mutation, it is advisable to use variables in this case since the input types are more complex than just strings:
mutation CreateCoupon(
    $siteId: String!
    $coupon: CouponGQLInputType!
    $code: String!
    $quantity: Int!
) {
    coupons(siteId: $siteId) {
        create(coupon: $coupon) {
            withCodes(code: $code, quantity: $quantity) {
                isSuccess
                message
            }
        }
    }
}

### variables
{
    "siteId": "test-site",
    "coupon": {
        "name": "John",
        "value": 50,
        "status": "Active",
        "type": "Percentage"
    },
    "code": "Empty-spaces-1575",
    "quantity": 5
}

Update Coupon

  • To update a coupon, you need to use the following Mutation:
mutation UpdateCoupon(
    $siteId: String!
    $coupon: CouponGQLInputType!
    $couponId: String!
) {
    coupon(siteId: $siteId, couponId: $couponId) {
        update(coupon: $coupon) {
            isSuccess
            message
        }
    }
}

### variables
{
    "siteId": "test-site",
    "couponId": "9a8386cd-23e2-48cf-a0b8-e3fee1b22174",
    "coupon": {
        "type": "percentage",
        "name": "new-name"
    }
}

Delete Coupon

  • To delete a coupon, you need to use the following Mutation:
mutation DeleteCoupon($siteId: String!, $couponId: String!) {
    coupon(siteId: $siteId, couponId: $couponId) {
        delete {
            isSuccess
            message
        }
    }
}

### variables
{
    "siteId": "test-site",
    "couponId": "9a8386cd-23e2-48cf-a0b8-e3fee1b22174"
}

Delete Codes

  • To delete codes, you need to use the following Mutation:
mutation DeleteCodes($siteId: String!, $ids: [String]!) {
    coupon(siteId: $siteId) {
        codes(ids: $ids) {
            delete {
                isSuccess
                message
            }
        }
    }
}

### variables
{
    "siteId": "test-site",
    "ids": [
        "1d7f4491-1773-45c7-8a77-1e80b929e242",
        "26c3f75c-35e1-49a9-8f1f-fec76c709fc3",
        "cdcf338c-30b1-4656-804b-a0637c1b2bfd",
        "e986e2e0-c771-425d-b7ea-872153785e21",
        "efaf8b55-d9e7-4481-8b49-7ab63e148811"
    ]
}

Apply Coupon on Subscription

  • To apply a coupon on a subscription, you need to use the following Mutation:
mutation ApplyCouponOnSubscription(
    $siteId: String!
    $customerId: String!
    $planSubscriptionId: String!
    $couponCode: String!
) {
    customer(siteId: $siteId, customerId: $customerId) {
        subscription(planSubscriptionId: $planSubscriptionId) {
            applyCoupon(couponCode: $couponCode) {
                isSuccess
                message
            }
        }
    }
}

### variables
{
        "siteId": "test-site",
        "customerId": "477a9b74-f959-4cd7-92e5-b978dfb62726",
        "planSubscriptionId": "2d9e18c6-2ca7-4c06-b30a-666a2695e75d",
        "couponCode": "testing-coupon2"
    }