> For the complete documentation index, see [llms.txt](https://wpcloudplugins.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wpcloudplugins.gitbook.io/docs/developers/api/create_shared_url.md). Agents can also search and read this documentation through its [MCP server](https://wpcloudplugins.gitbook.io/docs/~gitbook/mcp).

# create\_shared\_url()

## Create a preview url

&#x20; <mark style="background-color:orange;">create\_preview\_url()</mark> &#x20;

Create a shared url for a file or folder and update its sharing permissions.

{% tabs %}
{% tab title="OneDrive" %}
{% hint style="info" %}
**OneDrive Premium** and **Business** accounts can request an expiring shared link or set a password.
{% endhint %}

### **Parameters**

<table><thead><tr><th width="196">Name</th><th width="87">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>$id</code></td><td>string</td><td>ID of the entry</td></tr><tr><td><code>$param</code></td><td>array</td><td><p>Additional sharing permissions. Defaults to:</p><pre class="language-json"><code class="lang-json">$param = [
  'type' => 'view',
  'scope' => 'anonymous',
];
</code></pre></td></tr></tbody></table>

### **Return**

<table><thead><tr><th width="194">Name</th><th width="238">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>$url</code></td><td>string</td><td>The created shared link</td></tr></tbody></table>

### **Usage**

```php
WPCP_ONEDRIVE_API::set_account_by_id('8c9bacda0-d8d8-4b22-b634-7b5281687575');
WPCP_ONEDRIVE_API::set_drive_by_id('b!DlaHWskCed_MIid3KpJH5Lbatf9HsdXBAZH5YcvPAbMhJUKzTJyzgvXZYpBS');

$params = [
    'type' => 'view',
    'scope' => 'anonymous',
];

// Set password
// !!! Only available for OneDrive Business
$params['password'] = 'mypass1234';

// Set expire date
// !!! Only available for OneDrive Business
$expire_date = current_datetime()->modify('+1 month');
$params['unshared_at'] = $expire_date->setTimezone(new \DateTimeZone('UTC'))->format('Y-m-d\TH:i:s\Z');

// Create / Get shared links
$url = WPCP_ONEDRIVE_API::create_shared_url('01EXLSWHWMQZNDMLRG7NFIWAVYCFJAXP2R', $params);
```

{% endtab %}

{% tab title="Google Drive" %}

### **Parameters**

<table><thead><tr><th width="196">Name</th><th width="87">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>$id</code></td><td>string</td><td>ID of the entry</td></tr><tr><td><code>$params</code></td><td>array</td><td><p>Additional params for sharing permissions. Default: </p><pre class="language-json"><code class="lang-json">$param = [
    'role' => 'reader',
];
</code></pre></td></tr></tbody></table>

### **Return**

<table><thead><tr><th width="194">Name</th><th width="238">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>$url</code></td><td>string</td><td>The created shared link</td></tr></tbody></table>

### **Usage**

```php
WPCP_GDRIVE_API::set_account_by_id('201096615285735764133')

$params = [
  'role' => 'reader'
];

// Create / Get shared links
$url = WPCP_GDRIVE_API::create_shared_url('1wzWlDMsZkA4N5yEEAmMigp52u7M0Lk_7', $params);
```

{% endtab %}

{% tab title="Dropbox" %}
{% hint style="info" %}
**Dropbox Pro**, **Business** and **Enterprise** accounts can request e.g. read\_only or password protected links.
{% endhint %}

### **Parameters**

<table><thead><tr><th width="185">Name</th><th width="124">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>$id</code></td><td>string</td><td>ID of the entry</td></tr><tr><td><code>$param</code></td><td>array</td><td><p>Additional sharing permissions. Defaults to:</p><pre class="language-json"><code class="lang-json">$param = [
    'audience' => 'public',
    'access' => 'viewer',
    'expires' => null,
    'require_password' => null,
    'link_password' => null,
];
</code></pre></td></tr></tbody></table>

### **Return**

<table><thead><tr><th width="184">Name</th><th width="167">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>$url</code></td><td>string</td><td>The created shared link</td></tr></tbody></table>

### **Usage**

```php
WPCP_DROPBOX_API::set_account_by_id('dbid:AADSy6JxzbgqCs4A43CAAAfO9xvZwpcsLU');

// Set password for link
// !!! Only available for Pro, Business
$params = [
    'require_password' => true,
    'link_password' => 'mypass1234',
];

// Set expire date
// !!! Only available for Pro, Business
$expire_date = current_datetime()->modify('+1 month');
$params['expires'] = $expire_date->setTimezone(new \DateTimeZone('UTC'))->format('Y-m-d\TH:i:s\Z');

// Create / Get shared links
$shared_links = WPCP_DROPBOX_API::create_shared_url('id:4tUAwPCAdf0b0AAAAA_iw', $params);
```

{% endtab %}

{% tab title="Box" %}
{% hint style="info" %}
**Box Pro**, **Business** and **Enterprise** accounts can request an expiring shared link.
{% endhint %}

### **Parameters**

<table><thead><tr><th width="212">Name</th><th width="93">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>$id</code></td><td>string</td><td>ID of the entry</td></tr><tr><td><code>$is_dir</code></td><td>bool</td><td>Is the entry a folder or a file?</td></tr><tr><td><code>$param</code></td><td>array</td><td><p>Additional sharing permissions. Defaults to:</p><pre class="language-json"><code class="lang-json">$param = [
  'access' => 'open',
  'password' => null,
  'permissions' => [
      'can_download' => true,
  ],
  'unshared_at' => null,
];
</code></pre></td></tr></tbody></table>

### **Return**

<table><thead><tr><th width="210">Name</th><th width="96">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>$url</code></td><td>string</td><td>The created shared link</td></tr></tbody></table>

### **Usage**

```php
WPCP_BOX_API::set_account_by_id('29232154182');

// Set password for link
$params = [
    'access' => 'open',
    'password' => 'mypass1234',
];

// Set readonly link
$params['permissions']['can_download'] = false;

// Set expire date
// !!! Only available for Pro, Business
$expire_date = current_datetime()->modify('+1 month');
$params['unshared_at'] = $expire_date->format(DATE_RFC3339);

// Create / Get shared links
$shared_links = WPCP_BOX_API::create_shared_url('51142665', $params);
```

{% endtab %}
{% endtabs %}
