Category API
CREMA 서버에 등록된 카테고리 정보를 확인하고, 등록/수정하는 방법을 제공합니다.
List categories
카테고리 목록을 가져옵니다.
GET /v1/categories HTTP/1.1
Parameters
| 이름 | 타입 | 필수 | 설명 | 
| limit | integer | ✖ | 한 페이지의 카테고리 목록 길이. 범위: 1 ~ 100. 기본: 30 | 
Response
HTTP/1.1 200 OK
Link: <https://api.cre.ma/v1/categories?page=372>; rel="last", <https://api.cre.ma/v1/categories&page=2>; rel="next"
[
  {
    "id": 1,
    "code": "101",
    "name": "신상품 10% 할인",
    "depth": 1,
    "parent_category_id": null,
    "status": "visible",
    "created_at": "2013-09-23T10:12:29.000+09:00",
    "updated_at": "2014-03-17T08:07:41.000+09:00"
  },
  {
    "id": 2,
    "code": "12",
    "name": "아우터",
    "depth": 1,
    "parent_category_id": null,
    "status": "hidden",
    "created_at": "2013-09-23T10:12:28.000+09:00",
    "updated_at": "2014-04-21T17:34:07.000+09:00"
  },
  {
    "id": 3,
    "code": "35",
    "name": "니트/가디건",
    "depth": 2,
    "parent_category_id": 1,
    "status": "visible",
    "created_at": "2013-10-05T10:12:29.000+09:00",
    "updated_at": "2014-03-20T21:03:25.000+09:00"
  }
]
Get a single category
카테고리 한 개의 상세 정보를 가져옵니다.
with id
GET /v1/categories/:id HTTP/1.1
| 이름 | 타입 | 필수 | 설명 | 
| id | integer | ✔ | 카테고리의 id | 
with code
GET /v1/categories HTTP/1.1
| 이름 | 타입 | 필수 | 설명 | 
| code | string | ✔ | 카테고리의 code | 
Response
{
  "id": 1,
  "code": "12",
  "name": "블라우스",
  "depth": 1,
  "parent_category_id": null,
  "status": "visible",
  "created_at": "2014-05-17T08:39:52.000+09:00",
  "updated_at": "2014-05-17T08:39:52.000+09:00"
}
Create or Update a category
새로운 카테고리를 생성하거나 기존 데이터를 수정합니다.
POST /v1/categories HTTP/1.1
access_token=$ACCESS_TOKEN&code=0104&name=아우터
Parameters
| 이름 | 타입 | 필수 | 설명 | 
| code | string | ✔ | 카테고리의 code. 다른 카테고리와 중복되면 안됩니다. | 
| name | string | ✔ | 이름 | 
| parent_category_id | string | ✖ | 상위 카테고리의 id | 
| parent_category_code | string | ✖ | 상위 카테고리의 code | 
| status | string | ✖ | 진열 여부, 진열인 경우 visible, 미진열인 경우hidden | 
Response
HTTP/1.1 201 Created
Location: https://api.cre.ma/v1/categories
{
  "id": 1,
  "code": "12",
  "name": "니트/가디건",
  "depth": 1,
  "parent_category_id": null,
  "status": "visible",
  "created_at": "2014-05-17T08:39:52.000+09:00",
  "updated_at": "2014-05-17T08:39:52.000+09:00"
}
Update a category
카테고리의 내용을 수정합니다.
with id
PATCH /v1/categories/:id HTTP/1.1
access_token=$ACCESS_TOKEN&name=바지
| 이름 | 타입 | 필수 | 설명 | 
| id | integer | ✔ | 카테고리의 id | 
| code | string | ✖ | 카테고리의 code. 다른 카테고리와 중복되면 안됩니다. | 
| name | string | ✖ | 이름 | 
| parent_category_id | string | ✖ | 상위 카테고리 id | 
| status | string | ✖ | 진열 여부, 진열인 경우 visible, 미진열인 경우hidden | 
with code
PATCH /v1/categories HTTP/1.1
access_token=$ACCESS_TOKEN&name=바지
| 이름 | 타입 | 필수 | 설명 | 
| code | string | ✔ | 카테고리의 code | 
| name | string | ✖ | 이름 | 
| parent_category_id | string | ✖ | 상위 카테고리 id | 
| status | string | ✖ | 진열 여부, 진열인 경우 visible, 미진열인 경우hidden | 
Response
HTTP/1.1 204 No Content
Location: https://api.cre.ma/v1/categories/:id
Delete a single category
카테고리 한 개를 삭제합니다.
with id
DELETE /v1/categories/:id HTTP/1.1
| 이름 | 타입 | 필수 | 설명 | 
| id | integer | ✔ | 카테고리의 id | 
with code
DELETE /v1/categories HTTP/1.1
| 이름 | 타입 | 필수 | 설명 | 
| code | string | ✔ | 카테고리의 code | 
Response
  Example (Ruby)
require 'curl'
require 'json'
# access_token 값 얻기
c = Curl::Easy.new('https://api.cre.ma/oauth/token')
c.http_post(
  Curl::PostField.content('grant_type', 'client_credentials'),
  Curl::PostField.content('client_id', ENV['CREMA_APP_ID']),
  Curl::PostField.content('client_secret', ENV['CREMA_SECRET'])
)
access_token = JSON.parse(c.body_str)['access_token']
# 카테고리1 추가
category1 = {code: '0104', name: '아우터'}
c = Curl::Easy.new('https://api.cre.ma/v1/categories')
c.http_post(
  Curl::PostField.content('access_token', access_token),
  Curl::PostField.content('code', category1[:code]),
  Curl::PostField.content('name', category1[:name])
)
# 쇼핑몰 DB 카테고리 테이블에 컬럼을 하나 추가하시어 해당 카테고리에 이 값을 저장해주세요.
category1_id = JSON.parse(c.body_str)['id']
# 카테고리1 이름 변경
Curl.put("https://api.cre.ma/v1/categories/#{category1_id}?access_token=#{access_token}&name=Outer")
# 카페고리1의 하위 카테고리2 추가
category2 = {code: '010404', name: '자켓/코트', parent_category_id: category1_id}
c = Curl::Easy.new('https://api.cre.ma/v1/categories')
c.http_post(
  Curl::PostField.content('access_token', access_token),
  Curl::PostField.content('code', category2[:code]),
  Curl::PostField.content('name', category2[:name]),
  Curl::PostField.content('parent_category_id', category1_id)
)
category2_id = JSON.parse(c.body_str)['id']
# 카테고리2 삭제
Curl.delete("https://api.cre.ma/v1/categories/#{category2_id}?access_token=#{access_token}")
  직접 사용해 보세요!
  
    API Explorer를 사용하여 API 요청 및 응답을 확인해 보세요.