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

[@salesforce/b2c-tooling-sdk](../../modules.md) / [clients](../index.md) / createFallbackBackend

# Function: createFallbackBackend()

> **createFallbackBackend**\<`T`\>(`scapi`, `ocapi`, `domainName`): `T`

Defined in: [packages/b2c-tooling-sdk/src/clients/scapi-fallback-backend.ts:107](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/2feab01f654eec77c6d702777ec2818472f131f1/packages/b2c-tooling-sdk/src/clients/scapi-fallback-backend.ts#L107)

Creates a fallback wrapper over `scapi` and `ocapi` backends.

The returned object presents the same interface as `T`. Method calls are
intercepted: the first call tries SCAPI; on a safe fallback trigger it falls back
to OCAPI. The choice is cached for the wrapper's lifetime.

**Contract:**
- Both `scapi` and `ocapi` must implement `T`. TypeScript enforces this
  at the call site since both are typed as `T`.
- Only methods of `T` are routed through the fallback logic. The `name`
  getter is special-cased to reflect the resolved backend.
- **Non-method properties** are returned from the SCAPI target only and
  are not switched on fallback. By convention, backends should be method
  bags — any state beyond `name` should be encapsulated, not exposed.
- **Concurrency:** if two calls race before resolution, both may attempt
  SCAPI. This is benign for read operations (idempotent retries) and
  acceptable for writes (both either succeed or fail with the same
  error). Each Proxy instance has its own state, so this concerns only
  shared use of a single wrapper.

## Type Parameters

### T

`T` *extends* [`BackendBase`](../interfaces/BackendBase.md)

## Parameters

### scapi

`T`

Primary (SCAPI) backend implementation

### ocapi

`T`

Fallback (OCAPI) backend implementation

### domainName

`string`

Used in fallback log messages, e.g. `'jobs'`

## Returns

`T`

A Proxy over `scapi` whose methods route through fallback logic

## Example

```ts
const backend = createFallbackBackend<JobsBackend>(scapiJobs, ocapiJobs, 'jobs');
await backend.executeJob('my-job'); // tries SCAPI, may fall back to OCAPI
```
