# API 인증 토큰 발급받기

토스쇼핑의 모든 API에는 [Bearer](https://docs.tosspayments.com/resources/glossary/bearer-auth) 인증이 필요해요. 토스쇼핑에 입점한 이후 Access Token을 발급받고, 아래와 같이 API 인증헤더에 사용해주세요. Authorization 헤더에 `Bearer {발급된 Access Token}` 형식으로 추가하면 됩니다.

```bash
curl --request GET 'https://shopping-fep.toss.im/api/v3/shopping-fep/products/categories/children' \
--header 'Authorization: Bearer {발급된 access token}'
```

## Access Token 발급받기

&#x20;[토스쇼핑 파트너스](https://toss.im/shopping-seller)에서 확인한 Access Key, Secret Key로 Access Token을 발급받아주세요.&#x20;

{% stepper %}
{% step %}

### 토스쇼핑 파트너스 접속하기

토스쇼핑에 입점한 다음에 토스쇼핑 파트너스에 로그인해주세요.&#x20;

**상점 이름 > 가맹점·계정 관리 > 자체 개발**로 이동한 뒤 **‘키 발급'** 버튼을 클릭해주세요.&#x20;

<figure><img src="/files/roW0IvMHQREEUS78zGJd" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### IP 주소 입력하기

API를 호출할 IP 주소를 입력한 뒤 ‘발급’ 버튼을 눌러주세요. 등록된 IP 주소만 API에 접근할 수 있습니다.&#x20;

<figure><img src="/files/Th7mJj74GhCTToCpDdG7" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### 키 확인하기

자체 개발 메뉴에서 **Access Key**, **Secret Key**를 확인해주세요.&#x20;

<figure><img src="/files/xFLhmdWC1BYJ5u73F0xB" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Access Token 발급 API 호출하기

앞 단계에서 확인한 Access Key, Secret Key를 Access Token 발급에 사용해주세요. 아래 표와 같이 API body에 추가하면 됩니다.&#x20;

**POST** `https://oauth2.cert.toss.im/token`

* 테스트 환경이라면 `https://oauth2-alpha.cert.toss.im/token` 으로 요청해주세요

<table><thead><tr><th>필드명</th><th width="351.72265625">입력값</th></tr></thead><tbody><tr><td><code>grant_type</code></td><td><code>client_credentials</code></td></tr><tr><td><code>clientId</code></td><td>토스쇼핑 파트너스에서 확인한 Access Key</td></tr><tr><td><code>clientSecret</code></td><td>토스쇼핑 파트너스에서 확인한 Secret Key</td></tr><tr><td><code>scope</code></td><td><code>toss-shopping-fep:write</code><br><br></td></tr></tbody></table>

{% code overflow="wrap" fullWidth="false" %}

```bash
curl -X POST https://oauth2.cert.toss.im/token \
    -H "Content-Type: application/x-www-form-urlencoded" \
    -H "Accept: application/json; charset=UTF-8" \
    -d "grant_type=client_credentials&client_id={access key}&client_secret={secret key}&scope=toss-shopping-fep:write"
```

{% endcode %}
{% endstep %}

{% step %}

### Access Token 확인하기

Access Token 발급에 성공하면 아래 같은 JSON 응답이 반환돼요.&#x20;

* Access Token은  토스쇼핑 API Bearer 인증에 사용해요. 안전하게 저장해주세요.
* 보안을 위해 유효 기간이 있어요. 만료 전 새로 발급받는 걸 권장해요.
  * 만약 만료된 토큰으로 API를 호출하는 경우에는 **http status code 401**로 응답이 오도록 되어있어요.
* API를 호출할 때마다 Access Token을 발급하면 API 이용이 제한될 수 있어요. 과도한 Token 재발급 요청으로 발생할 수 있는 부하를 방지하기 위해서입니다.

{% code overflow="wrap" fullWidth="false" %}

```json
{
	"access_token": "{발급된 accesse token}",
	"scope": "toss-shopping-fep:write",
	"token_type": "Bearer",
	"expires_in": 31535999
}
```

{% endcode %}
{% endstep %}
{% endstepper %}

> ### API 연동 중 문의사항이나 개선 제안이 있으신가요?

{% hint style="info" %}
토스쇼핑 API 연동에 대한 질문이나, 건의사항이 있다면 [연동/개발 문의](https://discord.gg/xPz6H9NZ3P)에 남겨주세요. 다른 유저의 문의를 참고하거나, 토스쇼핑 담당자와 질의를 주고 받을 수 있어요.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://shopping-docs.toss.im/dev/api-1/token.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
