# Create Sub Account (Corporate)

Create Sub Account (Corporate) through this project environment’s SafeHaven account. Uses snake_case fields and NGN minor units. Requires accounts:write.

## Endpoint

POST https://api.veyqo.org/api/v1/safehaven/subaccounts/corporate

Server secret key required. Scope: accounts:write. The key determines the project and environment; no project-selection header is accepted.

> For each new operation, generate and persist one OPERATION_IDEMPOTENCY_KEY. Retry the unchanged request with that same key. Do not generate a new key on every retry.

## Example request

Examples use illustrative IDs and provider URLs. Replace path variables with IDs returned by your own requests. Never paste a live secret into client code or a public tool.

### cURL

```bash
curl --request POST "https://api.veyqo.org/api/v1/safehaven/subaccounts/corporate" \
  --header "Authorization: Bearer $VEYQO_SECRET_KEY" \
  --header "Accept: application/json" \
  --header "Idempotency-Key: $OPERATION_IDEMPOTENCY_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "phone_number": "+2348000000000",
  "email_address": "customer@example.com",
  "external_reference": "order-1001",
  "identity_type": "vID",
  "identity_id": "000000000000000000000001",
  "company_registration_number": "example"
}'
```

### Node.js

```javascript
// Server-side Node.js 18+. Save operation.idempotencyKey before a write.
const response = await fetch(`https://api.veyqo.org/api/v1/safehaven/subaccounts/corporate`, {
  method: 'POST',
  headers: {
  "Authorization": `Bearer ${process.env.VEYQO_SECRET_KEY}`,
  "Accept": "application/json",
  "Idempotency-Key": operation.idempotencyKey,
  "Content-Type": "application/json"
},
  body: JSON.stringify({
  "phone_number": "+2348000000000",
  "email_address": "customer@example.com",
  "external_reference": "order-1001",
  "identity_type": "vID",
  "identity_id": "000000000000000000000001",
  "company_registration_number": "example"
}),
});
const result = await response.json();
if (!response.ok || !result.success) {
  console.error(response.status, result.error?.code, response.headers.get('X-Request-Id'));
  throw new Error(result.error?.message ?? 'Veyqo request failed');
}
console.log(result.data);
```

### PHP

```php
<?php
// Server-side PHP with the cURL extension. Persist $operationIdempotencyKey.
$curl = curl_init('https://api.veyqo.org/api/v1/safehaven/subaccounts/corporate');
curl_setopt_array($curl, [
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer '.getenv('VEYQO_SECRET_KEY'),
    'Accept: application/json',
    'Idempotency-Key: '.$operationIdempotencyKey,
    'Content-Type: application/json'
  ],
  CURLOPT_POSTFIELDS => <<<'JSON'
{
  "phone_number": "+2348000000000",
  "email_address": "customer@example.com",
  "external_reference": "order-1001",
  "identity_type": "vID",
  "identity_id": "000000000000000000000001",
  "company_registration_number": "example"
}
JSON,
]);
$body = curl_exec($curl);
if ($body === false) throw new RuntimeException(curl_error($curl));
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
curl_close($curl);
$result = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
if ($status >= 400 || !($result['success'] ?? false)) {
  throw new RuntimeException($result['error']['code'] ?? 'Veyqo request failed');
}
print_r($result['data']);
```

### Python

```python
# pip install requests; run on your server.
import os, requests
from urllib.parse import quote

response = requests.request('POST', f'https://api.veyqo.org/api/v1/safehaven/subaccounts/corporate',
    headers={
  "Authorization": 'Bearer ' + os.environ['VEYQO_SECRET_KEY'],
  "Accept": "application/json",
  "Idempotency-Key": operation_idempotency_key,
  "Content-Type": "application/json"
},
    json={
  "phone_number": "+2348000000000",
  "email_address": "customer@example.com",
  "external_reference": "order-1001",
  "identity_type": "vID",
  "identity_id": "000000000000000000000001",
  "company_registration_number": "example"
},
    timeout=30)
result = response.json()
if not response.ok or not result.get('success'):
    raise RuntimeError(f"{response.status_code} {result.get('error')} request_id={response.headers.get('X-Request-Id')}")
print(result['data'])
```

## Request body

| Field | Type | Presence | Description |
| --- | --- | --- | --- |
| phone_number | string | Required | This is the phone number of the account holder. It should begin with the country code. |
| email_address | string | Required | This is the email address. |
| external_reference | string | Required | This is an external reference to be attached to the account object. |
| identity_type | string | Required | Identification method the account holder, should be vID (Provided you have Validated the KYC of at least one director of the company). Values: vID. |
| identity_id | string | Required | The `_id` from the Safe Haven Verification Endpoint. |
| company_registration_number | string | Required | The should be the company's RC or BN Number. |
| auto_sweep | boolean | Optional | This should be set when creating a virtual account. It determines if auto sweep should be enabled or disabled. |
| auto_sweep_details | object | Optional | This contains the auto sweep details to be filled if creating a virtual account. |
| auto_sweep_details.schedule | string | Required | This is the schedule for the autosweep Values: Instant. |
| auto_sweep_details.account_number | string | Required | This represents the account to auto sweep to. |

## Successful response · 200

HTTP success means the request was accepted. A pending payment or refund is not completed merely because the response is 200 or 201.

```json
{
  "success": true,
  "data": {
    "_id": "000000000000000000000001",
    "client": "example",
    "account_product": "example",
    "account_number": "0000000000",
    "account_name": "example",
    "account_type": "example",
    "currency_code": "example",
    "bvn": "example",
    "identity_id": "000000000000000000000001",
    "account_balance": 0,
    "book_balance": 0,
    "callback_url": "https://example.com",
    "is_sub_account": false,
    "sub_account_details": {
      "_id": "000000000000000000000001",
      "first_name": "example",
      "last_name": "example",
      "email_address": "customer@example.com",
      "bvn": "example"
    },
    "external_reference": "order-1001",
    "created_at": "example",
    "updated_at": "example",
    "nin": "example",
    "__v": 0,
    "cba_account_id": "000000000000000000000001",
    "operation_id": "pso_01M6EB66SC61Q3RQYAN0693DGM"
  }
}
```

## Response fields

| Field in data | Type | Presence | Description |
| --- | --- | --- | --- |
| _id | string | Optional | See the JSON example. |
| client | string | Optional | See the JSON example. |
| account_product | string | Optional | See the JSON example. |
| account_number | string | Optional | See the JSON example. |
| account_name | string | Optional | See the JSON example. |
| account_type | string | Optional | See the JSON example. |
| currency_code | string | Optional | See the JSON example. |
| bvn | string | Optional | See the JSON example. |
| identity_id | string | Optional | See the JSON example. |
| account_balance | integer | Optional | Amount in NGN minor units (kobo). |
| book_balance | integer | Optional | Amount in NGN minor units (kobo). |
| callback_url | string | Optional | See the JSON example. |
| is_sub_account | boolean | Optional | See the JSON example. |
| sub_account_details | object | Optional | See the JSON example. |
| sub_account_details._id | string | Optional | See the JSON example. |
| sub_account_details.first_name | string | Optional | See the JSON example. |
| sub_account_details.last_name | string | Optional | See the JSON example. |
| sub_account_details.email_address | string | Optional | See the JSON example. |
| sub_account_details.bvn | string | Optional | See the JSON example. |
| external_reference | string | Optional | See the JSON example. |
| created_at | string | Optional | See the JSON example. |
| updated_at | string | Optional | See the JSON example. |
| nin | string | Optional | See the JSON example. |
| __v | integer | Optional | See the JSON example. |
| cba_account_id | string | Optional | See the JSON example. |
| operation_id | string | Optional | Veyqo pso_ operation ID. Save it to reconcile retries and match provider_service.updated events. |
| merchant_reference | string | Optional | Your external_reference or payment_reference, if supplied. SafeHaven receives a globally unique Veyqo reference for supported writes. |

## Errors and recovery

| Code | HTTP | Recovery | Retry policy |
| --- | --- | --- | --- |
| VALIDATION_FAILED | 422 | Read error.details when present, correct the named fields and retry only after correction. Validation messages may describe state/capability errors without field details. | No automatic retry. |
| INVALID_API_KEY | 401 | Use a current kc_test_ or kc_live_ secret key on /api/v1. Use a pk_test_ or pk_live_ publishable key only on browser checkout. | After fixing credentials. |
| INSUFFICIENT_PERMISSION | 403 | Grant the required scope or use a suitably scoped key. Dashboard organization roles and staff permissions are separate. | After permission changes. |
| RESOURCE_NOT_FOUND | 404 | Check the ID, project and environment. Do not guess another project’s IDs. An inactive payment link is also not-found. | No blind retry. |
| PROVIDER_NOT_CONNECTED | 422 | Connect a provider, choose the project default, or explicitly pass provider. An account shared with another project still needs its own assignment here. | After configuration changes. |
| PROVIDER_AUTHENTICATION_FAILED | 502 | The merchant must check/rotate the provider credentials in the dashboard. Do not expose those secrets to your application users. | After credential correction; reconcile existing payment first. |
| PROVIDER_REQUEST_FAILED | 422 | Read the safe message, inspect the payment’s failure details and correct the request or provider account. Never repeatedly retry a business rejection. | Only after resolving the cause. |
| PROVIDER_UNAVAILABLE | 503 | Check the existing payment and verify its state before starting another attempt. Retry safe reads with backoff; preserve operation identity for retried writes. | Conditional: reconcile unknown outcomes first. |
| RATE_LIMIT_EXCEEDED | 429 | Honor Retry-After, use bounded exponential backoff with jitter, and reduce concurrent requests. Read X-RateLimit headers. | Yes, after Retry-After; preserve write idempotency. |
| IDEMPOTENCY_KEY_REUSED | 409 | Reuse the exact original request to recover that operation, or use a new key only for a genuinely different operation. | Do not retry a changed body with that key. |
| IDEMPOTENCY_IN_PROGRESS | 409 | Wait briefly, retry with the same key and unchanged request, then reconcile by reference if the result remains uncertain. | Back off with jitter; preserve key/body. |

- [Complete error catalogue](https://veyqo.org/docs/errors): Every Veyqo error code, including which surface emits it and how to recover.
