---
title: POST /v1/referral/code
---

# `POST /v1/referral/code`

Create my referral code

Create the account's referral code once the eligibility gates are met.

Money, price, rate and count fields cross the wire as decimal strings; units are shown beside each field ([Wire encoding](/api/wire-encoding)). Group: [Referral](/api/reference/referral/).

**Auth:** API key (`x-api-key`)

**Scope:** `trade`

**Rate limit:** the `order` budget ([Rate limits](/api/rate-limits))

**Effect:** `write`: changes orders or account state

**Idempotency key:** `any`: any fresh unique key, reused only to retry the same request

## Parameters

- <span id="param-idempotency-key"></span>`idempotency-key` (header) · string · required: Required on this mutating endpoint. A client-chosen unique key that makes the write safe to retry; reusing a key with a DIFFERENT body is refused (409 idempotency_key_reused), except on credential-minting and treasury approve/execute routes, which replay as before. What the value must be is the operation's `x-hardbasis-idempotency-key`: `order-id` = the client order id (it BECOMES the order/bracket/trigger id, 1..64 chars of [A-Za-z0-9._:-]); `quote-id` = the body's quoteId (any other value is refused, 400); `any` = any fresh unique key.

## Request

- <span id="req-code"></span>`code` · string · optional

```bash [curl]
curl -fsS -X POST "$HB/v1/referral/code" \
  -H "x-api-key: $HB_KEY" \
  -H "idempotency-key: $(uuidgen)" \
  -H "content-type: application/json" \
  -d '{
    "code": "SATSTACK"
  }'
```

```python [Python]
import os
import uuid

import requests

HB = os.environ.get("HB", "https://testnet.hardbasis.com")

resp = requests.post(
    f"{HB}/v1/referral/code",
    headers={
        "x-api-key": os.environ["HB_KEY"],
        "idempotency-key": str(uuid.uuid4()),
    },
    json={
        "code": "SATSTACK",
    },
)
resp.raise_for_status()
print(resp.json())
```

```ts [TypeScript]
const HB = process.env.HB ?? "https://testnet.hardbasis.com";

const res = await fetch(`${HB}/v1/referral/code`, {
  method: "POST",
  headers: {
    "x-api-key": process.env.HB_KEY!,
    "idempotency-key": crypto.randomUUID(),
    "content-type": "application/json",
  },
  body: JSON.stringify({
    "code": "SATSTACK"
  }),
});
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
console.log(await res.json());
```

## Responses

- **201**: Created
  - <span id="res-201-code"></span>`code` · string · required
  - <span id="res-201-createdTsMs"></span>`createdTsMs` · string · unit `ms` · required

Example `201` response:

```json
{
  "code": "string",
  "createdTsMs": "100000"
}
```

## Errors

Every refusal carries a stable `code` from [`ErrorCode`](/api/reference/all#errorcode) beside human `error` prose; match on the code. See [Errors](/api/errors).

- **401**: A refusal carrying a stable machine `code` (ErrorCode) beside human `error` prose.
- **403**: A refusal carrying a stable machine `code` (ErrorCode) beside human `error` prose.
- **429**: A token bucket is exhausted.
