> ## Documentation Index
> Fetch the complete documentation index at: https://www.1password.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Share items using 1Password SDKs

You can use 1Password SDKs to securely share a copy of a 1Password item with anyone, even if they don't have a 1Password account.

When you share an item, you'll get a unique link that you can send to others. You can choose when the link expires and who it's available to: anyone with the link, or only people with specific email addresses or email domains. You can also choose whether you want the link to be viewable only once, or multiple times.

## Before you get started

Before you begin, [follow the steps to get started](/sdks#get-started) with a 1Password SDK. The examples on this page assume you have an initialized `client` instance. For example:

<Tabs groupId="sdks">
  <Tab value="go" title="Go">
    {/* markdownlint-disable MD046 */}

    ```go theme={null}
    package main

    import (
    	"context"

    	"github.com/1password/onepassword-sdk-go"
    )

    func main() {
    	// TODO: Initialize client using your preferred authentication method (see Overview > Get started)
    	client, err := onepassword.NewClient(context.Background(),
    	)
    	if err != nil {
    		panic(err)
    	}

    	// Your code here
    }

    ```
  </Tab>

  <Tab value="js" title="JavaScript">
    {/* markdownlint-disable MD046 */}

    <Tabs groupId="sdk-before-start-js">
      <Tab value="esm" title="ES Modules">
        ```javascript theme={null}
        import sdk from "@1password/sdk";

        async function main() {
          const client = await sdk.createClient({
            // TODO: Initialize client using your preferred authentication method (see Overview > Get started)
          });

          // Your code here
        }

        main().catch(console.error);

        ```
      </Tab>

      <Tab value="cjs" title="CommonJS">
        ```javascript theme={null}
        const sdk = require("@1password/sdk");

        async function main() {
          const client = await sdk.createClient({
            // TODO: Initialize client using your preferred authentication method (see Overview > Get started)
          });

          // Your code here
        }

        main().catch(console.error);

        ```
      </Tab>
    </Tabs>
  </Tab>

  <Tab value="python" title="Python">
    {/* markdownlint-disable MD046 */}

    ```python theme={null}
    import asyncio

    from onepassword import Client  # Also import DesktopAuth for desktop app authentication.

    async def main():
        # TODO: Initialize client using your preferred authentication method (see Overview > Get started)
        client = await Client.authenticate(...)

        # Your code here

    asyncio.run(main())

    ```
  </Tab>
</Tabs>

<Tip>
  See the examples folder in the 1Password [Go](https://github.com/1Password/onepassword-sdk-go/tree/main/example), [JavaScript](https://github.com/1Password/onepassword-sdk-js/tree/main/examples), or [Python](https://github.com/1Password/onepassword-sdk-python/tree/main/example) SDK GitHub repository for full example code you can quickly clone and test in your project.
</Tip>

<Tip>
  Make sure to add the `Share items` permission when creating a [service account token](/service-accounts/) to share items using the SDKs.
</Tip>

### Step 1: Retrieve the 1Password item you want to share

<Tabs groupId="sdks">
  <Tab value="go" title="Go">
    To retrieve the item you want to share, use the [`Items().Get()`](https://github.com/1Password/onepassword-sdk-go/blob/main/items.go#L96) method with the [unique identifiers (IDs)](/sdks/concepts#unique-identifiers) for the item and the vault where the item is stored.

    ```go theme={null}
    item, err := client.Items().Get(context.Background(), vaultID, itemID)
    if err != nil {
    	panic(err)
    }
    ```
  </Tab>

  <Tab value="js" title="JavaScript">
    To retrieve the item you want to share, use the [`items.get()`](https://github.com/1Password/onepassword-sdk-js/blob/main/client/src/items.ts#L37) method with the [unique identifiers (IDs)](/sdks/concepts#unique-identifiers) for the item and the vault where the item is stored.

    ```js theme={null}
    let item = await client.items.get(vaultId, itemId);
    console.log(item);
    ```
  </Tab>

  <Tab value="python" title="Python">
    To retrieve the item you want to share, use the [`items.get()`](https://github.com/1Password/onepassword-sdk-python/blob/main/src/onepassword/items.py#L74) method with the [unique identifiers (IDs)](/sdks/concepts#unique-identifiers) for the item and the vault where the item is stored.

    ```python theme={null}
    from onepassword import ItemShareDuration, ItemShareParams

    # Get an item to share
    item = await client.items.get("your-vault-id", "your-item-id")
    print(item)
    ```
  </Tab>
</Tabs>

### Step 2: Fetch the item sharing account policy

The item sharing account policy contains the allowed share settings that your account admin or owner has set.

For individual and family accounts, these settings default to:

* Unlimited views
* All recipient types allowed
* All share types allowed
* Maximum share duration of 30 days
* Default share duration of 7 days

<Tabs groupId="sdks">
  <Tab value="go" title="Go">
    To fetch the item sharing account policy, use the [`Items().Shares().GetAccountPolicy()`](https://github.com/1Password/onepassword-sdk-go/blob/main/items_shares.go#L31) method with the [unique identifiers (IDs)](/sdks/concepts#unique-identifiers) for the item and the vault where the item is stored.

    ```go theme={null}
    accountPolicy, err := client.Items().Shares().GetAccountPolicy(context.Background(), item.VaultID, item.ID)
    if err != nil {
    	panic(err)
    }
    ```
  </Tab>

  <Tab value="js" title="JavaScript">
    To fetch the item sharing account policy, use the [`items.shares.getAccountPolicy()`](https://github.com/1Password/onepassword-sdk-js/blob/main/client/src/items_shares.ts#L47) method with the [unique identifiers (IDs)](/sdks/concepts#unique-identifiers) for the item and the vault where the item is stored.

    ```js theme={null}
    let policy = await client.items.shares.getAccountPolicy(
      item.vaultId,
      item.id,
    );
    console.log(policy);
    ```
  </Tab>

  <Tab value="python" title="Python">
    To fetch the item sharing account policy, use the [`items.shares.get_account_policy()`](https://github.com/1Password/onepassword-sdk-python/blob/main/src/onepassword/items_shares.py#L17) method with the [unique identifiers (IDs)](/sdks/concepts#unique-identifiers) for the item and the vault where the item is stored.

    ```python theme={null}
    from onepassword import ItemShareDuration, ItemShareParams

    # Get your item sharing account policy
    policy = await client.items.shares.get_account_policy(item.vault_id, item.id)
    print(policy)
    ```
  </Tab>
</Tabs>

### Step 3: (Optional) Validate the recipients

You can validate recipients to make sure that the people you want to share the link with are allowed to receive it, based on your account policy or sharing parameters.

This step is only required if the item sharing link is limited to specific email addresses or domains. If the share link is accessible to anyone with the link, you can skip validating the recipients.

<Tabs groupId="sdks">
  <Tab value="go" title="Go">
    To validate the recipients, use the [`Items().Shares().ValidateRecipients()`](https://github.com/1Password/onepassword-sdk-go/blob/main/items_shares.go#L16) method. Replace `helloworld@agilebits.com` with the recipient's email address or domain in the example below.

    ```go theme={null}
    recipients, err := client.Items().Shares().ValidateRecipients(context.Background(), accountPolicy, []string{"helloworld@agilebits.com"})
    if err != nil {
    	panic(err)
    }
    ```
  </Tab>

  <Tab value="js" title="JavaScript">
    To validate the recipients, use the [`items.shares.validateRecipients()`](https://github.com/1Password/onepassword-sdk-js/blob/main/client/src/items_shares.ts#L72) method. Replace `helloworld@agilebits.com` with the recipient's email address or domain in the example below.

    ```js theme={null}
    let valid_recipients = await client.items.shares.validateRecipients(policy, [
      "helloworld@agilebits.com",
    ]);

    console.log(valid_recipients);
    ```
  </Tab>

  <Tab value="python" title="Python">
    To validate the recipients, use the [`items.shares.validate_recipients()`](https://github.com/1Password/onepassword-sdk-python/blob/main/src/onepassword/items_shares.py#L38) method. Replace `helloworld@agilebits.com` with the recipient's email address or domain in the example below.

    ```python theme={null}
    from onepassword import ItemShareDuration, ItemShareParams

    # Validate item share recipients
    valid_recipients = await client.items.shares.validate_recipients(
        policy, ["your-recipient-email-address"]
    )

    print(valid_recipients)
    ```
  </Tab>
</Tabs>

### Step 4: Create the item sharing link

<Tip>
  Learn how to [view a shared item](https://support.1password.com/share-items#view-a-shared-item).
</Tip>

<Tabs groupId="sdks">
  <Tab value="go" title="Go">
    Use the [`Items().Shares().Create()`](https://github.com/1Password/onepassword-sdk-go/blob/main/items_shares.go#L65) method to create a unique link you can send to others. This method requires an [`ItemShareParams`](https://github.com/1Password/onepassword-sdk-go/blob/main/types.go#L584) struct with the following fields:

    * `ExpireAfter`: How long the item link will remain accessible. Options include: `OneHour`, `OneDay`, `SevenDays`, `FourteenDays`, `ThirtyDays`. Not specifying this will default to the `DefaultShareDuration` in the account policy.
    * `Recipients`: The validated recipients of an item share, obtained through the recipient validation function. Leaving this parameter empty will allow everyone with the link to see the item.
    * `OneTimeOnly`: A boolean that determines if the link expires after one view.

    The SDK will create the link based on the configuration settings in the `ItemShareParams` struct. If you have a 1Password Business account, it will also validate the settings against the item sharing policy set by your account owner or administrator.

    The SDK returns a `shareLink` you can send to the person or people you want to share the item with.

    ```go theme={null}
    shareLink, err := client.Items().Shares().Create(context.Background(), item, accountPolicy, onepassword.ItemShareParams{
    	Recipients:  recipients,
    	ExpireAfter: &accountPolicy.DefaultExpiry,
    	OneTimeOnly: false,
    })
    if err != nil {
    	panic(err)
    }
    ```
  </Tab>

  <Tab value="js" title="JavaScript">
    Use the [`items.shares.create()`](https://github.com/1Password/onepassword-sdk-js/blob/main/client/src/items_shares.ts#L30) method to create a unique link you can send to others. This method requires an [`ItemShareParams`](https://github.com/1Password/onepassword-sdk-js/blob/main/client/src/types.ts#L445) object with the following properties:

    * `expireAfter`: How long the link will remain accessible. Options include: `OneHour`, `OneDay`, `SevenDays`, `FourteenDays`, `ThirtyDays`. Not specifying this will default to the `DefaultShareDuration` in the account policy.
    * `recipients`: An array of `ValidRecipient` objects. Leave empty to allow anyone with the link to view the shared item.
    * `oneTimeOnly`: A boolean that determines if the link expires after a single view.

    The SDK will create the link based on the configuration settings in the `ItemShareParams` object. If you have a 1Password Business account, it will also validate the settings against the item sharing policy set by your account owner or administrator.

    The SDK returns a `share_link` you can send to the person or people you want to share the item with.

    ```js theme={null}
    let share_link = await client.items.shares.create(item, policy, {
      expireAfter: sdk.ItemShareDuration.OneHour,
      oneTimeOnly: false,
      recipients: valid_recipients,
    });

    console.log(share_link);
    ```
  </Tab>

  <Tab value="python" title="Python">
    Use the [`items.shares.create()`](https://github.com/1Password/onepassword-sdk-python/blob/main/src/onepassword/items_shares.py#L62) method to create a unique link you can send to others. This method requires an [`ItemShareParams`](https://github.com/1Password/onepassword-sdk-python/blob/main/src/onepassword/types.py#L845) object with the following attributes:

    * `expire_after`: How long the item share link will remain accessible. Options include: `OneHour`, `OneDay`, `SevenDays`, `FourteenDays`, `ThirtyDays`. Not specifying this will default to the `DefaultShareDuration` in the account policy.
    * `recipients`: An array of `ValidRecipient` objects. Leave empty to allow anyone with the link to view the shared item.
    * `one_time_only`: A boolean that determines if the link expires after a single view.

    The SDK will create your item share link based on the configuration settings in the `ItemShareParams` object. If you have a 1Password Business account, it will also validate the settings against the item sharing policy set by your account owner or administrator.

    The SDK returns a `share_link` you can send to the person or people you want to share the item with.

    ```python theme={null}
    from onepassword import ItemShareDuration, ItemShareParams

    # Create a unique link to share the item
    share_link = await client.items.shares.create(
        item,
        policy,
        ItemShareParams(
            recipients=valid_recipients,
            expireAfter=ItemShareDuration.ONEHOUR,
            oneTimeOnly=False,
        ),
    )

    print(share_link)
    ```
  </Tab>
</Tabs>
