# 템플릿 수정

원문: https://commerce.bootpay.ai/api/alimtalk/template/update

> 자체 알림톡 템플릿을 수정하는 API. 수정 가능한 상태와 전체 필드 전송 규칙

검수에서 반려됐거나, 등록만 해 두고 아직 검수를 요청하지 않은 자체 템플릿을 수정합니다.

덮어쓰기이므로 요청에 없는 필드는 지워집니다. 바꿀 값만 보내는 부분 수정은 지원하지 않습니다. [템플릿 상세](https://commerce.bootpay.ai/api/alimtalk/template/list)로 현재 값을 읽어 고칠 곳만 바꾼 뒤, 전체를 그대로 다시 보냅니다.

이름만 바꾸려고 `name` 만 보내면 본문과 메시지 유형이 비어 `3017` 로 거부됩니다. `content` 와 `msg_type` 까지 보내도 빠진 버튼·이미지·강조 설정·태그는 지워집니다.

::: warning 이미지를 빼면 카카오에서도 삭제됩니다
이미 올라간 템플릿을 고치면 카카오에 그대로 수정 요청이 나갑니다. 이미지 필드를 빠뜨리면 부트페이 쪽뿐 아니라 카카오에 올려 둔 이미지까지 삭제로 반영됩니다.
:::

::: endpoint
method: PUT
url: https://message.bootapi.com/alimtalk/templates/{id}
auth: [Basic Auth](https://commerce.bootpay.ai/api/server/authentication)
:::

## 수정할 수 있는 상태

| 상태 | 수정 가능 |
|------|-----------|
| 아직 올리기 전 | 가능 |
| REG (등록) | 가능 |
| REJ (승인 반려) | 가능. 고친 뒤 다시 검수를 요청합니다 |
| KRR (등록 거절) | 가능 |
| REQ (검수 중) | **거부** — 결과를 기다립니다 |
| APR (승인) | **거부** — 승인된 문구는 바꿀 수 없습니다 |

승인된 템플릿의 문구를 바꿔야 한다면 새 템플릿을 만들어 검수를 다시 받습니다.

## 요청 파라미터

파라미터는 [템플릿 생성](https://commerce.bootpay.ai/api/alimtalk/template/create)과 같습니다. `ksp_id`와 `register`만 받지 않습니다.

`필수` 는 요청이 거부되는지의 기준입니다. 전체를 덮어쓰므로 `N` 인 필드도 빼면 그 값이 지워집니다. 유지하려면 현재 값을 그대로 실어 보냅니다.

::: parameters

| 파라미터 | 타입 | 필수 | 설명 |
|---------|------|------|------|
| id | String | Y | 템플릿 문서 id (경로 파라미터) |
| name | String | N | 템플릿 이름. 빼면 비워집니다 |
| content | String | Y | 본문 (최대 1000자). 빼면 `3017` |
| msg_type | String | Y | `BA`·`EX`·`AD`·`MI`. 생성과 달리 기본값이 없어서 빼면 `3017` |
| emphasize_type | String | N | `NONE`·`TEXT`·`IMAGE`·`ITEM_LIST` |
| emphasize_title | String | N | 강조 타이틀 (최대 50자) |
| emphasize_subtitle | String | N | 강조 보조문구 (최대 40자). 변수를 쓸 수 없습니다 (`3017`) |
| template_extra | String | N | 부가정보 문구 |
| template_header | String | N | 아이템리스트형 헤더 (최대 16자) |
| item_highlight | Object | N | 아이템 하이라이트 |
| template_item | Object | N | 아이템 리스트 |
| buttons | Array | N | 버튼 (최대 5개). 웹링크(`WL`)의 `linkMo`·`linkPc`는 `https://#{변수명}` 형식만 받습니다 — 자세한 규칙은 [템플릿 생성](https://commerce.bootpay.ai/api/alimtalk/template/create)의 버튼 항목을 참고합니다 |
| image_url | String | N | 카카오 사본 이미지 URL |
| storage_image_url | String | N | 원본 이미지 URL. **빈 값으로 보내면 이미지 삭제**로 처리됩니다 |
| security_flag | Boolean | N | 보안 템플릿 여부 |
| category | String | N | 분류 |
| tags | Array | N | 태그 |
| examples | Object | N | 변수 예문(표시용) |
| template_code | String | N | 템플릿 코드 변경. **아직 올리기 전일 때만 반영**되고, 이미 올라간 템플릿에서는 무시됩니다. 중복이면 `3019` 로 거절됩니다 |

:::

## 코드 예제

::: code-group

```bash [cURL]
curl -X PUT "https://message.bootapi.com/alimtalk/templates/68b0f2a1c3d4e5f6a7b8c9d0" \
  -H "Authorization: Basic {base64(client_key:secret_key)}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "예약 확정 안내",
    "content": "#{company_name}\n#{user_name}님, #{booking_date} 예약이 확정되었어요. 방문 10분 전까지 와 주세요.",
    "msg_type": "BA",
    "emphasize_type": "NONE",
    "buttons": [
      {
        "name": "예약 확인하기",
        "linkType": "WL",
        "linkMo": "https://#{mobile_link}"
      }
    ]
  }'
```

```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.alimtalkTemplate.update('68b0f2a1c3d4e5f6a7b8c9d0', {
    name: '예약 확정 안내',
    content: '#{company_name}\n#{user_name}님, #{booking_date} 예약이 확정되었어요. 방문 10분 전까지 와 주세요.',
    msg_type: 'BA',
    emphasize_type: 'NONE',
    buttons: [{ name: '예약 확인하기', linkType: 'WL', linkMo: 'https://#{mobile_link}' }]
})
console.log(response)
```

```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.alimtalk_template.update('68b0f2a1c3d4e5f6a7b8c9d0', {
    'name': '예약 확정 안내',
    'content': '#{company_name}\n#{user_name}님, #{booking_date} 예약이 확정되었어요. 방문 10분 전까지 와 주세요.',
    'msg_type': 'BA',
    'emphasize_type': 'NONE',
    'buttons': [{'name': '예약 확인하기', 'linkType': 'WL', 'linkMo': 'https://#{mobile_link}'}]
})
print(response)
```

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

$commerce = new BootpayCommerceApi("your-commerce-client-key", "your-commerce-secret-key");
$response = $commerce->alimtalkTemplate->update('68b0f2a1c3d4e5f6a7b8c9d0', [
    'name' => '예약 확정 안내',
    'content' => "#{company_name}\n#{user_name}님, #{booking_date} 예약이 확정되었어요. 방문 10분 전까지 와 주세요.",
    'msg_type' => 'BA',
    'emphasize_type' => 'NONE',
    'buttons' => [['name' => '예약 확인하기', 'linkType' => 'WL', 'linkMo' => 'https://#{mobile_link}']]
]);
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.request.alimtalk.AlimtalkTemplateUpdateParams;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

Map<String, Object> button = new HashMap<>();
button.put("name", "예약 확인하기");
button.put("linkType", "WL");
button.put("linkMo", "https://#{mobile_link}");

List<Map<String, Object>> buttons = new ArrayList<>();
buttons.add(button);

AlimtalkTemplateUpdateParams params = new AlimtalkTemplateUpdateParams();
params.name = "예약 확정 안내";
params.content = "#{company_name}\n#{user_name}님, #{booking_date} 예약이 확정되었어요. 방문 10분 전까지 와 주세요.";
params.msgType = "BA";
params.emphasizeType = "NONE";
params.buttons = buttons;

BootpayStoreResponse response = commerce.alimtalkTemplate.update("68b0f2a1c3d4e5f6a7b8c9d0", params);
System.out.println(response.getRawData());
```

```ruby [Ruby]
require 'bootpay'

commerce = BootpayStore::RestClient.new(client_key: 'your-commerce-client-key', secret_key: 'your-commerce-secret-key')
response = commerce.alimtalk_template_update(
  template_id: '68b0f2a1c3d4e5f6a7b8c9d0',
  name: '예약 확정 안내',
  content: "\#{company_name}\n\#{user_name}님, \#{booking_date} 예약이 확정되었어요. 방문 10분 전까지 와 주세요.",
  msg_type: 'BA',
  emphasize_type: 'NONE',
  buttons: [{ name: '예약 확인하기', linkType: 'WL', linkMo: 'https://#{mobile_link}' }]
)
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")
response, err := commerce.AlimtalkTemplate.Update("68b0f2a1c3d4e5f6a7b8c9d0", bootpay.AlimtalkTemplateUpdateParams{
    Name:          "예약 확정 안내",
    Content:       "#{company_name}\n#{user_name}님, #{booking_date} 예약이 확정되었어요. 방문 10분 전까지 와 주세요.",
    MsgType:       "BA",
    EmphasizeType: "NONE",
    Buttons: []bootpay.AlimtalkTemplateButton{
        {Name: "예약 확인하기", LinkType: "WL", LinkMo: "https://#{mobile_link}"},
    },
})
fmt.Println(response, err)
```

```csharp [.NET]
using Bootpay.Commerce;
using Bootpay.Commerce.Models;
using System.Collections.Generic;

var commerce = new BootpayCommerceApi("your-commerce-client-key", "your-commerce-secret-key");
var response = await commerce.AlimtalkTemplateUpdate("68b0f2a1c3d4e5f6a7b8c9d0", new AlimtalkTemplateUpdateParams {
    Name = "예약 확정 안내",
    Content = "#{company_name}\n#{user_name}님, #{booking_date} 예약이 확정되었어요. 방문 10분 전까지 와 주세요.",
    MsgType = "BA",
    EmphasizeType = "NONE",
    Buttons = new List<Dictionary<string, object>> {
        new Dictionary<string, object> {
            { "name", "예약 확인하기" },
            { "linkType", "WL" },
            { "linkMo", "https://#{mobile_link}" }
        }
    }
});
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

:::

## 응답

수정된 템플릿 전체를 돌려줍니다. 구조는 [템플릿 상세](https://commerce.bootpay.ai/api/alimtalk/template/list)와 같습니다.

## 에러 코드

::: error-codes

| 코드 | error_code | 메시지 | 대처 방법 |
|------|------------|--------|-----------|
| `-48` | `INVALID_PARAMETER` | 수정 불가 상태 | 검수 중(REQ)이거나 승인(APR)된 템플릿입니다 |
| `3015` | `TEMPLATE_NOT_FOUND` | 템플릿 없음 | id 또는 코드를 확인합니다 |
| `3017` | `TEMPLATE_VARIABLE_MISSING` | 규격 위반 | 글자 수·강조표기 조건·버튼 규격(웹링크는 `https://#{변수명}` 형식)을 확인합니다. `content`·`msg_type`을 빼도 이 코드가 옵니다 |
| `3018` | `SENDER_NOT_VERIFIED` | 발신 채널 확인 불가 | 등록된 템플릿을 고칠 때 채널 키를 찾지 못했습니다. 채널을 다시 연동합니다 |
| `3019` | `TEMPLATE_CODE_DUPLICATED` | 템플릿 코드 중복 | `template_code`를 다른 값으로 바꿉니다 |
| `3024` | `SENDER_NOT_LINKED` | 발신프로필 미연결 | 이 프로젝트의 채널인지 확인합니다 |
| `3027` | `TEMPLATE_NAME_DUPLICATED` | 템플릿 이름 중복 | 같은 채널 안에서 이름이 겹칩니다 |
| `3013` | `KAKAO_TEMPLATE_REQUEST_FAILED` | 수정 거부 (HTTP 500) | 이미 올라간 템플릿일 때만 발생합니다. `message`의 사유를 확인합니다 |

:::

## 함께 보기

- [검수 요청](https://commerce.bootpay.ai/api/alimtalk/template/register) — 수정한 템플릿의 심사를 다시 요청합니다
