---
name: "getCustomConfig"
mode: "kit"
versionRequirements:
  - { name: "Base library", version: "2.0.0" }
  - { name: "@ray-js/ray", version: "1.7.29" }
async: true
---

## getCustomConfig

> [VERSION] Base library >= 2.0.0 | @ray-js/ray >= 1.7.29

> ⚡ **Supports Promise** — Returns a Promise when success / fail / complete callbacks are omitted.

### Description

Retrieve custom Mini Program configuration. This API fetches custom business configuration defined in the Developer Console, supporting multiple data types (URL, boolean, number, string). Custom configuration supports hierarchical management with template-level and instance-level settings; instance settings take precedence over template settings. Changes are automatically synced to the cloud, and the Mini Program can use this API to obtain the latest configuration.

### Parameters


#### Overload 1: `getCustomConfig(options: Object)` → `void`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `success` | `(config: Record<string, CustomConfigValue>) => void` | No | Callback invoked when the API call succeeds; the argument is a key-value map of configuration items. |
| `fail` | `(params: Object) => void` ↓see below | No | Failure callback |
| `complete` | `(res: Record<string, CustomConfigValue> \| GetCustomConfigError) => void` | No | Completion callback (executed on both success and failure) |

##### fail callback parameters

| Property | Type | Description |
| --- | --- | --- |
| `errorMsg` | `string` | Error message |
| `errorCode` | `string` | Error code |

#### Overload 2: `getCustomConfig()` → `Promise<Record<string, string \| number \| boolean \| string>>`

None


### Error Codes

| Error Code | Error Message |
| --- | --- |
| `7` | API internal processing failed |

### Referenced Types

##### `type` CustomConfigValue

Value types for custom configuration items; supports string, number, and boolean

```typescript
export type CustomConfigValue =
  /** 字符串 */
  | string
  /** 数字 */
  | number
  /** 布尔值 */
  | boolean
  /** 链接(特殊字符串) */
  | string;
```

##### `interface` GetCustomConfigError

| Property | Type | Description |
| --- | --- | --- |
| `errorMsg` | `string` | Error message |
| `errorCode` | `string` | Error code |


### Examples

#### Callback mode

```tsx
import { View, Button, Text, getCustomConfig } from '@ray-js/ray'

export default function Demo() {
  const handleGetConfig = () => {
    getCustomConfig({
      success(config) {
        console.log('Custom config:', config);
      },
      fail(err) {
        console.error('Failed to get:', err.errorMsg);
      },
    });
  };

  return (
    <View style={{ padding: 20 }}>
      <Button onClick={handleGetConfig}>Get custom config (callback)</Button>
    </View>
  );
}
```

#### Promise mode

```tsx
import { View, Button, Text, getCustomConfig } from '@ray-js/ray'

export default function Demo() {
  const [config, setConfig] = useState('');

  const handleGetConfig = async () => {
    try {
      const result = await getCustomConfig();
      setConfig(JSON.stringify(result));
      console.log('Custom config:', result);
    } catch (err) {
      console.error('Failed to get:', err);
    }
  };

  return (
    <View style={{ padding: 20 }}>
      <Button onClick={handleGetConfig}>Get custom config (Promise)</Button>
      {config && <Text style={{ marginTop: 10 }}>{config}</Text>}
    </View>
  );
}
```
