Unofficial Cafe24 API client implemented in javascript/typescript.
npm i cafe24api-client
There are 2 clients for each Admin API and Front API.
// Admin API
import { Cafe24AdminAPIClient } from 'cafe24api-client';
const client = new Cafe24AdminAPIClient({
mallId: '<your-mall-id>',
});
// Front API
import { Cafe24FrontAPIClient } from 'cafe24api-client';
const client = new Cafe24FrontAPIClient({
mallId: '<your-mall-id>',
clientId: '<your-cafe24-client-id>',
});
You can register needed endpoint sets to the client by importing each endpoint registerer.
Endpoint registerer is a function that takes a client instance and returns the client instance with registered endpoints.
It follows the path pattern like below, and only endpoints you've included will be bundled (if you're in bundling situation).
cafe24api-client/<admin|front>/endpoints/<endpoint-group-id>
Below is an example of registering endpoints.
Important
Note that cafe24api-client
uses axios
under the hood,
so the return value is an axios response object.
You can access the actual response data by data
property.
import { Cafe24AdminAPIClient } from 'cafe24api-client';
// This imports every endpoint methods
// documented at https://developers.cafe24.com/docs/api/admin/#products
import Products from 'cafe24api-client/admin/endpoints/products';
// This imports every endpoint methods
// documented at https://developers.cafe24.com/docs/api/admin/#customers-paymentinformation
import CustomersPaymentinformation from 'cafe24api-client/admin/endpoints/customers-paymentinformation';
Cafe24AdminAPIClient.use(Products);
Cafe24AdminAPIClient.use(CustomersPaymentinformation);
const client = new Cafe24AdminAPIClient({
mallId: '<your-mall-id>',
});
// Now you can use registered endpoints
// This calls https://developers.cafe24.com/docs/api/admin/#retrieve-a-list-of-products
const { data } = await client.products.retrieveAListOfProducts(
// First argument is a payload
//
// Pass request parameters documented at
// corresponding endpoint documentation
{ product_no: [838, 835], },
// Second argument is a configuration
{ fields: ['product_no', 'product_code', 'price'], }
);
Every endpoint methods by default uses camel cased keys for payload and response, as Cafe24 API uses snake cased keys.
If you want to use snake cased keys, you can import camel cased keys version of endpoint registerer which follows the path pattern like below.
cafe24api-client/<admin|front>/endpoints/camel-case/<endpoint-group-id>
Below is an example of registering endpoints with snake cased keys.
import { Cafe24AdminAPIClient } from 'cafe24api-client';
import Products from 'cafe24api-client/admin/endpoints/products';
import CustomersPaymentinformation from 'cafe24api-client/admin/endpoints/customers-paymentinformation';
Cafe24AdminAPIClient.use(Products);
Cafe24AdminAPIClient.use(CustomersPaymentinformation);
const client = new Cafe24AdminAPIClient({
mallId: '<your-mall-id>',
});
const { data } = await client.products.retrieveAListOfProducts(
{ productNo: [838, 835], },
{ fields: ['productNo', 'productCode', 'price'], }
);
Auth
endpoint group refers to:
- https://developers.cafe24.com/docs/api/admin/#authentication
- https://developers.cafe24.com/docs/api/admin/#get-access-token
- https://developers.cafe24.com/docs/api/admin/#get-access-token-using-refresh-token
This endpoint group is special as it is essential to use access tokens to call other endpoints when consuming Admin API.
Below is the example of registering and using Auth
endpoints.
import { Cafe24AdminAPIClient } from 'cafe24api-client';
import Auth from 'cafe24api-client/admin/endpoints/auth';
Cafe24AdminAPIClient.use(Auth);
const client = new Cafe24AdminAPIClient({
mallId: '<your-mall-id>',
});
const { data } = await client.getAccessToken({
client_id: '<your_client_id>',
client_secret: '<your_client_secret>',
code: '<your_code>',
redirect_uri: '<your_redirect_uri>',
});
const accessToken = data.access_token;
// By calling this, you can now use access token to call other endpoints
client.setAccessToken(accessToken);
- Typescript interfaces provided by this library (e.g.
interface <method>Input
,interface <method>Output
) are- not fully typed (for
interface <method>Input
andinterface <schema>
), - or fully documented with JSDoc (for
interface <method>Output
), - or fully scraped subproperties exceeding 2 levels deep (for
interface <schema>
andinterface <method>Input
).
- not fully typed (for
- This is because code generator cafe24api-schema-scraper constructs property info for schema, input, and output seperately, and logic to merge them is not implemented yet. If you're interested in contributing, please check out Contributing section below.
This repository also contains set of tools to help you develop a service with Cafe24 API.
Check out the list below for other available packages.
- cafe24-webhook-utils
- cafe24api-auth-code-getter
- cafe24api-schema-scraper (internal purpose)
- cafe24-webhook-schema-generator (internal purpose)
Any contribution is welcome! Check out CONTRIBUTING.md and CODE_OF_CONDUCT.md for more information on how to get started.
cafe24api-client
is licensed under a MIT License.