# Licence Service

## Request

If you only require Licence API functionality, you can import the module separately to the main SDK.

For example:

```javascript
const { Licence } = require('n-membership-sdk');
const licenceSDK = new Licence(config);
```

## Table of Contents

* [Config](#config)
	* [How to obtain a key](#how-to-obtain-a-key)
* [Methods](#methods)
	* [allocateSeat](#allocateSeat)
	* [getUserAdminLicences](#getUserAdminLicences)

## Config

* See common configuration options in the [README file](./README.doc)
* `LicenceApiKey`

```javascript
const config = new ProductionConfiguration({
	licenceApiKey: 'secret'
});
```

### How to obtain a key

Do one of the following:

1. Check in Doppler for your app to see if a licence service API key already exists.
2. Contact #membership-support slack channel for a licence service key.

## Methods

### allocateSeat

```javascript
const allocatedSeat = licenceSDK.allocateSeat(licenceId, userId, accessDuration);
```

| Parameters     | Required | Type   | Example | Description   |
| -------------- | -------- | -------| --------| ------------- |
| licenceId      | Yes      | String | zyoRrJB7YEJC... | The licence's Id. This can be retrieved from [graphql.getRedeemableToken](GRAPHQL.md#getRedeemableToken) |
| userId         | Yes      | String | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx  | The user's ID. This can be retrieved from [graphql.getUserDetails](GRAPHQL.md#getUserDetails)  |
| accessDuration | Yes      | String | P14D  | The amount of time the user will be allocated the seat on the licence. This can be retrieved from [graphql.getRedeemableToken](GRAPHQL.md#getRedeemableToken) |

**Response**:
```javascript
{
	accessLicenceId: 'licenceId',
	userId: 'id',
	joinedDate: '2019-06-11T13:33:08.641Z',
	seatExpiryDate: null
}
```

### getUserAdminLicences

```javascript
const allocatedSeat = licenceSDK.getUserAdminLicences(userId);
```

| Parameters     | Required | Type   | Example | Description   |
| -------------- | -------- | -------| --------| ------------- |
| userId         | Yes      | String | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx  | The user's ID. This can be retrieved from [graphql.getUserDetails](GRAPHQL.md#getUserDetails)  |


**Response**:
```javascript
[
	{
		"id": "some-uuid-here",
		"creationDateTime": "2017-09-29T15:19:07.222Z",
		"products": [
			{
			"code": "P2",
			"name": "FT.com Premium"
			}
		],
		"issueReason": "Contract Signed",
		"links": [
			{
			"rel": "contract",
			"href": "https://link-to-salesforce",
			"id": "FT-12345678"
			}
		],
		"status": "active",
		"seatLimit": 1000,
		"ipAccessEnabled": false,
		"ipAccessAddresses": [],
		"lastUpdatedDateTime": "2020-03-03T15:41:09.721Z",
		"adminsHref": [
			{
			"rel": "administrators",
			"href": "/licences/some-uuid-here/administrators"
			}
		],
		"seatsHref": [
			{
			"rel": "seats",
			"href": "/licences/some-uuid-here/seats"
			}
		],
		"href": "/licences/some-uuid-here"
	}
]
```

## Membership Documentation

| API Documentation | Confluence  | Description | Owner |
| -------------- | -------- | -------- | -------- |
| [Licence API](https://developer.ft.com/portal/docs-membership-platform-api-access-licence-api-get-licences) |  [Licence Documentation](https://confluence.ft.com/pages/viewpage.action?pageId=25526581) | Documentation for the licence service | FT Core - Membership |
