# SIP TN Leases

## AssignTNLeasesToSIPConnection

<mark style="color:green;">`POST`</mark> `https://api.opentact.org/rest/sip/connection/{uuid}/tnlease`

Assign TN Leases to SIP connection.

#### Path Parameters

| Name | Type   | Description                                                      |
| ---- | ------ | ---------------------------------------------------------------- |
| uuid | string | `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$` |

#### Headers

| Name         | Type   | Description      |
| ------------ | ------ | ---------------- |
| X-Auth-Token | string | JWT\_TOKEN       |
| Content-Type | string | application/json |

#### Request Body

| Name   | Type   | Description                                                     |
| ------ | ------ | --------------------------------------------------------------- |
| add    | string | <p>array of strings<br>List of TNLease uuids to be assigned</p> |
| remove | string | <p>Array of strings<br>List of TNLease uuids to be removed</p>  |

{% tabs %}
{% tab title="200 " %}

```javascript
{
  "success": true,
  "payload": [
    {
      "created_on": "2019-08-24T14:15:22Z",
      "modified_on": "2019-08-24T14:15:22Z",
      "uuid": "string",
      "tn": {},
      "account": {},
      "tnorder": {},
      "expired_on": "2019-08-24T14:15:22Z",
      "autorenew": true,
      "messaging_profile": {},
      "class4_product_item_id": 0,
      "sip_connection": {},
      "sip_control_app": {},
      "created_by": {},
      "modified_by": {}
    }
  ]
}
```

{% endtab %}

{% tab title="404 " %}

```javascript
{
  "success": false,
  "message": "string",
  "status": 400
}
```

{% endtab %}
{% endtabs %}

### Code Example

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST "https://api.opentact.org/rest/sip/connection/66eb0a8a-571e-41b1-8f50-4d97275cfab7/tnlease" -H  "accept: application/json" -H  "X-Auth-Token: JWT_TOKEN" -H  "Content-Type: application/json" \
-d "{\"add\":[\"string\"],\"remove\":[\"string\"]}"
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
include('vendor/rmccue/requests/library/Requests.php');
Requests::register_autoloader();
$headers = array(
    'accept' => 'application/json',
    'X-Auth-Token' => 'JWT_TOKEN',
    'Content-Type' => 'application/json'
);
$data = '{"add":["string"],"remove":["string"]}';
$response = Requests::post('https://api.opentact.org/rest/sip/connection/66eb0a8a-571e-41b1-8f50-4d97275cfab7/tnlease', $headers, $data);

```

{% endtab %}

{% tab title="Python" %}

```python
import requests

headers = {
    'accept': 'application/json',
    'X-Auth-Token': 'JWT_TOKEN',
    'Content-Type': 'application/json',
}

data = '{"add":["string"],"remove":["string"]}'

response = requests.post('https://api.opentact.org/rest/sip/connection/66eb0a8a-571e-41b1-8f50-4d97275cfab7/tnlease', headers=headers, data=data)

```

{% endtab %}

{% tab title="Javascript" %}

```javascript
var fetch = require('node-fetch');

fetch('https://api.opentact.org/rest/sip/connection/66eb0a8a-571e-41b1-8f50-4d97275cfab7/tnlease', {
    method: 'POST',
    headers: {
        'accept': 'application/json',
        'X-Auth-Token': 'JWT_TOKEN',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({"add":["string"],"remove":["string"]})
});

```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"strings"
)

func main() {
	client := &http.Client{}
	var data = strings.NewReader(`{"add":["string"],"remove":["string"]}`)
	req, err := http.NewRequest("POST", "https://api.opentact.org/rest/sip/connection/66eb0a8a-571e-41b1-8f50-4d97275cfab7/tnlease", data)
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("accept", "application/json")
	req.Header.Set("X-Auth-Token", "JWT_TOKEN")
	req.Header.Set("Content-Type", "application/json")
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	bodyText, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s\n", bodyText)
}

```

{% endtab %}
{% endtabs %}

###

## GETSIPConnectionTNLeasesList

<mark style="color:blue;">`GET`</mark> `https://api.opentact.org/rest/sip/connection/{uuid}/tnlease`

Get SIP Connection assigned TNLease's

#### Path Parameters

| Name | Type   | Description                                                      |
| ---- | ------ | ---------------------------------------------------------------- |
| uuid | string | `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$` |

#### Headers

| Name         | Type   | Description |
| ------------ | ------ | ----------- |
| X-Auth-Token | string | JWT\_TOKEN  |

{% tabs %}
{% tab title="200 " %}

```javascript
{
  "success": true,
  "payload": [
    {
      "created_on": "2019-08-24T14:15:22Z",
      "modified_on": "2019-08-24T14:15:22Z",
      "uuid": "string",
      "tn": {},
      "account": {},
      "tnorder": {},
      "expired_on": "2019-08-24T14:15:22Z",
      "autorenew": true,
      "messaging_profile": {},
      "class4_product_item_id": 0,
      "sip_connection": {},
      "sip_control_app": {},
      "created_by": {},
      "modified_by": {}
    }
  ]
}
```

{% endtab %}

{% tab title="401 " %}

```javascript
{
  "success": false,
  "message": "string",
  "status": 401
}
```

{% endtab %}

{% tab title="404 " %}

```javascript
{
  "success": false,
  "message": "string",
  "status": 404
}
```

{% endtab %}
{% endtabs %}

### Code Example

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X GET "https://api.opentact.org/rest/sip/connection/66eb0a8a-571e-41b1-8f50-4d97275cfab7/tnlease" \
-H  "accept: application/json" -H  "X-Auth-Token: JWT_TOKEN"
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
include('vendor/rmccue/requests/library/Requests.php');
Requests::register_autoloader();
$headers = array(
    'accept' => 'application/json',
    'X-Auth-Token' => 'JWT_TOKEN'
);
$response = Requests::get('https://api.opentact.org/rest/sip/connection/66eb0a8a-571e-41b1-8f50-4d97275cfab7/tnlease', $headers);

```

{% endtab %}

{% tab title="Python" %}

```python
import requests

headers = {
    'accept': 'application/json',
    'X-Auth-Token': 'JWT_TOKEN',
}

response = requests.get('https://api.opentact.org/rest/sip/connection/66eb0a8a-571e-41b1-8f50-4d97275cfab7/tnlease', headers=headers)

```

{% endtab %}

{% tab title="Javascript" %}

```javascript
var fetch = require('node-fetch');

fetch('https://api.opentact.org/rest/sip/connection/66eb0a8a-571e-41b1-8f50-4d97275cfab7/tnlease', {
    headers: {
        'accept': 'application/json',
        'X-Auth-Token': 'JWT_TOKEN'
    }
});

```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
)

func main() {
	client := &http.Client{}
	req, err := http.NewRequest("GET", "https://api.opentact.org/rest/sip/connection/66eb0a8a-571e-41b1-8f50-4d97275cfab7/tnlease", nil)
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("accept", "application/json")
	req.Header.Set("X-Auth-Token", "JWT_TOKEN")
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	bodyText, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s\n", bodyText)
}

```

{% endtab %}
{% endtabs %}

###
