---
editLink: false
lastUpdated: false
---

[@salesforce/b2c-tooling-sdk](../../../modules.md) / [operations/content](../index.md) / fetchContentLibrary

# Function: fetchContentLibrary()

> **fetchContentLibrary**(`instance`, `libraryId`, `options`): `Promise`\<[`FetchContentLibraryResult`](../interfaces/FetchContentLibraryResult.md)\>

Defined in: [packages/b2c-tooling-sdk/src/operations/content/export.ts:47](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/e7c16f1ae423da0aa47b3e10be88f9770b53619b/packages/b2c-tooling-sdk/src/operations/content/export.ts#L47)

Fetch and parse a content library from an instance (or local file).

Returns the parsed Library and optionally the raw archive data.
No filesystem side effects.

## Parameters

### instance

[`B2CInstance`](../../../instance/classes/B2CInstance.md)

B2C instance to fetch from

### libraryId

`string`

Library ID (or site ID if isSiteLibrary is true)

### options

[`FetchContentLibraryOptions`](../interfaces/FetchContentLibraryOptions.md) = `{}`

Fetch options

## Returns

`Promise`\<[`FetchContentLibraryResult`](../interfaces/FetchContentLibraryResult.md)\>

Parsed library and optional archive data

## Example

```typescript
// Fetch from instance
const { library } = await fetchContentLibrary(instance, 'SharedLibrary');

// Filter and traverse
library.filter(n => n.id === 'homepage');
const xml = await library.toXMLString({ traverseHidden: false });

// Use local file instead
const { library } = await fetchContentLibrary(instance, 'SharedLibrary', {
  libraryFile: './library.xml'
});
```
