SUNMI Store system is a store management system provided by SUNMI for merchants based on the IoT devices in stores.
As an open platform, SUNMI Store can do data interchange for third-party SaaS providers, including the interchange of product information, transaction information and membership system.
Multiple SUNMI IOT device can help the user to digitize their shop. Based on the data from their shop such as face recognition and customer statistics along with the order info from saas provider, user could analyze their shops better.
This document describes how to exchange data with the third party saas provider to make sure SUNMI store open platform can get the order information from saas provider as soon as possible to do analysis.
2. API Specification
2.1 Protocol
All APIs use HTTPS Protocol with POST method
Note: The size of the request body should be no more than 1 MB. If this size is exceeded, open platform will deny it.
unique identifier provided by SUNMI store open platform
random
yes
string
6-10 digit random string with number and alphabets
timestamp
yes
int
10 digit current unix timestamp
sign
yes
string
see chapter 2.2
3 APIs
3.1 Order APIs
3.1.1 Parameters
The following parameters are all for SUNMI store open platform and is used to explain APIs. Saas providers must provide the parameter of their own to make sure the order can be synced to open platform.
The parameters in the order below are the basics properties of an order, there will be more properties in real orders.
Order
parameter
type
required
unique
description
order_no
string
●
●
the unique identifier of an order
order_type
int
●
type of an order(1- normal order、 2- canceled, 3-exchanged for new product, 4- suspend,5-报表)
order_time
int
●
order timestamp
order_start_time
int
the start time of an order
purchase_amount
double (2 digit precision)
●
discount_amount
double (2 digit precision)
●
received_amount
double (2 digit precision)
●
payment_type
int
●
1-cash、2-alipay、3-wechat pay、4-QQpay、5-JD wallet、6-credit card、7-unionpay QR code、8-other
customer_count
int
default 1
device_sn
string
●
software_name
string
software_spec
string
hardware_name
string
hardware_spec
string
cashier_no
string
cashier_disk
string
shop_assistant_no
string
order_source
int
1-offline、 2-online (default offline)
member_no
string
ali_id
string
wechat_open_id
string
member_points
double
coupon_no
string
coupon_source
int
1-shop,2-alipay, 3-wechat pay, 4-other
receipt_no
string
sunmi_receipt_no
string
product_list
array[product]
●
see the list below
product
parameter
type
description
required
name
string
name of the product
●
seq_num
string
sequence number of the product
bar_code
string
bar code of the product
spec
string
spec of the product
●
unit
string
unit of the product
quantity
double (3 digit precision)
sell quantity
●
stock_quantity
double (3 digit precision)
stock quantity
original_price
double (2 digit precision)
original price
●
present_price
double (2 digit precision)
current price
●
promote_amount
double (2 digit precision)
promotion price
●
subtotal_amount
double (2 digit precision)
subtotal of this product
●
product additional properties for specific product
parameter
type
description
required
color
string
code for color
size
string
code for size
3.1.2 Update order
API description: By requesting this API, the saas provider can notify the SUNMI store open platform that there is a new order in their system.
API address:/order/update(this is for reference, the detail of this API for each saas provider will be different and needed to be discussed)
Error types will be returned in HTTP response. If the sign is invalid, then the http status code 401 will be returned.
If the sign is valid, then it will return HTTP status code 200 whatsoever, the error will be returned in the HTTP response body. The structure of our response body is normally:
SUNMI Store system is a store management system provided by SUNMI for merchants based on the IoT devices in stores.
As an open platform, SUNMI Store can do data interchange for third-party SaaS providers, including the interchange of product information, transaction information and membership system.
ESL and other IoT devices are directly attached to the store’s products, prices and strategies, thus a basic product database framework is preserved in SUNMI Store. For data sources, users can choose either to edit on the page of SUNMI Store or to deal with the data on the third-party SaaS provider.
This document describes the error codes user might encounter and the description of that error.
2. Return value
Error types will be returned in HTTP response. If the sign is invalid, then the http status code 401 will be returned.
If the sign is valid, then it will return HTTP status code 200 whatsoever, the error will be returned in the HTTP response body. The structure of our response body is normally:
{
code:0
msg: "success"
data: {}
}
3. Error list
Error code
description
5090
invalid sign
5091
invalid timestamp
5092
invalid random value
5000
database error
5013
invalid saas provider or shop
5015
invalid product
5022
invalid parameter
5041
invalid saas provider
5047
invalid order
Notification Center
1. Background
The data flow between the SUNMI store open platform and the Saas provider could be bidirectional and real-time. The Saas provider can pass its data to the open platform and remote control SUNMI’s IOT device.
Meanwhile, SUNMI store open platform could push the data in its system to the saas provider through the data center on their need
2. API specification
2.1 protocol
All Open APIs are HTTPS request with POST method only.
API description: By requesting this API, the user can cancel the monitor on given events
API address:/hook/delete
Parameters:
parameter
required
type
description
shop_id
yes
string
the identifier of the shop in open platform
event_list
yes
array[int]
the list of events that need to be canceled
Return value:
{
code: 0,
msg: "succeed",
data: {
}
}
Parameter event:
event value
description
1010
IPC FM010 motion detecting message
1100
add a face to a group result message
2001
IPC real time face recognition message
4100
price change message (currently unavailable)
Electronic Shelf Label(ESL)
1. Background
SUNMI Store system is a store management system provided by SUNMI for merchants based on the IoT devices in stores.
As an open platform, SUNMI Store can do data interchange for third-party SaaS providers, including the interchange of product information, transaction information and membership system.
2. API Specifications
2.1 Protocol
All APIs use HTTPS Protocol with POST method.
Note: The size of the request body should be no more than 1 MB. If this size is exceeded, open platform will deny it.
API description:By calling this API, user can update the name of an AP.
API address:/device/ap/updateName
Parameters:
parameter
required
type
description
shop_id
yes
string
The identifier of the shop in open platform
ap_id
yes
string
The id of an AP
ap_name
yes
string
The new name of this AP
Return value:
{
code: 0,
msg: "succeed",
data: {
}
}
Errors:
Error code
Description
5000
database error
5300
invalid AP
5.3.6 Reboot the given AP
API description:By calling this API, user can reboot the given AP.
API address:/device/ap/reboot
Parameters:
parameter
required
type
description
shop_id
yes
string
The identifier of the shop in open platform
ap_id
yes
string
The ID of an AP
Return value:
{
code: 0,
msg: "succeed",
data: {
}
}
Errors:
Error code
Descriptions
5000
database error
5300
invalid AP
5.3.7 Set the scan time of a given AP
API description:By calling this API, user can set the scan time of a given AP.
API address:/device/ap/setScanTime (temporary unavailableq)
Parameters:
parameter
required
type
description
shop_id
yes
string
The identifier of the shop in open platform
ap_id
yes
string
The ID of an AP
scan_time
yes
int
The new scan time of the given AP
Return value:
{
code: 0,
msg: "succeed",
data: {
}
}
6. Device update APIs
6.1 Description
This set of APIs are used to manage and update the firmware of ESL and AP.
6.2 API List
API address
description
/device/ap/firmware/getList
get the firmware info of APs by model
/device/ap/firmware/upgrade
update the firmware of APs
/device/esl/firmware/getList
get the firmware info of ESLs by model
/device/esl/firmware/upgrade
udpate the firmware of ESLs
6.3 API detail
6.3.1 Get the firmware info of APs by model
API description:By calling this API, user can get the firmware info of APs by model. If multiple versions of firmware are running on differents APs with same model type, only the latest version of firmware will be returned
API address:/device/ap/firmware/getList
Parameters:
parameter
required
type
description
shop_id
yes
string
The identifier of the shop in open platform
page_num
no
int
Current page (default 1) (currently unavailable)
page_size
no
int
Current items per page (default 10) (currently unavailable)
API description:By calling this API, user can update the firmware of APs by model. This API is currently not available.
API address:/device/ap/firmware/upgrade (暂未开放)
Parameters:
parameter
required
type
description
shop_id
yes
string
The identifier of the shop in open platform
返回值:
{
code: 0,
msg: "succeed",
data: {
}
}
6.3.3 Get the firmware info of ESLs by model
API description:By calling this API, user can Get the firmware info of ESLs by model. If multiple versions of firmware are running on differents ESLs with same model type, only the latest version of firmware will be returned
API address:/device/esl/firmware/getList
Parameters:
parameter
required
type
description
shop_id
yes
string
The identifier of the shop in open platform
page_num
no
int
current page (default 1) (currently not available)
page_size
no
int
current items per page (default 10) (currently not available)
API description:By calling this API, user can delete a given template.
API address:/template/delete
Parameters:
parameter
required
type
description
shop_id
yes
string
The identifier of the shop in open platform
template_id_list
yes
array
The unique ID of a template
Return value:
{
code: 0,
msg: "succeed",
data: {
}
}
Errors:
Error code
Description
5000
database error
8. Product Management APIs
8.1 Description
This set of APIs is used to manage the price of the product and its relationship to the ESLs. After the relationship is set up, SUNMI store open platform will automatically update the changes of a product to the ESLs.
8.2 API list
API address
description
/product/bindEsl
bind a product to an ESL
/product/unbindEsl
unbind a product from an ESL
/product/getBindEslList
get the list of ESLs a product is bound to
/product/updateTemplate
update the template of a product
/product/getInfo
get the info of a product
/product/getList
get the list of all product
8.3 API detail
8.3.1 Bind a product to an ESL
API description:By calling this API, user can bind a product to an ESL
API address:/product/bindEsl
Parameters:
parameter
required
type
description
shop_id
yes
string
The identifier of the shop in open platform
product_id
yes
string
The unique ID of a product
esl_code
no (either esl_code or esl_sn must be provided)
string
8-digit ID of the ESL
esl_id
no (either esl_code or esl_sn must be provided)
string
The unique ID of a given ESL
template_id
yes
string
The unique ID of a template
Return value:
{
code: 0,
msg: "succeed",
data: {
}
}
Errors:
Error code
Description
5000
database error
5020
invalid parameters
5015
invalid products
5343
invalid template
5300
invalid AP
5301
invalid ESL
5338
ESL already bounded to another shop
5342
invalid ESL image
5006
oss error
8.3.2 Unbind a product from an ESL
API description:By calling this API, user can unbind a product from an ESL
API address:/product/unbindEsl
Parameters:
parameter
required
type
description
shop_id
yes
string
The identifier of the shop in open platform
esl_code
no (either esl_code or esl_sn must be provided)
string
8-digit ID of the ESL
esl_id
no (either esl_code or esl_sn must be provided)
string
The unique ID of a given ESL
}
{
code: 0,
msg: "succeed",
data: {
}
}
Errors:
Error code
Description
5000
database error
5020
invalid parameters
5301
invalid ESL
5320
ESL not bounded
5336
ESL bound to another shop
5342
invalid ESL image
5006
oss error
8.3.3 Get the list of ESLs
API description:By calling this API, user can unbind a product from an ESL
SUNMI Store system is a store management system provided by SUNMI for merchants based on the IoT devices in stores.
As an open platform, SUNMI Store can do data interchange for third-party SaaS providers, including the interchange of product information, transaction information and membership system.
ESL and other IoT devices are directly attached to the store’s products, prices and strategies, thus a basic product database framework is preserved in SUNMI Store. For data sources, users can choose either to edit on the page of SUNMI Store or to deal with the data on the third-party SaaS provider.
This document describes how to interchange the product information of the third-party SaaS provider, including how to synchronize the information (the merchant’s products and prices) between SaaS system and SUNMI Store in real-time after the initial interchange of product data.
2 API Specifications
2.1 Protocol
All APIs use HTTPS Protocol with POST method
Note: The size of the request body should be no more than 1 MB. If this size is exceeded, open platform will deny it.
unique identifier provided by SUNMI store open platform
random
yes
string
6-10 digit random string with number and alphabets
timestamp
yes
int
10 digit current unix timestamp
sign
yes
string
see chapter 2.2
3 APIs
3.1 Product mapping
3.1.1 Parameters
The following parameters are for open platform APIs. The saas providers will need to provide their product properties list to create a mapping between their system and open platform’s system
parameter
type
description
required
saas system parameters
id
string
the id in sunmi database
yes
seq_num
string
product sequence number
no
bar_code
string
product bar code
no
name
string
product name
yes
alias
string
product alias
no
price
double
current product price
yes
promote_price
double
product promotion price
no
member_price
double
membership price
no
spec
string
specs for the product
no
unit
string
unit for the product
no
level
string
level of the product
no
area
string
area of the product
no
brand
string
brand of the product
no
qr_code
string
qr code url for the product
no
expire_time
int
product expire time
no
3.1.2 Create New Product
API description:This API is used after a saas system had created a new product to inform the open platform system about the change.
This API is for creating new products only, if the product ID exists, then this ID will be added into the exist_list. If the required parameter is not passed, then the id will be put into invalid_list and returned.
API description : This API is used after a saas system had udpate a new product to inform the open platform system about the change.
The delete API will only delete the existing product in the open platform, if the open platform cannot match the product id, it will add this id to the not_exist_list and return.
Error types will be returned in HTTP response. If the sign is invalid, then the http status code 401 will be returned. If the sign is valid, then it will return HTTP status code 200 whatsoever, the error will be returned in the HTTP response body. The structure of our response body is normally:
{
"code": 0,
"msg": "succeed",
"data": {}
}
4.2 Error Code List
Please Refer to the Error Code List
5 Open API from the saas provider
In the process of creating product mapping, SUNMI store open platform might request the saas provider to provide the following API:
5.1 Get all products Information List
API description : This API is used for SUNMI store open platform to get all product information from the saas provider. Note that for different saas provider the return data structure can be different.
The SUNMI Store Open Platform structure consists of 2 different units: merchant and store. Merchant is the basic unit to use the open platform. Users will be able to create mutilevels of stores to which the equipments belong. All products, membership information and face information from the equipments will be saved to the corresponding store. Additionally, if there are cooperation with other software service, a shop-to-shop mapping is needed first. After the mapping is established, the software service will be able to use the open store service. The open platform supports 2 ways of creating the mapping: either the software service provide the API to create the mapping or the open platform will. The details of it will be provided in chapter 2. All devices and data are aggregated based on the stores in SUNMI Store, which means that all devices are “bound” to a specified store. Meanwhile, users’ operation on devices and data are also based on stores. As shown below, there will be a multilevel shop system under 1 merchant. In this system, all data and device belongs to a specific shop.
If not specified, the parameter used to identify the store should be included in the parameters for all requests. Please see the table below:
parameter
required
type
description
shop_id
yes
string
the unique identifier for the shop in the saas provider
Note: the parameter shop_id is the unique identifier of a shop on the SaaS provider. Once it is determined, SUNMI Store open platform will use this ID for all request. Please refer to chapter 2 on how to map the shop to this unique identifier on SUNMI Store.
2. Mapping the shops
Before doing actual business on SUNMI store, the shop must on the saas provider must map themselves to the SUNMI store open platform. By mapping the shops to the correct shop_id, SUNMI store open platform will be able to recognize the shop to operate on.
There are currently 2 ways to do the mapping. The first will be requesting SUNMI store open platform API and the second one is requesting the API provided by the saas provider. User can do it either way.
2.1 Requesting the saas provider API
When users choose to do the mapping by requesting the saas provider API, they must be provided with the contents below:
The identifier of the shop, like the shop number, username and password
The HTTP API for the saas provider to validate the information above
After getting the information above, users can click the button 对接ERP to start the mapping.
Then the user can select the SaaS provider to do the mapping on the page below.
After clicking the button 保存 (Save), SUNMI Store will call the validation API provided by the SaaS provider to check if the information is valid. After the validation is passed, SUNMI Store open platform will record the shop information and the shop ID the user logged in with.
For all the request after, if the user pass the shop_id parameter in the request, it will automatically be done on the shop with this ID.
2.1.2 Saas Provider API Example
API description: this API is the request by by SUNMI Store open platform to validate the data provided by the user on SUNMI Store open platform to do the shop mapping.
For different saas provider, the identifier of a shop can be different and the way to validate the data should be discussed for each distinct saas provider. The example below use the shop id and the verification code as the identifier.
User can also do the shop mapping by requesting the SUNMI store open platform API.
First of all, user needs to register an account and create a merchant and a shop on SUNMI Store platform or SUNMI Assistant App. After creation, the user can obtain the API key by clicking on the menu on the left side: 基础数据 (basic data) → 门店管理 (store management) → 查看店铺信息 (check store info) to pop out the page below.
Click the 获取对接凭证 (get API key) to obtain the API key and the unique shop ID created by SUNMI Store system for the shop. To ensure the effectiveness and safety of the information, the interface voucher is valid for 24 hours, and a new API key can be obtained if the former one expired.
User can input the above two information to the saas provider shop mapping page to conduct verification through the shop mapping API provided by SUNMI Store open platform. For details, please refer to the API in chapter 4.
3. Mapping APIs
3.1 API Specifications
3.1.1 Protocol
All Open APIs are HTTP request with POST method only.
unique identifier provided by SUNMI store open platform
random
yes
string
6-10 digits random string with numbers and alphabets.
timestamp
yes
int
current 10 digit unix timestamp
sign
yes
string
see 3.1.2
3.2 API list
API address
description
/shop/bind
create a shop mapping
/shop/unbind
delete a shop mapping
/shop/update
update a shop mapping
3.3 API Details
3.3.1 Create a shop mapping
API description: users can create a shop mapping between SUNMI store open platform and the saas platform by calling this API.
API address: /shop/bind
Parameters:
parameter
required
type
description
shop_id
yes
string
the ID of the shop provided by the saas provider
shop_name
yes
string
the name of a shop
sunmi_shop_no
yes
string
the shop number provided by the open platform.
sunmi_shop_key
yes
string
the API key mentioned in chapter 2.2
company_id
yes
string
The unique ID of the merchant
company_name
yes
string
the name of a merchant
contact_person
yes
string
the name of the contact person
phone
yes
string
the phone number of the contact person
industry_id
no
int
the industry number of a shop
industry_name
no
string
the industry name of a shop
province
no
string
the province of the shop’s location
city
no
string
the city of the shop’s location
district
no
string
the disctrict of the shop’s location
address
no
string
the address of the shop’s location
mail
no
string
the mail address of the shop
format
no
int
Store format: 0 – None; 1 – pay before having meal; 2 – pay after having meal. 0 by default.
status
no
int
Store status: 1 – enabled; 2 – disabled; 1 by default
Return value:
{
code: 0
msg: "succeed"
data: {}
}
Error:
Error code
description
5000
database error
5032
invalid shop_id
5041
invalid saas provider
5042
shop already mapped
5043
API key error
3.2.2 Delete a shop mapping
API description: users can delete a shop mapping between SUNMI store open platform and the saas platform by calling this API.
API address: /shop/unbind
Parameter:
parameter
required
type
description
shop_id
yes
string
the shop_id of the shop to be unmapped
Return value:
{
code: 0
msg: "succeed"
data: {}
}
Error:
Error code
description
5032
invalid shop_id
5041
invalid saas provider
5000
database error
3.2.3 Update a shop mapping
API description: users can update a shop mapping between SUNMI store open platform and the saas platform by calling this API. (Currently the contact name and contact phone cannot be changed)
API address: /shop/bind
Parameter:
parameter
required
type
description
shop_id
yes
string
the ID of the shop provided by the saas provider
shop_name
yes
string
the name of a shop
company_name
yes
string
the name of a merchant
industry_id
no
int
the industry number of a shop
industry_name
no
string
the industry name of a shop
province
no
string
the province of the shop’s location
city
no
string
the city of the shop’s location
district
no
string
the disctrict of the shop’s location
address
no
string
the address of the shop’s location
mail
no
string
the mail address of the shop
format
no
int
Store format: 0 – None; 1 – pay before having meal; 2 – pay after having meal. 0 by default.
status
no
int
Store status: 1 – enabled; 2 – disabled; 1 by default
Return value:
{
code: 0
msg: "succeed"
data: {}
}
Error code:
error code
description
5032
invalid shop_id
5041
invalid saas provider
5000
database error
4. Merchant Mappings
For chain-stores, users need to manage multiple stores, the devices in stores and the data generated correspondingly. SUNMI Store open platform and the cooperative SaaS platform should create merchants mapping.
The API for mapping merchants are still developing
If there is merchant level setting in the cooperative SaaS platform, then when calling bindShop, the user can pass merchant ID and merchant name which can be used as the key to bind the merchant and the store for the interface (for aligning merchant) to come.
5. Appendix
Authentication
1.Background
Authentication is designed to ensure the security of all Open APIs of SUNMI store Open Platform. All HTTP Request in the SUNMI store Open Platform will be authenticated by the method described below. The content below describes how to pass the Sunmi store authentication and use its service.
2. Specification
2.1 Protocol
All open API in SUNMI store open platform uses HTTPS protocol with POST method.
2.2 Sign rules
SUNMI store open platform will distribute the following to all who uses our API:
app_id: the unique identifier of a user ( for some special API, the app_id can be skipped)
secret_key: the signing key of the user
The sign of the HTTP request will be generated from the parameters with the following rules:
There must be a parameter named ‘random’, it is a random string combination of number and alphabets with the length of 6 to 10 digits.
There must be a parameter named ‘timestamp’, it is the current 10-digit unix timestamp, for details please visit: https://tool.chinaz.com/tools/unixtime.aspx
There must be a parameter named ‘app_id’
Sort all parameter in the key’s alphabetic order. Create a string which concatenate all key-value pair in such order.
Concatenate the user’s secret_key at the tail of the string. For details, please read the example
use the MD5 signature of the string
Convert the MD5 sign to all caps.
Example:
Suppose the parameter of the request is the following:
product_id: 389238
user_id: 29389
content: newproductmask
environment: test
Then, by the rules above, we can generate our sign below:
Sunmi Store Open Platform will check if the sign is valid, if the sign is invalid then it will return error code: 5090. It will then check if the timestamp is within the reasonable time window, if the request is outdated, it will return error code: 5091.
3. Authentication Procedure
SUNMI Store Cloud Platform will conduct authentication in the following sequence.
4. Return Value
4.1 Error Type
Error types will be returned in HTTP response. If the sign is invalid, then the http status code 401 will be returned. If the sign is valid, then it will return HTTP status code 200 whatsoever, the error will be returned in the HTTP response body. The structure of our response body is normally: