پرش به مطلب اصلی

Use Coupon Code API

POST /useCouponCode

Description

This API endpoint allows users to use a coupon code. It processes the coupon code and, if valid, updates its status and applies the discount associated with it.

Request Body

The request utilizes GraphQL to perform the useCouponCode mutation.

Mutation:

mutation useCouponCode ($code: String) {
useCouponCode (code: $code) {
id
couponCode
startDate
expiryDate
discountRate
quantity
createdAt
}
}

Variables:

{
"code": "<Coupon_Code>"
}
  • code (String): The coupon code to use.

Response:

  • Success (200 OK):

    • If the coupon code is valid and successfully used, the response will include the updated details of the coupon.
    {
    "data": {
    "useCouponCode": {
    "id": <Coupon_Id>,
    "couponCode": "<Coupon_Code>",
    "startDate": "<Start_Date>",
    "expiryDate": "<Expiry_Date>",
    "discountRate": <Discount_Rate>,
    "quantity": <Quantity>,
    "createdAt": "<Creation_Date>"
    }
    }
    }
  • Error (4XX/5XX):

    • If the coupon code is invalid, expired, or there is an issue with the request, the response will include an appropriate error message and status code.

Note:

Ensure the code is correctly formatted. If the coupon code is invalid, expired, or already used, the response will indicate this in the error message.