Front API SDK guide

  • In order to conveniently use the API of cafe24, we provide SDK that includes a front API call function.
  • SDK makes it more convenient and allows you to create an app while preventing the cause of a problem.
  • SDK only works when an app is installed in a shopping mall. Any script can not be used.

SDK usage format

1. CAFE24API.init(appKey)

  • Initialize the CAFE24API SDK. You must call up the SDK before using it
Usage type

CAFE24API.init(String appKey);

- Parameters : appKey (App key of APP created by developer center (=Client id))


A correct example

CAFE24API.init('AMj8UZhBC9zsyTlFGI6PzC');

2. CAFE24API.MALL_ID

  • Returns the shopping mall ID from which the API is invoked.
Usage type

CAFE24API.MALL_ID;


A correct example

CAFE24API.MALL_ID;

Usage type

CAFE24API.MALL_ID;


A correct example

CAFE24API.MALL_ID;

3. CAFE24API.SHOP_NO

  • Returns the shopping mall number from which the API is invoked.
Usage type

CAFE24API.SHOP_NO;


A correct example

CAFE24API.SHOP_NO;

4. CAFE24API.getMemberID(callback)

  • Returns the member ID of current connected member.
Usage type

CAFE24API.getMemberID(Function callback);


- 파라미터 : callback (callback funtion to recall member ID)
A correct example

CAFE24API.getMemberID(function(memberID){
console.log(memberID);
});

5. CAFE24API.get(url, callback)

  • Returns the queried results of the called API.
Usage type

CAFE24API.get(String url, Function callback);

- Parameters : url (request URL)

- Parameters : callback (Callback function to recall after processing)


A correct example

CAFE24API.get('/api/v2/products/10', function(err, res){
if (err) {
// An Error object when an error occurs.
// name, message properties can be checked.
// You can view detailed error messages through the res object.

} else {
// You can view the response message through the res object.
}
});


Result Example

// This is a message of success.
{
"product": {
"shop_no": 1,
"product_no": 10,
.......
}
}

// This is a message of failure.
{
"error": {
"code": 404,
"message": "The ID of the corresponding Entity is invalid."
}
}

4. CAFE24API.post(url, params, callback)

  • Returns the registered result of the called API.
Usage Type

CAFE24API.post(String url, Object params, Function callback);

- Parameters : url (request URL)

- Parameters : params (Pass in the data to be processed to the key/value. Check API documentation since the parameters available for each endpoint are different)

- Parameters : callback (Callback function to recall after processing)


A correct example

var params = {
"request": {
"duplicated_item_check": "T",
"product_no": 950,
"basket_type": "A0000",
"shipping_type": "A",
"prefaid_shipping_fee": "P",
"variants": [
{
"quantity": 1,
"variants_code": "P0000BJU000H"
}
]
}

}
CAFE24API.post( '/api/v2/cart', params, function(err, res){
if (err) {
// An Error object when an error occurs.
// name, message properties can be checked.
// Detailed error message can be viewed through res object.

} else {
// You can view the response message through the res object.
}
});


Result Example

// This is a message of success.
{
"cart": [

"product_no": 950,
"basket_type": "A0000",
......
}
]
}

// This is a message of failure.
{
"error": {
"code": 422,
"message": "Failed to carry shopping basket.",
"more_info": {
.......
}
}
}

How to Use SDK

- How to Use (Example)

// Set app key for app to use.
CAFE24API.init( 'AMj8UZhBC9zsyTlFGI6PzC');

// Mall ID
CAFE24API.MALL_ID;

// GET
CAFE24API.get( '/api/v2/products/10', function(err, res){
console.log(res);
});

// POST
var data = {
"request": {
"client_id": "AMj8UZhBC9zsyTlFGI6PzC",
"src": "https://js-aplenty.com/bar.js",
"display_location": "product_detail"
}
};
CAFE24API.post( '/api/v2/scripttags', data, function(err, res){
console.log(res);
});

- Response Results (Success)

- Response result (failure)