---
title: "Update Coupon"
source_url: https://docs.rapyd.net/en/update-coupon.html
lang: en
---

# Update Coupon

Modify the metadata of a coupon.

This method triggers the **Coupon Updated** webhook. This webhook contains the same information as the response.

> **Note:**
>
> - The code samples include successful requests (200) and bad requests (400).
>
>   - For error messages that appear due to bad requests (400), see [General Errors](https://docs.rapyd.net/en/general-errors.md "General Errors").
>   - For information about unauthorized request (401) and other authentication errors, see [Troubleshooting Authentication and Authorization Errors](https://docs.rapyd.net/en/troubleshooting-authentication-and-authorization-errors.md "Troubleshooting Authentication and Authorization Errors").

### Parameters

### Request Path Parameters

- - coupon
  - ID of the coupon. String starting with **coupon_**.

### Request Header Parameters

- - access_key
  - Unique access key provided by Rapyd for each authorized user.

    See [Developers](https://docs.rapyd.net/en/developers.md "Developers").
- - Content-Type
  - Indicates that the data appears in JSON format. Set to **application/json**.
- - idempotency
  - A unique key that prevents the platform from creating the same object twice.

    See [Idempotency](https://docs.rapyd.net/en/idempotency.md "Idempotency").
- - salt
  - Random string. Recommended length: 8-16 characters.
- - signature
  - Signature calculated for each request individually.

    See [Request Signatures](https://docs.rapyd.net/en/request-signatures.md "Request Signatures").
- - timestamp
  - Timestamp for the request, in [Unix time](https://docs.rapyd.net/en/glossary.md#UUID-945d98cf-adae-e1cf-2606-c7fae8b4a7e1_unix_time "Unix time") (seconds).

### Request Body Parameters

- - metadata
  - A JSON object defined by the client. See [Metadata](https://docs.rapyd.net/en/metadata.md "Metadata").

### Response Parameters

- - amount_off
  - The amount of money to subtract from the payment. Decimal. Range: Positive decimal number, including the correct number of decimal places for the currency exponent, as defined in ISO 2417:2015.
- - created
  - When the coupon was created, in [Unix time](https://docs.rapyd.net/en/glossary.md#UUID-945d98cf-adae-e1cf-2606-c7fae8b4a7e1_unix_time "Unix time").
- - currency
  - Three-letter ISO 4217 code for the currency used in the `amount_off` parameter.
- - description
  - Description of the coupon.
- - discount_duration_in_uses
  - The number of times that the coupon can be redeemed by a specific customer or subscription.
- - discount_validity_in_months
  - The number of months after the discount is created that it can be used.
- - discount_valid_until
  - The final date that a discount can be used, in [Unix time](https://docs.rapyd.net/en/glossary.md#UUID-945d98cf-adae-e1cf-2606-c7fae8b4a7e1_unix_time "Unix time").
- - duration
  - Determines how long the discount remains in effect. One of the following:

    - **forever**
    - **repeating**
- - duration_in_months
  - Determines the number of months that the coupon remains in effect after its creation. Integer.
- - id
  - Unique ID for this coupon. English alphanumeric characters with no special characters except underscore. If the merchant does not define an ID, Rapyd generates a string starting with **coupon_**.
- - max_redemptions
  - Determines the number of times the coupon can be redeemed. The number of customers, subscriptions or orders that the coupon is applied to cannot exceed this number. Integer.
- - metadata
  - A JSON object defined by the client. See [Metadata](https://docs.rapyd.net/en/metadata.md "Metadata").
- - percent_off
  - Determines the size of the discount, measured in percent. Integer. Range: 1-100.
- - redeem_by
  - The last time at which the coupon can be redeemed, in [Unix time](https://docs.rapyd.net/en/glossary.md#UUID-945d98cf-adae-e1cf-2606-c7fae8b4a7e1_unix_time "Unix time"). After the `redeem_by` date, the coupon can no longer be applied to new customers. 'redeem_by' takes precedence over the setting of `discount_duration_in_uses` and `duration_in_months`.
- - times_redeemed
  - Indicates the number of times the coupon has been applied to a customer, subscription or invoice. If the discount has been used more than one time by a customer, subscription or invoice, the number of redemptions after the first is also added to this value. Integer.

    When this value equals `max_redemptions`, the coupon becomes no longer valid.
- - valid
  - Indicates whether the coupon can be redeemed.

### Code Samples

- - .NET

    - ```csharp
      using System;
      using System.Text.Json;

      namespace RapydApiRequestSample
      {
          class Program
          {
              static void Main(string[] args)
              {
                  try
                  {
                      var coupon = "coupon_78a69ea113bccfc8a186061e0b96336d";
                      var requestObj = new
                      {
                         metadata = new
                          {
                              coupon_type = "Holiday promotional"
                          }
                      };

                      string request = JsonSerializer.Serialize(requestObj);

                      string result = RapydApiRequestSample.Utilities.MakeRequest("POST", "/v1/coupons/{coupon}", request);

                      Console.WriteLine(result);
                  }
                  catch (Exception e)
                  {
                      Console.WriteLine("Error completing request: " + e.Message);
                  }
              }
          }
      }
      ```
- - JavaScript

    - ```javascript
      const makeRequest = require('<path-to-your-utility-file>/utilities').makeRequest;

      async function main() {
        try {
          const body = {
            metadata: {
              coupon_type: 'Holiday promotional'
            }
          };
          const result = await makeRequest(
            'POST',
            '/v1/coupons/coupon_78a69ea113bccfc8a186061e0b96336d',
            body
          );

          console.log(result);
        } catch (error) {
          console.error('Error completing request', error);
        }
      }
      ```
- - PHP

    - ```php
      <?php
      $path = $_SERVER['DOCUMENT_ROOT'];
      $path .= "/<path-to-your-utility-file>/utilities.php";
      include($path);

      $body = [
          "metadata" => array(
              "coupon_type" => "Holiday promotional"
          )
      ];

      try {
          $object = make_request('post', "/v1/coupons/coupon_78a69ea113bccfc8a186061e0b96336d", $body);
          var_dump($object);
      } catch (Exception $e) {
          echo "Error =>$e";
      }
      ?>
      ```
- - Python

    - ```python
      from pprint import pprint

      from utilities import make_request

      coupon_id = "coupon_78a69ea113bccfc8a186061e0b96336d"
      coupon_data = {
          "metadata": {
              "coupon_type": "Holiday promotional"
          }
      }
      result = make_request(method='post', path=f'/v1/coupons/{coupon_id}', body=coupon_data)
      pprint(result)
      ```

- /v1/coupons/:coupon

- Update Coupon
- ```curl
  curl -X post 'https://sandboxapi.rapyd.net/v1/coupons/coupon_72b8f33846b06f9e7fb0d12cccf98061' \
  -H 'access_key: your-access-key-here' \
  -H 'Content-Type: application/json' \
  -H 'idempotency: your-idempotency-parameter-here' \
  -H 'salt: your-random-string-here' \
  -H 'signature: your-calculated-signature-here' \
  -H 'timestamp: your-unix-timestamp-here' \
  --data-raw '{
      "metadata": {
          "coupon_type": "Holiday promotional"
      }
  }'
  ```
- ```json
  {
      "status": {
          "error_code": "",
          "status": "SUCCESS",
          "message": "",
          "response_code": "",
          "operation_id": "16781943-87e5-49d3-8a99-52de2a894032"
      },
      "data": {
          "id": "coupon_f7c2c630d01a8effe46da9df3d271ad4",
          "amount_off": 0,
          "created": 1764590120,
          "currency": "",
          "duration": "repeating",
          "duration_in_months": 3,
          "max_redemptions": 10,
          "metadata": {
              "coupon_type": "Holiday promotional"
          },
          "percent_off": 10,
          "redeem_by": 0,
          "times_redeemed": 0,
          "discount_valid_until": 0,
          "discount_validity_in_months": 0,
          "discount_duration_in_uses": 0,
          "description": "",
          "valid": true
      }
  }
  ```

- Bad Request - Metadata Wrong Datatype
- ```curl
  curl -X post 'https://sandboxapi.rapyd.net/v1/coupons/coupon_72b8f33846b06f9e7fb0d12cccf98061' \
  -H 'access_key: your-access-key-here' \
  -H 'Content-Type: application/json' \
  -H 'idempotency: your-idempotency-parameter-here' \
  -H 'salt: your-random-string-here' \
  -H 'signature: your-calculated-signature-here' \
  -H 'timestamp: your-unix-timestamp-here' \
  --data-raw '{
      "metadata": "Holiday promotional"
  }'
  ```
- ```json
  {
      "status": {
          "error_code": "ERROR_METADATA_IS_NOT_OBJECT_TYPE",
          "status": "ERROR",
          "message": "The request attempted an operation on metadata, but the metadata was not an object. The request was rejected. Corrective action: For the 'metadata' field, use a JSON object.",
          "response_code": "ERROR_METADATA_IS_NOT_OBJECT_TYPE",
          "operation_id": "d95c7002-69b1-447d-b5dd-99d42d624a03"
      }
  }
  ```
