# RedeemableToken Model

## Request

- When requesting `graphql.getRedeemableToken()` a RedeemableToken instance is returned.

```javascript
try {
	const redeemableToken = await graphql.getRedeemableToken(token);
} catch (error) {
	throw error;
}
```

### Required Parameters

| Parameters  | Required | Type   | Description           | Example |
| ----------  | -------- | -------| ----------------------| ------------- |
| token       | Yes      | String | Token to get access to a B2B licence | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |

**Response**: Returns a [RedeemableToken instance](../../src/models/redeemable-token.ts).

## Table of Contents

* [Initiate RedeemableToken Class](#Initiate-RedeemableToken-Class)
* [Properties of the redeemableToken response](#Properties-of-the-redeemableToken-response)
* [Prototypes](#Prototypes)
* [Membership RedeemableToken Response](#Membership-RedeemableToken-Response)

### Initiate RedeemableToken Class

```javascript
 const redeemableTokenInstance = new RedeemableToken(tokenData);
```

| Parameters  | Required | Type   | Description                                | Example |
| ----------  | -------- | ------ | ------------------------------------------ | --------|
| tokenData   | Yes      | Object | A mapped membership graphql redeemableToken data response | see [Membership RedeemableToken Response](#Membership-RedeemableToken-Response) |

The membership response is mapped to the model [here](../../src/mappers/redeemable-token.ts).

### Properties of the redeemableToken response

| Properties  | Type   | Description           | Example                                   |
| ----------  | ------ | --------------------- | ----------------------------------------- |
| id              | String | ID of the token    | 1d2ca849...  |
| accessDuration  | String | Period of time one has access to the licence | P30D |
| accessLicenceId | String | A licence ID  (used to get access to a licence) | 1d2ca777...  |
| externalUserId  | String | A client' specified user identifier | someExtId12...  |
| type            | String | Type of licence    | LICENCE |
| status          | String | Validity of token  | AVAILABLE |
| redeemability   | String | The number of times a token can be redeemed | SINGLE_USE |

### Prototypes

* [isValid](#isValid)
* [isSingleUseToken](#isSingleUseToken)


#### isValid

```javascript
const isTokenValid = redeemableTokenInstance.isValid();
```

- Returns true if token can still be used.
```
	Parameters: none
	Response: boolean
```

#### isSingleUseToken

```javascript
const isSingleUseToken = redeemableTokenInstance.isSingleUseToken();
```

- Returns true if redeemable token is a single use token.
```
	Parameters: none
	Response: boolean
```

### Membership RedeemableToken Response

```javascript
	{
		id: 'tokenId',
		redeemableFor: {
			accessDuration: null,
			licenceId: 'accessLicenceId',
			type: 'LICENCE'
		},
		status: 'AVAILABLE',
		redeemability: 'SINGLE_USE'
	}
```
