---
metadata:
  - name: generator
    content: Diplodoc Platform v5.44.0
alternate:
  - https://yandex.ru/dev/disk-api/doc/en/reference/publish.md
  - https://yandex.ru/dev/disk-api/doc/ru/reference/publish.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.ru/dev/disk-api/doc/en/llms.txt

# Publishing a file or folder

You can publish a file or folder stored on Yandex Disk by generating a link that gives other users access to them. Access to previously published resources can be revoked.

A published resource gets two new attributes:

- `public_key` — The key of the published resource. Other apps can use this key to get the [published resource's meta information](https://yandex.ru/dev/disk-api/doc/en/reference/public.md#meta).
- `public_url` — The public link to the resource in the format `https://yadi.sk/...`. With the link, users can open the published folder or download the file.

When the owner restricts access to the resource, these attributes are removed.

[Publishing a resource](#publish-q)

[Restricting access to a resource](#unpublish-q)


## Publishing a resource {#publish-q}

A resource becomes accessible via a direct link. You can only publish a resource using the file owner's OAuth token.

### Request format {#publish-q-request}

Use the PUT method to send a publish request.
```
https://cloud-api.yandex.net/v1/disk/resources/publish
 ? [path](*popup-path)=<path to the resource being published>
```

path[*](*popup-a)
: The path to the resource being published. For example, `%2Fbar%2Fphoto.png`. <br>
  
  <!-- source: en/_includes/reference/parameters-warehouse/id-format/path-encoding.md -->
  The path in the parameter value should be encoded in URL format.
  <!-- endsource: en/_includes/reference/parameters-warehouse/id-format/path-encoding.md -->


\*  Required parameter.

### Response format {#publish-q-response}

If the request is processed without errors, the API returns the `200 OK` code and the published resource's meta information within the [Link](https://yandex.ru/dev/disk-api/doc/en/reference/response-objects.md#link) object in the response body.

Sample response:

```json
{
  "href": "https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2Fbar%2Fphoto.png",
  "method": "GET",
  "templated": false
}
```

<!-- source: en/_includes/reference/response-objects/id-link/link-table.md -->


#|
|| **Element** | **Description**||
|| `href` | URL. It may be a URL template. See the `templated` key. ||
|| `method` | The HTTP method for requesting the URL from the `href` key. ||
|| `templated` | Indicates a URL template according to [RFC 6570](http://tools.ietf.org/html/rfc6570). Possible values:

- "true" — URL template. To send a request to this address, replace the placeholder values in the curly brackets with the parameter values.
- "false" — The URL can be requested without changes.||
   |#
<!-- endsource: en/_includes/reference/response-objects/id-link/link-table.md -->



## Restricting access to a resource {#unpublish-q}

The resource loses the `public_key` and `public_url` attributes, and the public links to it stop working. You can only restrict access to a resource using the resource owner's OAuth token.

### Request format {#unpublish-q-request}

Use the PUT method to restrict access to a resource.
```
https://cloud-api.yandex.net/v1/disk/resources/unpublish
 ? [path](*popup-path2)=<path to the resource being restricted>
```

path[*](*popup-a)

: The path to the resource being restricted. For example, `%2Fbar%2Fphoto.png`. <br>
  
  <!-- source: en/_includes/reference/parameters-warehouse/id-format/path-encoding.md -->
  The path in the parameter value should be encoded in URL format.
  <!-- endsource: en/_includes/reference/parameters-warehouse/id-format/path-encoding.md -->


\*  Required parameter.


### Response format {#unpublish-q-response}

If the request is processed without errors, the API returns the `200 OK` code and the restricted resource's meta information within the [Link](https://yandex.ru/dev/disk-api/doc/en/reference/response-objects.md#link) object in the response body.

Sample response:

```json
{
  "href": "https://cloud-api.yandex.net/v1/disk/resources?path=disk%3A%2Fbar%2Fphoto.png",
  "method": "GET",
  "templated": false
}
```

<!-- source: en/_includes/reference/response-objects/id-link/link-table.md -->


#|
|| **Element** | **Description**||
|| `href` | URL. It may be a URL template. See the `templated` key. ||
|| `method` | The HTTP method for requesting the URL from the `href` key. ||
|| `templated` | Indicates a URL template according to [RFC 6570](http://tools.ietf.org/html/rfc6570). Possible values:

- "true" — URL template. To send a request to this address, replace the placeholder values in the curly brackets with the parameter values.
- "false" — The URL can be requested without changes.||
   |#
<!-- endsource: en/_includes/reference/response-objects/id-link/link-table.md -->

[*popup-path]: The path to the resource being published. For example, `%2Fbar%2Fphoto.png`. <br>
  
  
The path in the parameter value should be encoded in URL format.

[*popup-path2]: The path to the resource being restricted. For example, `%2Fbar%2Fphoto.png`. <br>
  
  
The path in the parameter value should be encoded in URL format.

[*popup-a]: Required parameter.