# Copy a coupon

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


[Idempotency Supported](/docs/api/idempotency)

Copies a coupon over from one site to another. Copying of `[archived](/docs/api/coupons/coupon-object#status)` coupons is not supported.

The item prices that are linked to the coupon in the source site are also linked to the coupon in the destination site. However, this will only work if those item prices exist and with the same `[ids](/docs/api/item_prices/item_price-object#id)`, in the destination site. Hence, it is recommended that the item prices be copied over before copying the coupons.

The value for `[redemptions](/docs/api/coupons/coupon-object#redemptions)` is not copied. It is set to `0` for the newly created coupon. Hence, if such a coupon had `expired` in the source site due to `redemptions` having reached `[max_redemptions](/docs/api/coupons/coupon-object#max_redemptions)`, it's `[status](/docs/api/coupons/coupon-object#status)` would be `active` in the destination site.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/coupons/copy \
     -u {site_api_key}:\
     -d from_site="merchant-test" \
     -d id_at_from_site="copy_coupon"
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Coupon.Copy()
		.FromSite("merchant-test")
		.IdAtFromSite("copy_coupon")
		.Request();

Coupon coupon = result.Coupon;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    couponAction "github.com/chargebee/chargebee-go/v3/actions/coupon"
    "github.com/chargebee/chargebee-go/v3/models/coupon"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := couponAction.Copy(&coupon.CopyRequestParams{
        FromSite : "merchant-test",
        IdAtFromSite : "copy_coupon",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Coupon := res.Coupon
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.CouponCopyRequest{
    FromSite : "merchant-test",
    IdAtFromSite : "copy_coupon",
}
  res, err := client.Coupon.Copy(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Coupon := res.Coupon
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Coupon.copy()
            .fromSite("merchant-test")
            .idAtFromSite("copy_coupon")
            .request();

        Coupon coupon = result.coupon();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.coupon.Coupon;
import com.chargebee.v4.models.coupon.params.CouponCopyParams;
import com.chargebee.v4.models.coupon.responses.CouponCopyResponse;

public class CouponCopy {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        CouponCopyParams params = CouponCopyParams.builder()
            .fromSite("merchant-test")
            .idAtFromSite("copy_coupon")
            .build();

        CouponCopyResponse response = client.coupons().copy(params);

        Coupon coupon = response.getCoupon();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.coupon.copy({
        from_site: "merchant-test",
        id_at_from_site: "copy_coupon"
    });

    console.log(result);
    const coupon = result.coupon;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->coupon()->copy([
    "from_site" => "merchant-test",
    "id_at_from_site" => "copy_coupon"
]);
$coupon = $result->coupon;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Coupon.copy(
    cb_client.Coupon.CopyParams(
        from_site="merchant-test",
        id_at_from_site="copy_coupon"
    )
)
coupon = response.coupon
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::Coupon.copy({
  :from_site => "merchant-test",
  :id_at_from_site => "copy_coupon"
})

coupon = result.coupon
```

## Sample Response

```json
{
  "coupon": {
    "apply_discount_on": "not_applicable",
    "apply_on": "each_specified_item",
    "created_at": 1517495314,
    "currency_code": "USD",
    "discount_amount": 100,
    "discount_type": "fixed_amount",
    "duration_type": "one_time",
    "id": "copy_coupon",
    "item_constraints": [
      {
        "constraint": "all",
        "item_type": "plan"
      },
      {..}
    ],
    "name": "Copy Coupon",
    "object": "coupon",
    "redemptions": 0,
    "resource_version": 1517495314819,
    "status": "active",
    "updated_at": 1517495314
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/coupons/copy

## Input Parameters

- `from_site` (required, string, max chars=50)
  Your Chargebee site name having the coupon to be copied. **Note:** Unless you are copying from a twin site (acme & acme-test are twin sites), [contact support](https://www.chargebee.com/docs/billing/2.0/kb/getting-started/how-to-contact-chargebees-support-team?utm_source=docs_api&utm_medium=content&utm_campaign=support) to have this allow-listed.

- `id_at_from_site` (required, string, max chars=100)
  Id of the coupon to be copied. The new coupon created in this site will have the same Id.

- `id` (optional, string, max chars=100)
  Id of copied coupon in this site.

- `for_site_merging` (optional, boolean, default=false)
  If copy action is performed as part of Chargebee site merge action, pass the value as true. **Note:** If this parameter is passed true coupon state, redmeptions, coupon set and coupon codes associated with this coupon will be copied.

## Returns

- `coupon` (Coupon object)
  Resource object representing coupon
