# Get OTP

> The affiliate (partner) calls Get OTP for the shop owner's phone, GHN sends an SMS OTP to that phone, and the affiliate then submits that OTP to create a shop for — or add itself as staff to — the owner's shop. This endpoint is step 1: it triggers the OTP SMS.

## Endpoint

| Environment | URL |
| --- | --- |
| Production | `https://online-gateway.ghn.vn/shiip/public-api/v2/shop/affiliateOTP` |
| Staging | `https://dev-online-gateway.ghn.vn/shiip/public-api/v2/shop/affiliateOTP` |

**Method**: `POST`

## Headers

| Header | Required | Description |
| --- | --- | --- |
| `Content-Type` | Yes | `application/json` |
| `Token` | Yes | Your (the partner's) token, issued by GHN. Your account must be active — [get a token](https://developer.ghn.vn/en/docs/token/get-token.md) |
| `ShopId` | No | Selects your shop context; when omitted, your account's default shop is used. The resolved shop must be active and belong to you, otherwise the request is rejected |

## Parameters

- **phone** (String): Phone of the shop owner (your customer) who will receive the OTP SMS. Must already belong to a registered GHN account, and must not be your own account
- **language** (String): Language of `code_message_value` in error responses. Default `vi`.<br>`vi`: Vietnamese<br>`en`: English

## Request Example

```bash
curl -X POST https://dev-online-gateway.ghn.vn/shiip/public-api/v2/shop/affiliateOTP \
  -H "Token: 5c1d8a9e-2f4b-11ed-..." \
  -H "ShopId: 92837" \
  -H "Content-Type: application/json" \
  -d '{
    "phone": "0987654321"
  }'
```

## Response

### Success (HTTP 200)

The OTP SMS is sent to the phone number stored on the owner's GHN account (which normally matches the number you submit).

```json
{
  "code": 200,
  "message": "Success",
  "data": {
    "TTL": 600
  }
}
```

### Response Fields

| Field | Type | Description |
| --- | --- | --- |
| `code` | Int | HTTP code (`200` on success) |
| `message` | String | Result message (`Success`) |
| `data.TTL` | Int | OTP time-to-live, in seconds. Submit the OTP to the next step before it expires |

### Error — missing phone (HTTP 400)

_Captured from a real Staging-environment call._

```json
{
  "code": 400,
  "message": "Key: 'myRequest.Phone' Error:Field validation for 'Phone' failed on the 'required' tag",
  "data": null,
  "code_message": "USER_ERR_COMMON",
  "code_message_value": "Sai thông tin đầu vào. Vui lòng thử lại."
}
```

## Error Codes

| Condition | HTTP | code_message |
| --- | --- | --- |
| Missing `phone` or invalid input | 400 | `USER_ERR_COMMON` |
| Phone is your own account (`Không thể tự liên kết tài khoản của chính mình`) | 400 | `USER_ERR_COMMON` |
| Phone not registered as a GHN account (`SDT chưa được đăng ký tài khoản GHN`) | 400 | `USER_ERR_COMMON` |
| Internal error (e.g. OTP SMS dispatch failed) | 500 | `SERVER_ERROR_COMMON` |
