# 상품 등록

원문: https://commerce.bootpay.ai/api/catalog/create

> 쇼핑몰에 상품을 등록합니다. 상품명과 판매가만 보내도 등록되고, 발급된 product_id 는 주문서 요청의 products[].product_id 에 넣습니다.

상품을 등록합니다.

v1 API 상세: [상품](https://commerce.bootpay.ai/api/reference/v1/products)

## API 엔드포인트

::: endpoint
method: POST
url: https://api.bootapi.com/v1/products
auth: [Basic Auth](https://commerce.bootpay.ai/api/server/authentication)
scope: user:product_create
:::

## 요청 파라미터

::: parameters

| 파라미터 | 타입 | 필수 | 설명 |
|---------|------|------|------|
| name | String | Y | 상품명 (서버가 빈 값을 검사하지 않으므로 반드시 보냅니다) |
| desc | String | N | 상품 요약 설명 |
| content | String | N | 상품 상세 설명 (HTML 지원) |
| images | File[] | N | 대표 이미지 파일. 파일을 올릴 때는 `multipart/form-data` 를 사용합니다 |
| category_id | String | N | 카테고리 ID |
| display_price | Integer | Y | 판매가 (표시가). 0보다 커야 합니다. 0원은 사용량 기반·수시결제 구독 상품만 허용됩니다 |
| tax_free_price | Integer | N | 비과세 가격 |
| use_stock | Boolean | N | 재고 관리 사용 여부 |
| stock | Integer | N | 재고 수량 |
| use_subscription | Boolean | N | 구독 상품 여부 |
| subscription_setting_id | String | N | 구독 설정 템플릿 ID |
| usage_api_url | String | N | 사용량 조회 URL. 종량제(사용량 기반) 구독 상품이면 필수이고, 비어 있으면 `SUBSCRIPTION_SETTIGN_NEED_USAGE_API_URL` 로 거절됩니다. 구독 설정이 아니라 상품에 저장됩니다 ([사용량 API](https://commerce.bootpay.ai/api/subscription/usage-api)) |
| use_discount | Boolean | N | 할인 사용 여부 |
| discount_price | Integer | N | 할인 금액 또는 할인율. 판매가에서 이 값만큼 뺍니다 (`discount_price_type` 참고) |
| discount_price_type | Integer | N | 할인 단위 — `1` 퍼센트 / `2` 정액. 생략하면 정액으로 계산합니다 |
| status_display | Boolean | N | 쇼핑몰 노출 여부 |
| status_sale | Boolean | N | 판매 상태 |
| ex_uid | String | N | 외부 시스템 고유 ID (`external_uid` 로도 받습니다) |
| save_by | Integer | N | 저장 방식 (`1` 시스템 임시저장 / `2` 사용자 임시저장 / `3` 발행). **구독·배송 설정 검증은 `3` 을 명시해야 동작**합니다. 생략하면 발행 상태로 저장되지만 이 검증을 건너뜁니다. `1`·`2` 로 저장한 상품은 목록·상세·주문에 나오지 않습니다 |

:::

::: tip 처음 보낼 값
처음에는 `name` 과 `display_price` 만 보내고, 필요할 때 아래 묶음을 더합니다. 연결(`category_id` · `ex_uid`), 재고(`use_stock` · `stock`), 할인(`use_discount` · `discount_price` · `discount_price_type`), 과세(`tax_free_price`), 구독(`use_subscription` · `subscription_setting_id` — 아래 경고대로 발행 상태의 구독 상품은 관리자에서 만듭니다), 노출 · 판매(`status_display` · `status_sale`). `ex_uid` 에 내 상품 DB 의 ID 를 넣어 두면 [상품 목록](https://commerce.bootpay.ai/api/catalog/list)에서 그 값으로 찾아올 수 있습니다(쇼핑몰에 노출 중인 상품만). 이 API 는 `metadata` 를 받지 않으므로 상품-판매자 매핑 같은 내 데이터는 `ex_uid` 로 내 DB 에 남깁니다. 상품 · 상태 개념은 [상품](https://commerce.bootpay.ai/docs/catalog)에 있습니다.
:::

::: warning 구독 상품은 save_by: 3 을 함께 보냅니다
`use_subscription: true` 로 구독 상품을 만들 때는 `save_by: 3` 을 함께 보내야 구독 설정·가격 검증이 실행됩니다. 생략하면 발행 상태로 저장되지만 검증을 건너뛰므로, 구독 상품을 등록할 때는 생략하면 안 됩니다.
:::

::: warning 발행 상태의 구독 상품은 관리자에서 만듭니다
이 API 는 구독 기간별 가격(`subscription_periods`)을 받지 않습니다. 옵션 없는 구독 상품을 `save_by: 3` 으로 발행하면 기간별 가격이 없어 `PRODUCT_PRICE_INVALID`(HTTP 409)로 거절됩니다.

구독 상품은 [관리자 > 상품 관리](https://admin.bootpay.co.kr/product)에서 만들고, 받은 `product_id` 를 체크아웃·구독에 사용합니다.
:::

## 코드 예제

::: code-group

```bash [cURL]
curl -X POST "https://api.bootapi.com/v1/products" \
  -H "Authorization: Basic {base64(client_key:secret_key)}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "드립백 커피 10개입",
    "desc": "매일 아침 한 잔",
    "display_price": 29900,
    "save_by": 3,
    "tax_type": 1,
    "ex_uid": "shop-coffee-10",
    "status_visible": true,
    "status_display": true,
    "status_sale": true
  }'
```

```javascript [Node.js]
import { BootpayCommerce } from '@bootpay/backend-js'

const commerce = new BootpayCommerce({
    client_key: 'your-commerce-client-key',
    secret_key: 'your-commerce-secret-key',
    mode: 'production'
})

const response = await commerce.product.create({
    name: '드립백 커피 10개입',
    desc: '매일 아침 한 잔',
    display_price: 29900,
    save_by: 3,
    tax_type: 1,
    ex_uid: 'shop-coffee-10',
    status_visible: true,
    status_display: true,
    status_sale: true
})
console.log('product_id:', response.product_id)
```

```python [Python]
from bootpay_backend import BootpayCommerce

commerce = BootpayCommerce(
    client_key='your-commerce-client-key',
    secret_key='your-commerce-secret-key',
    mode='production'
)

response = commerce.product.create({
    'name': '드립백 커피 10개입',
    'desc': '매일 아침 한 잔',
    'display_price': 29900,
    'save_by': 3,
    'tax_type': 1,
    'ex_uid': 'shop-coffee-10',
    'status_visible': True,
    'status_display': True,
    'status_sale': True
})
print('product_id:', response['product_id'])
```

```php [PHP]
use Bootpay\ServerPhp\BootpayCommerceApi;

$commerce = new BootpayCommerceApi("your-commerce-client-key", "your-commerce-secret-key");
$response = $commerce->product->create([
    'name' => '드립백 커피 10개입',
    'desc' => '매일 아침 한 잔',
    'display_price' => 29900,
    'save_by' => 3,
    'tax_type' => 1,
    'ex_uid' => 'shop-coffee-10',
    'status_visible' => true,
    'status_display' => true,
    'status_sale' => true
]);
print_r($response);
```

```java [Java]
import kr.co.bootpay.store.BootpayStore;
import kr.co.bootpay.store.model.request.TokenPayload;
import kr.co.bootpay.store.model.response.BootpayStoreResponse;
import kr.co.bootpay.store.model.pojo.SProduct;

TokenPayload tp = new TokenPayload("your-commerce-client-key", "your-commerce-secret-key");
BootpayStore commerce = new BootpayStore(tp).withToken();

SProduct product = new SProduct();
product.name = "드립백 커피 10개입";
// ⚠️ 상품 설명은 Java SDK 로 보낼 수 없습니다. SProduct.description 은 description 키로 전송되지만
//    커머스 API 는 desc 를 읽으므로 값이 버려집니다. 설명은 관리자 화면이나 REST 직접 호출로 입력합니다.
product.displayPrice = 29900.0;
product.taxType = 1;              // int 필드라 비우면 0 으로 나갑니다 — 1 과세 · 2 복합과세 · 3 면세 · 4 영세
product.externalUid = "shop-coffee-10";   // external_uid 로 나갑니다 (ex_uid 와 같은 값)
product.statusDisplay = true;
product.statusSale = true;

BootpayStoreResponse response = commerce.product.create(product);
System.out.println(response);
```

```ruby [Ruby]
require 'bootpay'

commerce = BootpayStore::RestClient.new(client_key: 'your-commerce-client-key', secret_key: 'your-commerce-secret-key')
response = commerce.product_create(
  name: '드립백 커피 10개입',
  desc: '매일 아침 한 잔',
  display_price: 29900,
  save_by: 3,
  tax_type: 1,
  ex_uid: 'shop-coffee-10',
  status_visible: true,
  status_display: true,
  status_sale: true
)
puts response.data
```

```go [Go]
import "github.com/bootpay/backend-go/v2"

commerce := bootpay.NewCommerceAPI("your-commerce-client-key", "your-commerce-secret-key", nil, "production")
// Go SDK 의 CommerceProduct 구조체에는 desc · save_by · status_visible 칸이 없어 범용 Post 로 보냅니다
response, err := commerce.Post("products", map[string]interface{}{
    "name":           "드립백 커피 10개입",
    "desc":           "매일 아침 한 잔",
    "display_price":  29900,
    "save_by":        3,
    "tax_type":       1,
    "ex_uid":         "shop-coffee-10",
    "status_visible": true,
    "status_display": true,
    "status_sale":    true,
})
fmt.Println(response, err)
```

```csharp [.NET]
using Bootpay.Commerce;
using System.Net.Http;
var commerce = new BootpayCommerceApi("your-commerce-client-key", "your-commerce-secret-key");
// .NET SDK 의 CommerceProduct 에는 desc · save_by · status_* 속성이 없어 SendAsync 로 보냅니다
var response = await commerce.SendAsync("products", HttpMethod.Post, new {
    name = "드립백 커피 10개입",
    desc = "매일 아침 한 잔",
    display_price = 29900,
    save_by = 3,
    tax_type = 1,
    ex_uid = "shop-coffee-10",
    status_visible = true,
    status_display = true,
    status_sale = true
});
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

:::

## 응답

#### 성공 응답

```json
{
  "product_id": "67c95e64d01640bb9859c629",
  "save_by": 3
}
```

::: warning 알려진 문제 — 등록은 되지만 응답이 500 입니다
현재 상품이 저장된 뒤에 `SERVER_ERROR`(HTTP 500)가 반환됩니다. 같은 요청을 다시 보내면 상품이 중복 생성될 수 있습니다.

등록할 때 `ex_uid` 를 함께 보내고, 500 을 받으면 재시도하기 전에 [상품 목록](https://commerce.bootpay.ai/api/catalog/list)에서 `ex_uid` 로 저장 여부와 `product_id` 를 확인합니다. `ex_uid` 가 중복 생성을 막아 주지는 않습니다.
:::

#### 에러 응답

```
HTTP/1.1 409 Conflict
Content-Type: application/json
```

```json
{
  "error_code": "PRODUCT_PRICE_INVALID",
  "message": "상품가격은 0원 이상이어야 합니다."
}
```

## 에러 코드

::: info 공통 에러
인증·권한 에러는 [에러 코드표](https://commerce.bootpay.ai/api/reference/codes#커머스-api-인증-에러)를 참고합니다.
:::

::: error-codes

| 코드 | 메시지 | 대처 방법 |
|------|--------|-----------|
| `PRODUCT_PRICE_INVALID` | 상품가격은 0원 이상이어야 합니다. (HTTP 409) | `display_price` 를 0보다 큰 값으로 보냅니다. 0원은 사용량 기반·수시결제 구독 상품만 허용됩니다 |

:::

::: warning 알려진 문제 — 판매가가 0 이거나 없으면 500 입니다
현재 일반 상품의 `display_price` 가 0 이거나 없으면 `PRODUCT_PRICE_INVALID` 대신 `SERVER_ERROR`(HTTP 500)가 반환됩니다. `display_price` 는 항상 0보다 큰 값으로 보냅니다.
:::

::: tip
`product_id` 는 주문서 요청의 `products[].product_id` 에 사용합니다.
:::
