> ## Documentation Index
> Fetch the complete documentation index at: https://docs.slm.m1amdocs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Campaign.retrieveCouponCodes

Fetches previously generated Coupon Codes.

Coupon Codes must be retrieved before a Campaign is set to Active. Coupon Codes may not be retrieved for an Active Campaign.

For more information on generating Coupon Codes, see Campaign Code Generation and Distribution in the Subscribe User Guide.

If you attempt to retrieve a page of Campaign Codes, and Code generation is not yet complete, `retrieveCouponCodes` will return an error, and the error string will indicate how many Codes have been generated, and how many have been requested. For example:

Campaign codes requested = *nnn*; campaign codes generated = *mmm*.

## Input

*srd*: sparse response description, a SOAP string (which must be a JSON object), in which you specify the elements you want returned.This parameter enables the calling system to constrain a `method` call to return only components you specify. This gives you greater control over returned content, and improves response time within the Vindicia platform by reducing the processing needed for the call.

Some fields are required, either practically or in the WSDL, and will be returned regardless of the *srd*. A null *srd* returns the complete response.

*campaign*: the `Campaign` object for which `CouponCodes` should be returned. Identify this object with its VID or `campaignId`.

*page*: the page number, starting at 0, for which to return the results. For example, if the total number of results is 85 and `pageSize` is 10:

* Specifying 0 for *page* gets the results from 1 through 10.
* Specifying 2 for *page* gets the results from 21 through 30

`pageSize`: the number of records to display per page per call. This value must be greater than 0.

## Output

*return*: an object of type `Return` that indicates the success or failure of the call.

*couponCode*: An array of Coupon Codes fetched.

## Returns

In addition to those listed in [The Return Object](The_Return_Object), this call returns:

| Return Code | Return String |
| - | - |
| `400` | One of the following: - `Page number must be >= 0 and pageSize must be > 0.` - `Can't load Campaign.` - `Claimed to load a campaign by ID but it has no VID.` - `Can't retrieve campaign codes when campaign state is 'Active.'` - `Can't retrieve campaign codes:` - `Coupon codes not initialized.` - `Number of campaign codes requested not yet set up.` - `Number of campaign codes requested is zero.` - `Campaign codes requested = *&lt;requested&gt;*;` - `campaign codes generated = *&lt;generated&gt;*` |

## Example

```

$camp = new Campaign();
$camp->setCampaignId('camp132');
$response = $camp->retrieveCouponCodes(
   0, // page num
   10, // page size
);
$codes = $response['couponCode'];
for ($codes as $c) {
   print "code " . $c->sequence
         . " " . $c->code
         . " " . $c->state
         . "\n";
   }
```

**Parent topic:**[Campaign Methods](../topics/Campaign_Methods)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.