# Links

"Link" refers to shortened link. You can *create*, *access*, *update* and *delete* Link.

* [Create](#create)
* [Update](#update)
* [Delete](#delete)
* [Access](#access)
* [Access all links](#alllinks)

## Create link <a href="#create" id="create"></a>

*POST* <https://to.click/api/v1/links>

*HEADERS*

```
X-AUTH-TOKEN: jvuhNJgV59Wo6HRmtVxEgDEU
Content-Type: application/json
```

*BODY*

```
{ "data": { "type": "link", "attributes": { "short_url": "asdasdasd1111", "web_url": "lenta.ru", "pixel_ids": [1] } }}
```

### Sample Request

```
curl --request POST  --url 
https://to.click/api/v1/links
  --header 'Content-Type: application/json'  --header 'X-AUTH-TOKEN: jvuhNJgV59Wo6HRmtVxEgDEU'  
  --data '{ "data": { "type": "link", "attributes": { "short_url": "some_custom_slug", "web_url": "https://lenta.ru", "pixel_ids": [] } }}'
```

| JSON element | Description                             | Type        | Required?                                                                   |
| ------------ | --------------------------------------- | ----------- | --------------------------------------------------------------------------- |
| short\_url   | Short URL will contain this name as URI | String      | No                                                                          |
| web\_url     | URL to redirect if platform is web      | String      | At least one parameter from \[web\_url, ios\_url, android\_url] is required |
| ios\_url     | URL to redirect if platform is iOS      | String      | At least one parameter from \[web\_url, ios\_url, android\_url] is required |
| android\_url | URL to redirect if platform is Android  | String      | At least one parameter from \[web\_url, ios\_url, android\_url] is required |
| pixel\_ids   | Array of pixel IDs to link with         | \[] of Ints | No                                                                          |

### Sample Response

```
{
    "data": {
        "id": "4095",
        "type": "link",
        "attributes": {
            "full_url": "http://clc.la/some_custom_slug",
            "id": 4095,
            "short_url": "some_custom_slug",
            "web_url": "http://lenta.ru",
            "ios_url": null,
            "android_url": null,
            "is_stat_secret": false,
            "created_at": "2018-03-01T12:54:48.728+03:00",
            "ios_fallback_url": null,
            "android_fallback_url": null,
            "kind_of": "short",
            "domain_id": null,
            "pixel_ids": []
        }
    }
}
```

| JSON element           | Descriptions                         | Type       | Can be empty? |
| ---------------------- | ------------------------------------ | ---------- | ------------- |
| short\_url             | Custom part of URI                   | String     | No            |
| full\_url              | Full short URL                       | String     | No            |
| web\_url               | Shortened URL                        | String     | Yes           |
| android\_url           | Shortened URL                        | String     | Yes           |
| ios\_url               | Shortened URL                        | String     | Yes           |
| is\_stat\_secret       | Stat is secret or publicly available | Boolean    | No            |
| created\_at            | Date of creation                     | Datetime   | No            |
| ios\_fallback\_url     | URL to store if app is not installed | String     | Yes           |
| android\_fallback\_url | URL to store if app is not onstalled | String     | Yes           |
| kind\_of               | LInk type                            | String     | No            |
| domain\_id             | ID of your domain                    | Int        | Yes           |
| pixel\_ids             | ID of linked pixels                  | \[] of Int | Yes           |

## Update link <a href="#update" id="update"></a>

*PUT* <https://to.click/api/v1/links/1>

*HEADERS*

```
X-AUTH-TOKEN: jvuhNJgV59Wo6HRmtVxEgDEU
Content-Type: application/json
```

*BODY*

```
{ "data": { "id": "1", "type": "link", "attributes": { "short_url": "asdasdasd", "web_url": "lenta.ru", "pixel_ids": [1,2] } }}
```

### Sample Request

```
 curl --request PUT  --url 
https://to.click/api/v1/links/1
  --header 'Content-Type: application/json'  --header 'X-AUTH-TOKEN: jvuhNJgV59Wo6HRmtVxEgDEU'  
  --data '{ "data": { "id": "1", "type": "link", "attributes": { "short_url": "asdasdasd", "web_url": "lenta.ru", "pixel_ids": [1,2] } }}'
```

## Delete link <a href="#delete" id="delete"></a>

*DELETE* <http://click.to/api/v1/links/2396>

*HEADERS*

```
X-AUTH-TOKEN: jvuhNJgV59Wo6HRmtVxEgDEU
Content-Type: application/json
```

### Sample Request

```
curl --request DELETE  --url 
http://click.to/api/v1/links/2396
  --header 'Content-Type: application/json'  --header 'X-AUTH-TOKEN: jvuhNJgV59Wo6HRmtVxEgDEU'
```

## Access link <a href="#access" id="access"></a>

*GET* <https://to.click/api/v1/links/234>

*HEADERS*

```
X-AUTH-TOKEN: jvuhNJgV59Wo6HRmtVxEgDEU
Content-Type: application/json
```

### Sample Request

```
curl --request GET  --url 
https://to.click/api/v1/links/234
  --header 'Content-Type: application/json'  --header 'X-AUTH-TOKEN: jvuhNJgV59Wo6HRmtVxEgDEU'
```

## Get all links <a href="#alllinks" id="alllinks"></a>

*GET* <https://to.click/api/v1/links>

*HEADERS*

```
X-AUTH-TOKEN: jvuhNJgV59Wo6HRmtVxEgDEU
Content-Type: application/json
```

### Sample Request

```
curl --request GET  --url 
https://to.click/api/v1/links
  --header 'Content-Type: application/json'  --header 'X-AUTH-TOKEN: jvuhNJgV59Wo6HRmtVxEgDEU'
```
