Skip to main content

Configuring the APIs required to build an e-commerce site

This tutorial explains step by step how to build an e-commerce site with Kuroco. Building the site involves three main tasks:

  1. Configuring e-commerce settings from the admin panel
  2. Configuring the APIs required to build an e-commerce site (this page)
  3. Creating the front-end

This tutorial explains how to configure the APIs required to build an e-commerce site.

Prerequisites​

This tutorial assumes that purchases are made after logging in. Therefore, this page describes the API settings for login and profile retrieval in addition to the e-commerce API settings. Implementing login is not covered in this tutorial. For details, see Building a login page.

Endpoint list​

The endpoints created in this tutorial are as follows.

ItemEndpoint pathSample Vue file
Loginlogin-
Get orderer informationprofileproduct_list.vue
purchase.vue
Get product listproduct-listproduct_list.vue
Add to cartadd-cartproduct_list.vue
Get cart contentscart-items/{ec_cart_id}product_list.vue
purchase.vue
Purchase productspurchasepurchase.vue
tip

The sample Vue files are the Vue files of the pages created later in Creating the front-end.

Creating the API​

First, create an API. In this tutorial, create an API named "EC". On the API screen, click [Create new API].

Image (fetched from Gyazo)

Enter the following and click [Add].

Image (fetched from Gyazo)

ItemValue
TitleEC
Version1
DescriptionAPI for e-commerce

Creating endpoints​

Next, create the endpoints. On the screen of the EC API you just created, click [Configure Endpoint].

Image (fetched from Gyazo) The endpoint creation screen appears.

Image (fetched from Gyazo) Create the following endpoints from this screen.

Login​

Performs the login process.

Image (fetched from Gyazo)

ItemValue
Pathlogin
CategoryAuthentication
ModelLogin
Operationlogin_challenge

Sample request​

{
"email": "test@example.co.jp",
"password": "test_password",
"login_save": 0
}
KeyDescription
emailEmail address of the member logging in
passwordPassword of the member logging in
login_saveWhether to keep the login state (specify 1 to keep it)

Sample response​

{
"grant_token": "(omitted)",
"status": 0,
"member_id": 123,
"info": {
"validUntil": 1633945168
},
"messages": [],
"errors": []
}

Get orderer information​

Gets the cart ID and member information after login.

Image (fetched from Gyazo)

ItemValue
Pathprofile
CategoryAuthentication
ModelLogin
Operationprofile
Parameters: basic_infoname1
name2
zip_code
tdfk_cd
address1
address2
address3
tel
email

Sample response​

{
"name1": "Test",
"name2": "Taro",
"zip_code": "1234567",
"tdfk_cd": "03",
"address1": "Address (city)",
"address2": "Street address",
"address3": "Building name",
"tel": "09022223333",
"email": "test@example.co.jp",
"member_id": 123,
"group_ids": {
"102": "Login User"
},
"shash": "(omitted)",
"expiresAt": 1633945233,
"ec_cart_id": 1000,
"ec_point": 1,
"ec_temp_point": 150
}

Get product list​

This API retrieves product content data and product item data. It also supports searching with the filter function.

Image (fetched from Gyazo)

ItemValue
Pathproduct-list
CategoryEC
ModelECProduct
Operationlist
Parameters: topics_group_id(Specify the group ID of the target content structure)
tip

You can check the group ID of a content structure in Content structure in the Kuroco admin panel.

Sample response​

  "list": [
{
"product_id": 41205,
"ymd": "1970-01-01",
"subject": "PHP Development\t- Paperback",
"link_url": "",
"open_flg": 1,
"inst_ymdhi": "2020-06-19 17:42:18.033674+09",
"update_ymdhi": "2020-11-04 20:48:26.468659+09",
"product_group_id": 11,
"ext_col_01": "",
"topics_id": 7,
"combination_id": 235,
"stock": 3978,
"stock_unlimited": 0,
"sale_limit": 0,
"sale_unlimited": 1,
"price_01": "0",
"price_02": "2500",
"set_product_ids": "",
"release_ymdhi": null,
"delivery_type": 255,
...omitted...
"product_data": {
"topics_id": 7,
"season": 2016,
"ymd": 0,
"contents_type": 6,
"contents": "<img class=\"img-responsive\" src=\"/files/user/201512070955_1.jpg\"><br/>\r\n<br/>\r\nThe layout changes when the screen size is reduced.",
"subject": "PHP Development",
"topics_flg": 1,
"open_flg": 1,
"regular_flg": 0,
"inst_ymdhi": "2016-06-09T12:28:31+09:00",
"update_ymdhi": "2020-06-19T17:09:39+09:00",
"topics_group_id": 5,
"ext_col_01": "",
...omitted...
},
"combination_name": "Paperback",
"class_options": {
"16": {
"ec_class_id": 16,
"ec_class_option_id": 44,
"label_nm": "Paperback"
}
},
"order_list": []

Add to cart​

Adds a product to the cart with the specified cart ID.

Image (fetched from Gyazo)

ItemValue
Pathadd-cart
CategoryEC
ModelECCart
Operationadd

Sample request​

{
"ec_cart_id": 1000,
"item": {
"product_id": 41205,
"quantity": 1
}
}
KeyDescription
ec_cart_idCart ID
item.product_idProduct item ID
item.quantityQuantity

Sample response​

{
"messages": [
"新規追加しました。"
],
"errors": []
}

Get cart contents​

Gets the current contents of the cart.

Image (fetched from Gyazo)

ItemValue
Pathcart-items/{ec_cart_id}
CategoryEC
ModelECCart
Operationdetails

Sample response​

{
"messages": [],
"errors": [],
"details": {
"ec_cart_id": 1000,
"items": [
{
"product_id": 41205,
"quantity": 1
}
],
"subtotal": 2500,
"deliv_fee": 200,
"total": 2700,
"total_quantity": 1
},
"payment_list": {
"59": {
"payment_type": "Bank transfer",
"payment_method": 4,
"use_link_type": false,
"use_token": false
}
}
}
tip

payment_list contains the payment methods that can be used in common by all product items in the cart.

Purchase products​

This API purchases the products in the cart. Sample requests and notes for each payment method are described below.

Image (fetched from Gyazo)

ItemValue
Pathpurchase
CategoryEC
ModelECOrder
Operationpurchase

Sample request​

{
"ec_cart_id": 0,
"order_products": {},
"product_id": 0,
"quantity": 0,
"ec_payment_id": 1,
"discount": {
"point": 0,
"serial_code": "string"
},
"shipping_address": {
"name1": "",
"name2": "",
"zip_code": "000",
"tdfk_cd": "",
"address1": "",
"address2": "",
"address3": "",
"tel": ""
},
"sp_career_info": {
"sp_career": 1,
"open_id": "string",
"return_url": "string",
"cancel_url": "string",
"other_url": "string",
"outline": "string"
},
"orderer": {
"name1": "string",
"name2": "string",
"zip_code": "000",
"tdfk_cd": "01",
"address1": "string",
"address2": "string",
"address3": "string",
"tel": "string",
"email": "email@example.com"
},
"card_token": "string",
"order_note": "string",
"validate_only": false
}
KeyDescription
ec_cart_idCart ID
If logged in, you can get it from the profile API.
If not logged in, specify 0.
order_productsUsed to specify the products to purchase directly in the API request without using the cart (*)
product_idUsed to specify the products to purchase directly in the API request without using the cart (*)
quantityUsed to specify the products to purchase directly in the API request without using the cart (*)
ec_payment_idSpecify the payment method ID.
Typically, you get the "sales method" linked to the product and specify the ID of the payment method selected from it.
shipping_addressShipping address
If logged in and not specified, the logged-in user's information is used.
ordererOrderer information
If logged in and not specified, the logged-in user's information is used.
order_noteOrder note
validate_onlySet to true if you only want to validate the input without actually processing the payment and purchase.

This completes the API creation.

tip

For details on the endpoint settings, see Endpoint settings.

Next, create the front-end. See Creating the front-end.


Support

If you have any other questions, please contact us or check out Our Slack Community.