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

[@salesforce/b2c-tooling-sdk](../../modules.md) / [instance](../index.md) / B2CInstance

# Class: B2CInstance

Defined in: [packages/b2c-tooling-sdk/src/instance/index.ts:141](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b099fb909260c5c00c90ca9da612a7f50c1328d4/packages/b2c-tooling-sdk/src/instance/index.ts#L141)

Represents a connection to a B2C Commerce instance.

Provides lazy-loaded, typed API clients for WebDAV and OCAPI operations.
Authentication is handled automatically based on the configured credentials.

## Example

```ts
// From configuration (recommended)
import { resolveConfig } from '@salesforce/b2c-tooling-sdk/config';

const config = await resolveConfig({
  clientId: process.env.SFCC_CLIENT_ID,
  clientSecret: process.env.SFCC_CLIENT_SECRET,
});
const instance = config.createB2CInstance();

// WebDAV uses Basic auth if available, falls back to OAuth
await instance.webdav.mkcol('Cartridges/v1');

// OCAPI always uses OAuth
const { data } = await instance.ocapi.GET('/sites', {});
```

## Constructors

### Constructor

> **new B2CInstance**(`config`, `auth`, `options`): `B2CInstance`

Defined in: [packages/b2c-tooling-sdk/src/instance/index.ts:154](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b099fb909260c5c00c90ca9da612a7f50c1328d4/packages/b2c-tooling-sdk/src/instance/index.ts#L154)

Creates a new B2CInstance.

#### Parameters

##### config

[`InstanceConfig`](../interfaces/InstanceConfig.md)

Instance configuration (hostname, code version)

##### auth

[`AuthConfig`](../../auth/interfaces/AuthConfig.md)

Authentication configuration

##### options

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

Optional runtime dependencies, including a pre-resolved OAuth strategy

#### Returns

`B2CInstance`

## Properties

### auth

> `readonly` **auth**: [`AuthConfig`](../../auth/interfaces/AuthConfig.md)

Defined in: [packages/b2c-tooling-sdk/src/instance/index.ts:156](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b099fb909260c5c00c90ca9da612a7f50c1328d4/packages/b2c-tooling-sdk/src/instance/index.ts#L156)

Authentication configuration

***

### config

> `readonly` **config**: [`InstanceConfig`](../interfaces/InstanceConfig.md)

Defined in: [packages/b2c-tooling-sdk/src/instance/index.ts:155](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b099fb909260c5c00c90ca9da612a7f50c1328d4/packages/b2c-tooling-sdk/src/instance/index.ts#L155)

Instance configuration (hostname, code version)

## Accessors

### apiBackend

#### Get Signature

> **get** **apiBackend**(): `"ocapi"` \| `"scapi"` \| `"auto"`

Defined in: [packages/b2c-tooling-sdk/src/instance/index.ts:172](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b099fb909260c5c00c90ca9da612a7f50c1328d4/packages/b2c-tooling-sdk/src/instance/index.ts#L172)

Backend preference for operations that support both OCAPI and SCAPI.
Defaults to `'auto'` when not configured.

##### Returns

`"ocapi"` \| `"scapi"` \| `"auto"`

***

### hasOAuthCredentials

#### Get Signature

> **get** **hasOAuthCredentials**(): `boolean`

Defined in: [packages/b2c-tooling-sdk/src/instance/index.ts:220](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b099fb909260c5c00c90ca9da612a7f50c1328d4/packages/b2c-tooling-sdk/src/instance/index.ts#L220)

Whether an API client is available for OCAPI and SCAPI calls (configured
OAuth credentials or a caller-provided OAuth strategy). Without one, only
WebDAV can be used, with Basic auth or a browser login.

##### Returns

`boolean`

***

### ocapi

#### Get Signature

> **get** **ocapi**(): [`OcapiClient`](../../clients/type-aliases/OcapiClient.md)

Defined in: [packages/b2c-tooling-sdk/src/instance/index.ts:277](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b099fb909260c5c00c90ca9da612a7f50c1328d4/packages/b2c-tooling-sdk/src/instance/index.ts#L277)

OCAPI Data API client.

Returns the openapi-fetch client directly with full type safety.
Always uses OAuth authentication.

##### Example

```ts
const { data, error } = await instance.ocapi.GET('/sites', {});
const { data, error } = await instance.ocapi.PATCH('/code_versions/{code_version_id}', {
  params: { path: { code_version_id: 'v1' } },
  body: { active: true }
});
```

##### Returns

[`OcapiClient`](../../clients/type-aliases/OcapiClient.md)

The OCAPI Data API client (openapi-fetch Client with full type safety).

***

### scapiClientConfig

#### Get Signature

> **get** **scapiClientConfig**(): [`ScapiClientConfig`](../interfaces/ScapiClientConfig.md) \| `undefined`

Defined in: [packages/b2c-tooling-sdk/src/instance/index.ts:201](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b099fb909260c5c00c90ca9da612a7f50c1328d4/packages/b2c-tooling-sdk/src/instance/index.ts#L201)

SCAPI connection coordinates + a scope-flexible auth strategy, or
`undefined` when this instance cannot reach SCAPI under `auto` mode.

This is the forward-looking seam for the OCAPI → SCAPI transition: a SCAPI
client factory (jobs, sites, scripts, …) needs only a B2CInstance,
not a separately-threaded shortCode/tenantId/auth bundle. When OCAPI is
eventually removed, the OCAPI accessors disappear and this stays.

Returns `undefined` unless **all** of the following hold:
  1. `shortCode` and `tenantId` are configured, and
  2. the configured OAuth flow is stateless and scope-flexible —
     client-credentials (clientId + clientSecret) or JWT Bearer
     (clientId + cert/key).

Browser user-auth flows (Authorization Code + PKCE and deprecated
implicit) are excluded on purpose because SCAPI Admin APIs currently only
support system authentication. Fixed-token stored sessions are also
excluded because they cannot request the `sfcc.*` scopes SCAPI needs.
This is not an `auto`-only restriction —
because both consumers (the dual-backend factory and the system-job runner)
gate on this getter, even explicit `--api-backend scapi` cannot use SCAPI
with implicit/stateful auth; it fails with a clear error naming the flow
requirement. SCAPI requires client-credentials or JWT Bearer.

##### Returns

[`ScapiClientConfig`](../interfaces/ScapiClientConfig.md) \| `undefined`

***

### webdav

#### Get Signature

> **get** **webdav**(): [`WebDavClient`](../../clients/classes/WebDavClient.md)

Defined in: [packages/b2c-tooling-sdk/src/instance/index.ts:247](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b099fb909260c5c00c90ca9da612a7f50c1328d4/packages/b2c-tooling-sdk/src/instance/index.ts#L247)

WebDAV client for file operations.

Uses Basic auth if username/password are configured,
otherwise falls back to OAuth.

##### Example

```ts
await instance.webdav.mkcol('Cartridges/v1');
await instance.webdav.put('Cartridges/v1/app.zip', content);
const entries = await instance.webdav.propfind('Cartridges');
```

##### Returns

[`WebDavClient`](../../clients/classes/WebDavClient.md)

The lazy-initialized WebDAV client for file operations.

***

### webdavHostname

#### Get Signature

> **get** **webdavHostname**(): `string`

Defined in: [packages/b2c-tooling-sdk/src/instance/index.ts:164](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b099fb909260c5c00c90ca9da612a7f50c1328d4/packages/b2c-tooling-sdk/src/instance/index.ts#L164)

The hostname to use for WebDAV operations.
Falls back to main hostname if not specified.

##### Returns

`string`

***

### webdavUsesUserAuth

#### Get Signature

> **get** **webdavUsesUserAuth**(): `boolean`

Defined in: [packages/b2c-tooling-sdk/src/instance/index.ts:230](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/b099fb909260c5c00c90ca9da612a7f50c1328d4/packages/b2c-tooling-sdk/src/instance/index.ts#L230)

Whether the WebDAV client authenticates as an Account Manager user (browser
login) rather than with Basic auth or an API client token. User tokens are
authorized by the user's Business Manager permissions. `false` until the
[webdav](#webdav) client has been created.

##### Returns

`boolean`
