---
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:135](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/2feab01f654eec77c6d702777ec2818472f131f1/packages/b2c-tooling-sdk/src/instance/index.ts#L135)

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:147](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/2feab01f654eec77c6d702777ec2818472f131f1/packages/b2c-tooling-sdk/src/instance/index.ts#L147)

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:149](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/2feab01f654eec77c6d702777ec2818472f131f1/packages/b2c-tooling-sdk/src/instance/index.ts#L149)

Authentication configuration

***

### config

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

Defined in: [packages/b2c-tooling-sdk/src/instance/index.ts:148](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/2feab01f654eec77c6d702777ec2818472f131f1/packages/b2c-tooling-sdk/src/instance/index.ts#L148)

Instance configuration (hostname, code version)

## Accessors

### apiBackend

#### Get Signature

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

Defined in: [packages/b2c-tooling-sdk/src/instance/index.ts:165](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/2feab01f654eec77c6d702777ec2818472f131f1/packages/b2c-tooling-sdk/src/instance/index.ts#L165)

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

##### Returns

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

***

### ocapi

#### Get Signature

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

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

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:194](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/2feab01f654eec77c6d702777ec2818472f131f1/packages/b2c-tooling-sdk/src/instance/index.ts#L194)

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:221](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/2feab01f654eec77c6d702777ec2818472f131f1/packages/b2c-tooling-sdk/src/instance/index.ts#L221)

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:157](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/2feab01f654eec77c6d702777ec2818472f131f1/packages/b2c-tooling-sdk/src/instance/index.ts#L157)

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

##### Returns

`string`
