# Migrate to unified asset-sharing endpoints

The legacy sharing endpoints are type-specific; each shareable resource type (for example, sheets, reports, and sights) has its own set of sharing endpoints (five endpoints for each type). They're now replaced by a unified set of [five endpoints for sharing **all shareable types**](/api/smartsheet/openapi/sharing), including collections and files.

With the new endpoints, the asset type is a parameter. For example, when you're sharing sheets, set the type to `sheet`; when you're sharing reports, set the type to `report`.

This guide demonstrates sharing an asset (in this case, a sheet) using the Smartsheet SDKs. The other asset sharing operations work similarly.

## New SDK operations

Here is a quick reference to the new **share asset** SDK operations:

Here is a mapping to the new replacement SDK operation reference documentation:

| **SDK** | **Share Asset** |
|  --- | --- |
| C# | ShareAsset() |
| Java | shareTo() |
| Python | share_asset() |
| JavaScript | getWorkspaceMetadata() Refer to the SDK project for details. |


The four other replacement operations are in the same sections as the **share asset** operations listed above.

For listing asset shares, refer to the [List asset shares](/api/smartsheet/openapi/sharing/list-asset-shares) REST operation, the equivalent operation for the SDK you're using, and the [Pagination - SDK examples](/api/smartsheet/guides/basics/pagination-sdk-examples).

## Example code

The code examples below contrast the old operation call to the new operation call.

Refer to them as you follow the migration steps.

Python

```python
# ❌ Old
# Set sharing options
share = smartsheet.models.Share({
    'access_level': 'VIEWER',
    'email': 'jane.doe@smartsheet.com'
  }
)

response = smartsheet_client.Sheets.share_sheet(
  sheet_id, 
  share,
  True  # sendEmail
)

# ✅ New
# Set sharing options
share = smartsheet.models.Share()
share.email = 'jane.doe@smartsheet.com'
share.access_level = 'VIEWER'
share.message = 'Please review this sheet'
share.subject = 'Sheet for review'

result = smartsheet.Sharing.share_asset(
    share_obj=[share],
    asset_type='sheet',
    asset_id=sheet_id,
    send_email=True
)
```

JavaScript

```javascript
// ❌ Old
// Set sharing options
var share = [
  {
    "email": "jane.doe@smartsheet.com",
    "accessLevel": "VIEWER"
  }
];
var options = {
  sheetId: sheetId,
  body: share
};

// Share the asset
smartsheet.sheets.share(options)
  .then(function(addressList) {
    console.log(addressList);
  })
  .catch(function(error) {
    console.log(error);
  });

// ✅ New
// Set sharing options
const shareOptions = {
  queryParameters: {
    assetType: 'sheet',
    assetId: sheetId,
    sendEmail: true
  },
  body: [{
    email: 'jane.doe@smartsheet.com',
    accessLevel: 'VIEWER',
    message: 'Please review this sheet'
  }]
};

// Share the asset
const result = await smartsheet.sharing.shareAsset(shareOptions);
```

Java

```java
// ❌ Old
// Set sharing options
Share shareSpecification = new Share()
        .setEmail("jane.doe@smartsheet.com")
        .setAccessLevel(AccessLevel.VIEWER);

// Share the asset
List<Share> addressList = smartsheet.sheetResources().shareResources().shareTo(
        sheetId,
        (Arrays.asList(shareSpecification)),
        true    // sendEmail
        );

// ✅ New
// Set sharing options
CreateShareRequest shareRequest = new
    CreateShareRequest.CreateShareRequestBuilder()
        .setEmail("jane.doe@smartsheet.com")
        .setAccessLevel(AccessLevel.VIEWER)
        .setMessage("What do you think of this sheet?")
        .setSubject("Sheet for review")
        .build();

List<CreateShareRequest> shareRequests =
    new ArrayList<CreateShareRequest>();
shareRequests.add(shareRequest);

// Share the asset
List<ShareResponse> shareResponses = client.assetShareResources().shareTo(
    sheetId, "sheet", shareRequests, true);
```

C#

```csharp
// ❌ Old
// Set sharing options
Share[] shareSpecification = new Share[] { new Share
  {
    Email = "jane.doe@smartsheet.com",
    AccessLevel = AccessLevel.VIEWER
  }
};

// Share the asset
IList<Share> addressList = smartsheet.SheetResources.ShareResources.ShareTo(
  sheetId, 
  shareSpecification,
  true  // sendEmail
);

// ✅ New
// Set sharing options
CreateShareRequest request = new CreateShareRequest();
request.Email="jane.doe@smartsheet.com";
request.Subject="Sheet for review";
request.Message="Please review this sheet.";
request.AccessLevel=AccessLevel.VIEWER;

// Share the asset
BulkItemResult<AssetShare> itemResult =
    client.AssetSharingResources.ShareAsset(
        assetType: AssetType.SHEET,
        assetId: sheetId, 
        createShareRequests: new List<CreateShareRequest> {request},
        sendEmail: true);
```

## Before you begin

- Back up or branch your code before starting.
- Update your SDK version.


## Migration steps

These steps demonstrate using the new replacement operations. They refer to the new example code.

### Step 1: Set the sharing options

For each user you want to which you want to share the asset, create a share object that declares the user email address and desired permission access level, and any message information, if you're emailing the user.

Optionally, you can share to multiple users by creating a list of share objects.

If you're using the JavaScript SDK, set query parameters for the asset type and asset ID, and set the email option to `true`, if you're emailing the user.

Python

```python
# Set sharing options
share = smartsheet.models.Share()
share.email = 'jane.doe@smartsheet.com'
share.access_level = 'VIEWER'
share.message = 'Please review this sheet'
share.subject = 'Sheet for review'
```

JavaScript

```javascript
// Set sharing options
const shareOptions = {
  queryParameters: {
    assetType: 'sheet',
    assetId: sheetId,
    sendEmail: true
  },
  body: [{
    email: 'jane.doe@smartsheet.com',
    accessLevel: 'VIEWER',
    message: 'Please review this sheet',
    subject('Sheet for review')
  }]
};
```

Java

```java
// Set sharing options
CreateShareRequest shareRequest = new
    CreateShareRequest.CreateShareRequestBuilder()
        .setEmail("jane.doe@smartsheet.com")
        .setAccessLevel(AccessLevel.VIEWER)
        .setMessage("What do you think of this sheet?")
        .setSubject("Sheet for review")
        .build();

List<CreateShareRequest> shareRequests =
    new ArrayList<CreateShareRequest>();
shareRequests.add(shareRequest);
```

C#

```csharp
// Set sharing options
CreateShareRequest request = new CreateShareRequest();
request.Email="jane.doe@smartsheet.com";
request.Message="Please review this sheet.";
request.Subject="Sheet for review";
request.AccessLevel=AccessLevel.VIEWER;
```

### Step 2: Share the asset

Declare the asset type and its ID, and set the email parameter `true` if you're emailing the user.

Python

```python
# Set sharing options
share = smartsheet.models.Share()
share.email = 'jane.doe@smartsheet.com'
share.access_level = 'VIEWER'
share.message = 'Please review this sheet'
share.subject = 'Sheet for review'

# Share the asset
result = smartsheet.Sharing.share_asset(
    share_obj=[share],
    asset_type='sheet',
    asset_id=sheet_id,
    send_email=True
)
```

JavaScript

```javascript
// Set sharing options
const shareOptions = {
  queryParameters: {
    assetType: 'sheet',
    assetId: sheetId,
    sendEmail: true
  },
  body: [{
    email: 'jane.doe@smartsheet.com',
    accessLevel: 'VIEWER',
    message: 'Please review this sheet',
    subject: 'Sheet for review'
  }]
};

// Share the asset
const result = await smartsheet.sharing.shareAsset(shareOptions);
```

Java

```java
// Set sharing options
CreateShareRequest shareRequest = new
    CreateShareRequest.CreateShareRequestBuilder()
        .setEmail("jane.doe@smartsheet.com")
        .setAccessLevel(AccessLevel.VIEWER)
        .setMessage("What do you think of this sheet?")
        .setSubject("Sheet for review")
        .build();

List<CreateShareRequest> shareRequests =
    new ArrayList<CreateShareRequest>();
shareRequests.add(shareRequest);

// Share the asset
List<ShareResponse> shareResponses = client.assetShareResources().shareTo(
    sheetId, "sheet", shareRequests, true);
```

C#

```csharp
// Set sharing options
CreateShareRequest request = new CreateShareRequest();
request.Email="jane.doe@smartsheet.com";
request.Message="Please review this sheet.";
request.Subject="Sheet for review";
request.AccessLevel=AccessLevel.VIEWER;

// Share the asset
BulkItemResult<AssetShare> itemResult =
    client.AssetSharingResources.ShareAsset(
        assetType: AssetType.SHEET,
        assetId: sheetId, 
        createShareRequests: new List<CreateShareRequest> {request},
        sendEmail: true);
```

The asset is shared with the users you specified!

## Common pitfalls

**Forgetting to declare the asset type**

**Declare the type of asset** you're sharing.

## Test your migration

Test your migrated code thoroughly.

Deploy your code to production before the deprecated operation sunsets.

Congratulations on migrating to the new **share asset** operation!

## Related topics

[Pagination - SDK examples](/api/smartsheet/guides/basics/pagination-sdk-examples)

[Token-based pagination](/api/smartsheet/guides/basics/pagination#token-based-pagination)