# Migrate from `GET /workspaces/{id}`  for workspace and child metadata

The **GET /2.0/workspaces/{id}** legacy operation (without the `loadAll=true` parameter) retrieves the workspace's metadata and its immediate children, including its folders, sheets, reports, templates, and dashboards. The operation is deprecated and is replaced by the following two operations:

- [GET /2.0/workspaces/{workspaceId}/metadata](/api/smartsheet/openapi/workspaces/get-workspace-metadata) (**get workspace metadata**) returns information describing the workspace.
- [GET /2.0/workspaces/{workspaceId}/children](/api/smartsheet/openapi/workspaces/get-workspace-children) (**get workspace children**) returns basic, paginated reference information about the workspace's immediate child items.


**Get workspace children includes Templates**

You can now list your **Templates** via the **get workspace children** operation.

## New SDK operations

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

| **SDK** | **Get Workspace Metadata** | **Get Workspace Children** |
|  --- | --- | --- |
| C# | GetWorkspaceMetadata() | GetWorkspaceChildren() |
| Java | getWorkspaceMetadata() | getWorkspaceChildren() |
| JavaScript | getWorkspaceMetadata() Refer to the SDK project for details. | getWorkspaceChildren() Refer to the SDK project for details. |
| Python | get_workspace_metadata() | get_workspace_children() |


This article describes what changed between the old and new way, and demonstrates migrating from the `GET /2.0/workspaces/{workspaceId}` REST operation (and equivalent SDK operations) to the new SDK operations.

If you're currently using the **loadAll=true** parameter in calls to `GET /2.0/workspaces/{workspaceId}?loadAll=true` or equivalent SDK operations, refer to the [Migrate from GET /workspaces/{id} for workspace hierarchies](/api/smartsheet/guides/updating-code/migrate-from-get-workspaces-loadall) article.

## Example code

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

Refer to them as you follow the migration steps.

Python

```python
# ❌ Old
folders = []
sheets = []
reports = []
sights = []
templates = []

response = smart.Workspaces.get_workspace(workspace_id)
assert isinstance(response, smartsheet.models.workspace.Workspace)

workspace = response

for child in response.folders:
    folders.append(child)
for child in response.sheets:
    sheets.append(child)
for child in response.reports or []:
    reports.append(child)
for child in response.sights or []:
    sights.append(child)
for child in response.templates or []:
    templates.append(child)

# ✅ New
folders = []
sheets = []
reports = []
sights = []
templates = []

response = smart.Workspaces.get_workspace_metadata(workspace_id)
assert isinstance(response, smartsheet.models.workspace.Workspace)

workspace = response.name, response.id, response.permalink, response.access_level, response.created_at, response.modified_at

last_key = None
while True:
    response = smart.Workspaces.get_workspace_children(
        workspace_id, last_key=last_key
    )
    assert isinstance(
        response,
        smartsheet.models.paginated_children_result.PaginatedChildrenResult
    )

    for child in response.data:
        if type(child) is Folder:
            folders.append(child)
        elif type(child) is Sheet:
            sheets.append(child)
        elif type(child) is Report:
            reports.append(child)
        elif type(child) is Sight:
            sights.append(child)
        elif type(child) is Template:
            templates.append(child)

    last_key = getattr(response, "last_key", None)
    if not last_key:
        break
```

JavaScript

```javascript
// ❌ Old
const workspace = await client.workspaces.getWorkspace({ workspaceId });
const sheets = workspace.sheets;
const reports = workspace.reports;
const sights = workspace.sights;
const folders = workspace.folders;
const templates = workspace.templates;

// ✅ New
const workspace = await client.workspaces.getWorkspaceMetadata({ workspaceId });
const sheets = [];
const reports = [];
const sights = [];
const folders = [];
const templates = [];
let lastKey = '';

do {
    const page = await client.workspaces.getWorkspaceChildren({
        workspaceId,
        queryParameters: { lastKey },
    });
    const children = page?.data ?? [];
    for (const child of children) {
        switch (child?.resourceType) {
        case 'sheet':
            sheets.push(child);
            break;
        case 'report':
            reports.push(child);
            break;
        case 'sight':
            sights.push(child);
            break;
        case 'folder':
            folders.push(child);
            break;
        case 'template':
            templates.push(child);
            break;
        default:
            break;
        }
    }
    lastKey = page?.lastKey;
} while (lastKey);
```

Java

```java
// ❌ Old
Workspace workspace = client.workspaceResources().getWorkspace(workspaceId, null, null);

List<Sheet> sheets = workspace.getSheets();
List<Report> reports = workspace.getReports();
List<Sight> sights = workspace.getSights();
List<Template> templates = workspace.getTemplates();
List<Folder> folders = workspace.getFolders();

// ✅ New
Workspace workspaceMetadata = client.workspaceResources().getWorkspaceMetadata(workspaceId, null);

List<Sheet> sheets = new ArrayList<>();
List<Report> reports = new ArrayList<>();
List<Sight> sights = new ArrayList<>();
List<Template> templates = new ArrayList<>();
List<Folder> folders = new ArrayList<>();

String lastKey = null;
do {
    TokenPaginatedResult<Object> response = client.workspaceResources()
            .getWorkspaceChildren(workspaceId, null, null, lastKey, null);

    for (Object child : response.getData()) {
        if (child instanceof Folder folder) {
            folders.add(folder);
        } else if (child instanceof Report report) {
            reports.add(report);
        } else if (child instanceof Sheet sheet) {
            sheets.add(sheet);
        } else if (child instanceof Sight sight) {
            sights.add(sight);
        } else if (child instanceof Template template) {
            templates.add(template);
        }
    }

    lastKey = response.getLastKey();
} while (lastKey != null && !lastKey.isBlank());
```

C#

```csharp
// ❌ Old
// Get the workspace metadata and abbreviated metadata on its immediate children
Workspace workspace = client.WorkspaceResources.GetWorkspace(workspaceId, null, null);
var folders = workspace.Folders;
var sheets = workspace.Sheets;
var reports = workspace.Reports;
var sights = workspace.Sights;
var templates = workspace.Templates;

// ✅ New
// Get the workspace metadata
Workspace workspace = client.WorkspaceResources.GetWorkspaceMetadata(workspaceId);
List<Sheet> sheets = new();
List<Folder> folders = new();
List<Report> reports = new();
List<Sight> sights = new();
List<Template> templates = new();
// Get metadata on the immediate workspace children with pagination
string? lastKey = null;
do
{
    TokenPaginatedResult<object> page = client.WorkspaceResources.GetWorkspaceChildren(
        workspaceId,
        childrenResourceTypes: null,
        include: null,
        numericDates: null,
        accessApiLevel: null,
        lastKey: lastKey,
        maxItems: null);

    foreach (var item in page.Data)
    {
        // Check each child item's type
        switch (item)
        {
            case Sheet sheet:
                sheets.Add(sheet);
                break;
            case Folder folder:
                folders.Add(folder);
                break;
            case Report report:
                reports.Add(report);
                break;
            case Sight sight:
                sights.Add(sight);
                break;
            case Template template:
                templates.Add(template);
                break;
        }

    }

    lastKey = page.LastKey;
} while (!string.IsNullOrEmpty(lastKey));
```

## Before you begin

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


## Migration steps

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

If you don't want the workspace metadata, skip the first step.

### Step 1: Get the workspace metadata

Call the **get workspace metadata** operation to get details on the workspace itself.

Python

```python
response = smart.Workspaces.get_workspace_metadata(workspace_id)
assert isinstance(response, smartsheet.models.workspace.Workspace)

workspace = response.name, response.id, response.permalink, response.access_level, response.created_at, response.modified_at
```

JavaScript

```javascript
const workspace = await client.workspaces.getWorkspaceMetadata({ workspaceId });
```

Java

```java
Workspace workspaceMetadata = client.workspaceResources().getWorkspaceMetadata(workspaceId, null);
```

C#

```csharp
Workspace workspace = client.WorkspaceResources.GetWorkspaceMetadata(workspaceId);
```

You can check that the response is a Workspace instance.

The workspace object has these attributes:

- ID
- Name
- Access level
- Permalink
- Creation timestamp (New)
- Modified timestamp (New)


### Step 2: Paginate over the workspace children

Here's the flow logic for paging through the children.

Python

```python
import com.smartsheet.api.models.TokenPaginatedResult; # Include this import

last_key = None
while True:
    response = smart.Workspaces.get_workspace_children(
        workspace_id, last_key=last_key
    )
    assert isinstance(
        response,
        smartsheet.models.paginated_children_result.PaginatedChildrenResult
    )

    # Removed response processing (covered next) for illustration purposes

    last_key = getattr(response, "last_key", None)
    if not last_key:
        break
```

JavaScript

```javascript
let lastKey = '';
do {
    const page = await client.workspaces.getWorkspaceChildren({
        workspaceId,
        queryParameters: { lastKey },
    });

    // Removed response processing (covered next) for illustration purposes

    lastKey = page?.lastKey;
} while (lastKey);
```

Java

```java
String lastKey = null;
do {
    TokenPaginatedResult<Object> response = client.workspaceResources()
            .getWorkspaceChildren(workspaceId, null, null, lastKey, null);

    // Removed response processing (covered next) for illustration purposes

    lastKey = response.getLastKey();
} while (lastKey != null && !lastKey.isBlank());
```

C#

```csharp
string? lastKey = null;
do
{
    TokenPaginatedResult<object> page = client.WorkspaceResources.GetWorkspaceChildren(
        workspaceId,
        childrenResourceTypes: null,
        include: null,
        numericDates: null,
        accessApiLevel: null,
        lastKey: lastKey,
        maxItems: null);

    // Removed response processing (covered next) for illustration purposes

    lastKey = page.LastKey;
} while (!string.IsNullOrEmpty(lastKey));
```

To fetch the first page of children, set the **last key** token to `None`, `null`, or an empty string (`""`), depending on your language's conventions.

In your call to **get workspace children**, you have these optional request parameters (see the operation documentation for exact parameter names):

- **children resource types**: Default is unspecified, which returns all types. To filter on ONLY particular types, specify those types (for example, "sheets", "reports", "sights", "templates", and/or "folders") in this parameter.
- **max items**: The maximum number of items to return in a response (page).


You can assert the response's type.

Lastly, in preparation for the next page of results, set your **last key** to the last key value from the response.

When there are no more children, last key is absent from the response.

If you expect only one page of child items (the **max items** per page default is `100`), you can call **get workspace children** once and forego any looping. Note, the response's **last key** is present (non-null) if more items exist.

To learn more about token-based pagination refer to [Token-based pagination](/api/smartsheet/guides/basics/pagination#token-based-pagination).

### Step 3: Get child items from the response

The **get workspace children** operation response includes a page of child items in a *generic* data list. You should check each list item's type.

The old **get workspace** operation response was a workspace object that had resource-specific list fields, such as `workspace.sheets[]` and `workspace.reports[]`, but the **get workspace children** operation response includes the page's child items in a *generic* data list.

The **get workspace children** operation response doesn't include a count of *total* child items or *total* pages. If you're interested in such counts, calculate them as you paginate.

Iterate over the generic data list, check each child item type, and do what you want with each item.

Python

```python
for child in response.data:
    if type(child) is Folder:
        folders.append(child)
    elif type(child) is Sheet:
        sheets.append(child)
    elif type(child) is Report:
        reports.append(child)
    elif type(child) is Sight:
        sights.append(child)
    elif type(child) is Template:
        templates.append(child)
```

JavaScript

```javascript
const children = page?.data ?? [];
for (const child of children) {
    switch (child?.resourceType) {
    case 'sheet':
        sheets.push(child);
        break;
    case 'report':
        reports.push(child);
        break;
    case 'sight':
        sights.push(child);
        break;
    case 'folder':
        folders.push(child);
        break;
    case 'template':
        templates.push(child);
        break;
    default:
        break;
    }
}
```

Java

```java
for (Object child : response.getData()) {
    if (child instanceof Folder folder) {
        folders.add(folder);
    } else if (child instanceof Report report) {
        reports.add(report);
    } else if (child instanceof Sheet sheet) {
        sheets.add(sheet);
    } else if (child instanceof Sight sight) {
        sights.add(sight);
    } else if (child instanceof Template template) {
        templates.add(template);
    }
}
```

C#

```csharp
foreach (var item in page.Data)
{
    // Check each child item's type
    switch (item)
    {
        case Sheet sheet:
            sheets.Add(sheet);
            break;
        case Folder folder:
            folders.Add(folder);
            break;
        case Report report:
            reports.Add(report);
            break;
        case Sight sight:
            sights.Add(sight);
            break;
        case Template template:
            templates.Add(template);
            break;
    }

}
```

For example, as shown above, you could add the child items to type-based collections.

Each child item has the following properties:

- ID
- Name
- Permalink
- Access level (New)
- Creation timestamp (New)
- Modified timestamp (New)


## Common pitfalls

**A child item's type is unexpected**

**Check the type** of each child item before using it.

**Some types are excluded from the child items**

If you set the **children resource types** parameter to a subset of types, the **get workspace children** operation only returns those types.

Best practice: Leave **children resource types** unspecified to get all types by default.

**The operation only returns one of multiple pages**

It's easy to forget that you need to pass in the **last key** from the response to get the next page (if one exists).

## Test your migration

Test your migrated code thoroughly.

Deploy your code to production before the deprecated operation sunsets.

Congratulations on migrating to the new **get workspace metadata** and **get workspace children** operations!

## Related topics

[Migrate from GET /workspaces/{id} for workspace hierarchies](/api/smartsheet/guides/updating-code/migrate-from-get-workspaces-loadall)

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

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