云打印机CP事件及消息示例

1 事件列表

event取值说明
6001未经处理的文字小票上传消息
6002未经处理的图片小票上传消息
6003经过处理的小票消息

2 事件消息示例

2.1 未经处理的文字小票上传消息(event=6001)

{
  "id": 123,     // 系统生成的小票ID
  "sn": "sn",    // 打印设备SN
  "text": "abc"  // 文字小票内容
}

2.2 未经处理的图片小票上传消息 (event=6002)

{
  "id": 123,  // 系统生成的小票ID
  "sn": "sn", // 打印设备SN
  "base64_image": "avc"  // 图片小票的base64 encoded string
}

2.3 经过处理的小票消息 (event=6003)

{
  "id": 123,  // 系统生成的小票ID
  "sn": "sn",  // 打印设备SN
  "order_id": 456, // 小票上的订单ID
  "order_time": "2020-01-01", // 小票生成时间
  "total_payment": 10.11  // 小票金额
  "sales_detail_list": [{   //明细列表
    "amount": 10,          // 商品单价
    "item":   "商品",      // 商品名字
    "quantity": 1          // 商品数量
  },
  ...
  ]
}

Order APIs

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.

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.

Content-Typeapplication/x-www-form-urlencoded
return typeJSON
encodingUTF-8
signing algorithmMD5
signing rulessee chapter 2.2

2.2 Signing rules

see Authentication

2.3 Common parameter

parameterrequiredtypedescription
app_idyesstringunique identifier provided by SUNMI store open platform
randomyesstring6-10 digit random string with number and alphabets
timestampyesint10 digit current unix timestamp
signyesstringsee 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
parametertyperequireduniquedescription
order_nostringthe unique identifier of an order
order_typeinttype of an order(1- normal order、 2- canceled, 3-exchanged for new product, 4- suspend,5-报表)
order_timeintorder timestamp
order_start_timeintthe start time of an order
purchase_amountdouble (2 digit precision)
discount_amountdouble (2 digit precision)
received_amountdouble (2 digit precision)
payment_typeint1-cash、2-alipay、3-wechat pay、4-QQpay、5-JD wallet、6-credit card、7-unionpay QR code、8-other
customer_countintdefault 1
device_snstring
software_namestring
software_specstring
hardware_namestring
hardware_specstring
cashier_nostring
cashier_diskstring
shop_assistant_nostring
order_sourceint1-offline、 2-online (default offline)
member_nostring
ali_idstring
wechat_open_idstring
member_pointsdouble
coupon_nostring
coupon_source int1-shop,2-alipay, 3-wechat pay, 4-other
receipt_nostring
sunmi_receipt_nostring
product_listarray[product]
see the list below
product
parametertypedescriptionrequired
namestringname of the product
seq_numstringsequence number of the product
bar_codestringbar code of the product
specstringspec of the product
unitstringunit of the product
quantitydouble (3 digit precision)sell quantity
stock_quantity double (3 digit precision) stock quantity
original_pricedouble (2 digit precision) original price
present_pricedouble (2 digit precision) current price
promote_amountdouble (2 digit precision) promotion price
subtotal_amountdouble (2 digit precision) subtotal of this product
product additional properties for specific product
parametertypedescriptionrequired
colorstringcode for color
sizestringcode 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)

Parameters

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
order_listyesarraythe list of order needed to be update

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
    "invalid_list": [
      "CN0000938",
      "CN0000939"
    ]
  }
}

Errors:

Error codeDescription
5041invalid saas provider
5047invalid order

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:

{
    code:0
    msg: "success"
    data: {}
} 

4.2 Error list

see Error List

5 Examples

Error Codes

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.

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 codedescription
5090invalid sign
5091invalid timestamp
5092invalid random value
5000database error
5013invalid saas provider or shop
5015invalid product
5022invalid parameter
5041invalid saas provider
5047invalid 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.

Content-Typeapplication/x-www-form-urlencoded
data typeJSON
encodingUTF-8
signatureMD5
sign rule see chapter 2.2

2.2 Sign rule

See authentication

2.3 Common parameter

parameterrequiredtypedescription
app_idyesstringunique identifier provided by SUNMI store open platform
randomyesstring6-10 digits random string with numbers and alphabets.
timestampyesintcurrent 10 digit unix timestamp
signyesstringsee 2.2

3. Event Monitor APIs

3.1 API list

API addressdescription
/hook/addadd the HTTP callback address for a set of events
/hook/deletedelete the HTTP callback address for a set of events

3.2 API detail

8.3.1 Add an event monitoring

API description: By requesting this API, User could set up an http callback for a set of events of their choice on the SUNMI store open platform.

When the specified events happened, open platform will request the given HTTP API.

The authorization of this HTTP API must be the same as the SUNMI store open platform API method.

Following parameters must be included in the callback API:

parameterrequiredtypedescription
shop_idyesstringthe identifier of the shop in open platform
eventyesintThe type of event to monitor
payloadyesstringthe specific structure of message in JSON

API address: /hook/add

Parameters

parameterrequiredtypedescription
shop_idstringthe identifier of the shop in open platform
http_callbackstringthe http call back API
event_listarray[int]the list of event to be monitored

return value: 

{
  code: 0,
  msg: "succeed",
  data: {
  }
}

parameter event

event valuedescription
1010IPC FM010 motion detecting message
1100add a face to a group result message
2001IPC real time face recognition message
4100price change message (currently unavailable)

payload(event=1010): 

{
  ipc_id: 029388
  sn: "FS101D8BS00080",
  name: "设备1",
 video_url:"http://xxx.xxx.xxx.xxx/xxx/xxx/41b061f6f10dbd6fe1aaf469fb0ab012d9193d9655816af31cdfbcsdfe71a5fe1",
  model_name: "FM020",
  motion_type: 0,
}

Parameter motion_type:

motion_type valuedescription
1motion detection event
2voice detection event

payload(event=1100): 

{
  code: 0,
  msg: "",
  face_id:195
}

Parameter code

code valuedescription
5527bad face image
5000database error

payload(event=2001): 

{
    ipc_id: "928",
    face_id: "29195",
    gender: 1,
    age_range: 4,
    group_id: "8927",
    group_name: "stranger",
    group_type": 2
}

Parameter gender:

gender valuedescription
0unknown
1male
2female

parameter age_range:

age_range valuedescription
1age 0~6
2age 7~12
3age 13~18
4age 19~28
5age 29~35
6age 36~45
7age 46~55
8age 56~

Parameter group_type

group_type valuedescription
1stranger face library
2familiar face library
3shop assistant face library
5custom face library

8.3.2 Cancel event monitoring

API description: By requesting this API, the user can cancel the monitor on given events

API address:/hook/delete

Parameters

parameterrequiredtypedescription
shop_idyesstringthe identifier of the shop in open platform
event_listyesarray[int]the list of events that need to be canceled

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
  }
}

Parameter event:

event valuedescription
1010IPC FM010 motion detecting message
1100add a face to a group result message
2001IPC real time face recognition message
4100price 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.

Content-Typeapplication/x-www-form-urlencoded
return type JSON
encodingUTF-8
signing algorithmsMD5
signing rules see chapter 2.2

2.2 Signing rules

see Authentication

2.3 common parameter

parameterrequiredtypedescription
app_idyesstring unique identifier provided by SUNMI store open platform
randomyesstring 6-10 digit random string with number and alphabets
timestampyesint 10 digit current unix timestamp
signyesstring see chapter 2.2

3. Shop design

See Shop section

4. ESL APIs

4.1 Description

This set of APIs are used to manage the basic properties of the ESL.

4.2 API List

API addressDescription
/device/esl/bindbind an ESL to a shop
/device/esl/unbindunbind an ESL from a shop
/device/esl/getListget the list of ESLs from a shop
/device/esl/getInfoget the detail info of a given ESL
/device/esl/pushImagepush an image to the ESL
/device/esl/flashLedorder the given ESL to flash its LED light
/device/esl/setRefreshTimeset the refresh rate of a given esl (unavailable yet)
/device/getOverviewget the overview of both a shop’s ESL and its AP

4.3 API detail

4.3.1 Bind an ESL to a shop

API description:By calling this API, user can bind his ESL to a given shop

API address:/device/esl/bind

Parameters

parameterrequiredtypedescription
shop_idyesstring The identifier of the shop in open platform
esl_codeno (either esl_code or esl_sn must be provided)string8-digit ID of the ESL
esl_snno (either esl_code or esl_sn must be provided)stringSerial number of the ESL

Return Value: 

{
  code: 0,
  msg: "succeed",
  data: {
    "esl_id": "129200",
  }
}

Errors:

Error codeDescription
5000database error
5301invalid ESL
5338ESL already bounded

4.3.2  Unbind an ESL from a shop

API description:By calling this API, user can bind his ESL to a given shop

API address:/device/esl/unbind

Parameters

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
esl_idyesstringThe unique ID from bind API

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
    "esl_id": "129200",
  }
}

Errors:

Error codeDescription
5000database error
5301invalid ESL

4.3.3 Get the list of ESLs from a shop

API description:By calling this API, user can get the list of ESLs from a shop

API address:/device/esl/getList

Parameters

parametersrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
page_numno (default 1)intcurrent page
page_sizeno (default 10)intThe number of items per page

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
    "total_count": 100,
    "esl_list": [{
      "esl_id": "129200",
      "esl_code": "SKDI39DN",
      "esl_sn": "B101194N00002",
      "model_name": "SL121+",
      "status": 2
    }, 
    .......
    ]
  }
}

Parameter Status:

status valuedescription
0Not activated
1Not binded
2Waiting For Data
3Push success
4Push Failed

Errors:

Error CodeDescription
5000database error
5020invalid parameter

4.3.4 Get the detail info of a given ESL

API description:By calling this API, user can get the detail info of a given ESL

API address:/device/esl/getInfo

Parameters:

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
esl_code
no (either esl_code or esl_sn must be provided)string8-digit ID of the ESL
esl_idno (either esl_code or esl_sn must be provided)stringunique ID of the ESL

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
    "esl_id": "1000",
    "esl_code": "SKDI39DN",
    "esl_sn": "B101194N00002",
    "model_name": "SL121+",
    "status": 2,
    "screen_size_name": "2.13寸",
    "software_version": "1.0.1",
    "battery": 90,
    "rssi": -23,
    "connect_time": 15683920394,
    "ap_id":  "10200",
    "ap_sn": "B201E95D00001",
     "ap_sn": "B201E95D00001",
  }
}

Parameter status

status valuedescription
0Not activated
1Not binded
2Waiting For Data
3Push Success
4Push Failed

Errors:

error codedescription
5000database error
5023parameter missing
5502invalid ESL

4.3.5 Push an image to the ESL

API description:By calling this API, user can push an image to a given ESL

API address:/device/esl/pushImage

Parameters:

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
esl_idyesstringThe ID of the given ESL
picyesfileThe picture to be pushed

Note:

The color and the resolusion of the picture must meet the standard below, otherwise the ESL won’t be able to display that.

ESL typecolor supportedpicture size(px)
SL121black, white, red212 * 104
SL126black, white, red296 * 152
SL126+black, white296 * 152
SL142black, white, red400 * 300
SL142+black, white, red400 * 300

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
  }
}

Errors:

Error codedescription
5004system error
5005invalid file
5020invalid parameter
5300invalid AP
5301invalid ESL

4.3.6 Order the given ESL to flash its LED light

API description:By calling this API, user can order the given ESL to flash its LED light

API address:/device/esl/flashLed

Parameters

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
esl_idyesstringThe ID of the given ESL
channelnointLED color: 1-white, 2-blue, 4-green, 8- red, 512-cyan, 1024-purple, 2048-yellow(default 4)
cyclenointThe duration of a single flash, 1 cycle = 10ms. (default 100)
durationnointThe total flash times (default 8)

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
  }
}

Errors:

Error codedescription
5000database error
5301invalid ESL

4.3.7 Set the refresh rate of a given esl

API description:By calling this API, user can set the refresh rate of a given esl. Currently this API is not available.

API address:/device/esl/setRefreshTime (unavailable yet)

Parameters

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
esl_code
no (either esl_code or esl_id must be provided)string8-digit ID of the ESL
esl_idno (either esl_code or esl_id must be provided)intThe unique ID of a given ESL
refresh_timeyesintrefresh time in second

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
  }
}

4.3.8 Get the overview of both a shop’s ESL and its AP

API description:By calling this API, user can set the refresh rate of a given esl. Currently this API is not available.

API address:/device/getOverview

Parameters:

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform

Return value:

{
  code: 0,
  msg: "succeed",
  data: {
    "ap_total_count":24,
    "esl_total_count":55,
    "esl_pending_count":54,
    "esl_failed_count":3
  }
}

5. Access Point APIs

5.1 Description

The set of APIs used to manage the basic properties of the Access Points(AP)

5.2 API lists

API addressdescription
/device/ap/bindbind an AP to a shop
/device/ap/unbindunbind an AP from a shop
/device/ap/getListget the List of APs from a shop
/device/ap/getInfoget the info about a given AP
/device/ap/updateNameupdate the name of an AP
/device/ap/rebootreboot a given AP
/device/ap/setScanTimeset the scan time of a given AP (currently unavailable)

5.3 API detail

5.3.1 Bind an AP to a shop

API description:By calling this API, user can bind an AP to a shop.

API address:/device/ap/bind

Parameters:

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
ap_snyesstringThe serial number of an AP
ap_namenostringThe name of an AP
ap_macnostringThe MAC Address of an AP

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
    "ap_id": "129200,
  }
}

Errors:

Error codeDescription
5000database error
5023invalid parameter
5300invalid AP
5339AP already bound to a shop

5.3.2 Unbind an AP from a shop

API description:By calling this API, user can unbind an AP from a shop.

API address:/device/ap/unbind

Parameters

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
ap_idyesstringThe ID of an AP

Return value: 

{
  code: 0,
  msg: "succeed", 
  data: {
  }
}

Errors:

Error codeDescription
5000database error
5300invalid AP

5.3.3 Get the List of APs from a shop

API description:By calling this API, user can get the List of APs of a shop.

API address:/device/ap/getList

Parameters:

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
page_numnointcurrent page (default 1)
page_sizenointcurrent items per page (default 10)

返回值: 

{
  code: 0,
  msg: "succeed", 
  data: {
    "total_count": 100,
    "ap_list": [{
      "ap_id": “1000”,
      "ap_sn": "B201E96500001",
      "ap_name": "Gate 5", 
      "esl_count": 1920,
      "status": 2
    },
    ......
  ]}
}

Return parameter status

status valuedescription
0not activated
1online
2offline

Errors:

Error codedescription
5000database error
5020invalid parameter

5.3.4 Get the info about a given AP

API description:By calling this API, user can get the info about a given AP.

API address:/device/ap/getInfo

Parameters

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
ap_idyesstring The ID of an AP

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
    "ap_id": “1000”,
    "ap_sn": "B201E96500001",
    "ap_name": "Gate 5",
    "model_name": "SLAP1",
    "status": 2,
    "esl_count": 1920,
    "software_version": "1.0.1",
    "connect_time": 15683920394,
  }
}

Return parameter status

status valuedescription
0not activated
1online
2offline

Errors:

Error codedescription
5000database error
5011invalid model type
5300invalid AP

5.3.5 Update the name of an AP

API description:By calling this API, user can update the name of an AP.

API address:/device/ap/updateName

Parameters

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
ap_idyesstringThe id of an AP
ap_nameyesstringThe new name of this AP

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
  }
}

Errors:

Error codeDescription
5000database error
5300invalid 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

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
ap_idyesstringThe ID of an AP

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
  }
}

Errors:

Error codeDescriptions
5000database error
5300invalid 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

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
ap_idyesstringThe ID of an AP
scan_timeyesintThe 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 addressdescription
/device/ap/firmware/getListget the firmware info of APs by model
/device/ap/firmware/upgradeupdate the firmware of APs
/device/esl/firmware/getListget the firmware info of ESLs by model
/device/esl/firmware/upgradeudpate 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:

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
page_numnointCurrent page (default 1) (currently unavailable)
page_sizenointCurrent items per page (default 10) (currently unavailable)

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
    "total_count": 10,
    "ap_firmware_list": [{
      "model_name": "SLAP1",
      "software_version": "1.0.2",
      },
      ......
    ],
  }
}

Errors:

Error codeDescription
5000database error

6.3.2 Update the firmware of APs

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

parameterrequiredtypedescription
shop_idyesstringThe 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

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
page_numnointcurrent page (default 1) (currently not available)
page_sizenointcurrent items per page (default 10) (currently not available)

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
    "total_count": 10,
    "ap_firmware_list": [{
      "model_name": "SLAP1",
      "software_version": "1.0.2",
      },
      ......
    ],
  }
}

Errors:

Error codeDescription
5000database error

6.3.4 Update the firmware of ESLs

API description:By calling this API, user can update the firmware of ESLs by model. This API is currently not available.

API address:/device/esl/firmware/upgrade (currently unavailable)

Parameters

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
  }
}

7. Template management API

7.1 Description

The set of APIs used to manage the template

7.2 API list

API addressdescription
/template/createcreate a new template
/template/updateupdate an existing template
/template/getListget all template
/template/getInfoget the detail of a given template
/template/deletedelete a template

7.3 API detail

7.3.1 Create a new template

API description:By calling this API, user can upload json and create a new template.

API address:/template/create

Parameters

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
template_nameyesstringThe name of the template
template_coloryesintThe color type that the templates support: 1-black and white, 2- black white and red.
template_screenyesintThe screen size this template support (1 – 2.13 inch,2 – 2.6 inch,3 – 4.2 inch)
template_jsonyesstringThe template JSON

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
    "template_id": "1000"
  }
}

Errors:

Error codeDescription
5000database error
5005file error
5343invalid template
5346template name already exists

7.3.2 Update a given template

API description:By calling this API, user can upload json and create a new template.

API address:/template/update

Parameters

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
template_idyesstring
The ID of a template
template_namenostringThe name of a template
template_jsonnostringTemplate JSON

Return value: 

}

{
  code: 0,
  msg: "succeed",
  data: {
  }
}

Errors:

Error codeDescription
5000database error
5005file error
5343invalid template
5346template name already exists

7.3.3 Get all template

API description:By calling this API, user can get all templates.

API address:/template/getList

Parameters

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
page_numnointcurrent page
page_sizenointcurrent items per page

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
    "total_count": 15,
    "template_list":[{
      "template_id": "100",
      "template_name": "sample",
      "template_color": 1,  /* currently not available*/
      "template_screen": 1
    },
    .......
    ]
  }
}

Errors:

Error codeDescription
5000database error
5020invalid parameters

Return parameter color:

color valuedescription
1black and white
2black, white and red

Return parameter screen:

screen valuedescription
12.13 inch
22.6 inch
34.2 inch

7.3.4 Get the detail of a given template

API description:By calling this API, user can get the detail of a given template.

API address:/template/getInfo

Parameters

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
template_idyesstringThe unique ID of a template

Rerturn value: 

{
  code: 0,
  msg: "succeed",
  data: {
    "template_name": "sample",
    "template_color_name": "BW",
    "template_screen_type_name": "2.6",
    "template_json": "...",
    "template_color:": 1, /* currently unavailable */
    "template _screen": 1, /* currently unavailable */
  }
}

Errors:

Error codeDescription
5000database error
5005file error
5343invalid template

Return parameter color:

color valuedescription
1black and white
2black white and red

Return parameter screen:

screen valuedescription
12.13 inch
22.6 inch
34.2 inch

7.3.5 Delete a template

API description:By calling this API, user can delete a given template.

API address:/template/delete

Parameters

parameterrequiredtypedescription
shop_idyesstring The identifier of the shop in open platform
template_id_listyesarrayThe unique ID of a template

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
  }
}

Errors:

Error codeDescription
5000database 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 addressdescription
/product/bindEslbind a product to an ESL
/product/unbindEslunbind a product from an ESL
/product/getBindEslListget the list of ESLs a product is bound to
/product/updateTemplateupdate the template of a product
/product/getInfoget the info of a product
/product/getListget 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

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
product_idyesstringThe unique ID of a product
esl_codeno (either esl_code or esl_sn must be provided)string8-digit ID of the ESL
esl_idno (either esl_code or esl_sn must be provided)stringThe unique ID of a given ESL
template_idyesstringThe unique ID of a template

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
  }
}

Errors:

Error codeDescription
5000database error
5020invalid parameters
5015invalid products
5343invalid template
5300invalid AP
5301invalid ESL
5338ESL already bounded to another shop
5342invalid ESL image
5006oss 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

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
esl_codeno (either esl_code or esl_sn must be provided)string 8-digit ID of the ESL
esl_idno (either esl_code or esl_sn must be provided)stringThe unique ID of a given ESL

}

{
  code: 0, 
  msg: "succeed",
  data: {
  }
}

Errors:

Error codeDescription
5000database error
5020invalid parameters
5301invalid ESL
5320ESL not bounded
5336ESL bound to another shop   
5342invalid ESL image
5006oss error

8.3.3 Get the list of ESLs

API description:By calling this API, user can unbind a product from an ESL

API address:/product/getBindEslList

Parameters

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
product_idyesstringThe unique ID of a product

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
    "esl_list": [{
      "esl_id": ”1000“,
      "esl_code": "DJKS90EN",
      "template_id": ”10002“,
      "status": 1,
      },
      .......
      ]
    }
  }
}

Errors:

Error codedescription
5000database error
5020invalid parameters
5301invalid ESL
5015invalid product

8.3.4 Update the template of a product

API description:By calling this API, user can update the template of a product

API address:/product/updateTemplate

Parameters

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
product_idyesstringThe unique id of the product
template_idyesstring
The unique id of a template

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
  }
}

Errors:

Error codedescription
5000database error
5020invalid parameter
5005file error
5006oss error
5343invalid template
5015invalid product
5342invalid ESL image

8.3.5 Get product info

API description:By calling this API, user can get the product info of a specific product

API address:/product/getInfo

Parameters

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
product_idyesstringThe unique ID of a product

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
    "id":,
    "name":,
    "alias":,
    "seq_num":,
    "bar_code":,
    "qr_code":,
    "unit":,
    "spec":,
    "area":,
    "level":,
    "brand":, 
    "expire_time":,
    "price":,
    "promote_price":,
    "member_price":,
  }
}

Errors:

Error codedescription
5000database error
5015invalid product id

8.3.6 Get product list

API description:By calling this API, user can get the product list of a given shop

API address:/product/getList

Parameters

parameterrequiredtypedescription
shop_idyesstringThe identifier of the shop in open platform
keywordnostringsearching keywords
page_numnointpage number
page_sizenointnumber of items per page

Return value: 

{
  code: 0,
  msg: "succeed",
  data: {
    "total_count": 1,
    "product_list": [{
      "id": ,
      "name": ,
      "seq_num": ,
      "bar_code": ,
      "category_id": ,
      "price": ,
      "modified_time":
    }]
  }
}

Errors:

Error codeDescription
5000database error
5020invalid parameters

9. Notifications

9.1 Description

After receiving the message from the device, SUNMI store open platform can push notification to the saas providers based on their need.

9.2 API specification

具体接口和实现标准,参考 015.消息推送中心

Product APIs

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.

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.

Content-Typeapplication/x-www-form-urlencoded
return typeJSON
encodingUTF-8
signing algorithmsMD5
signing rulessee chapter 2.2

2.2 Signing rules

see Authentication

2.3 common parameter

parameterrequiredtypedescription
app_idyesstringunique identifier provided by SUNMI store open platform
randomyesstring6-10 digit random string with number and alphabets
timestampyesint10 digit current unix timestamp
signyesstringsee 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

parametertypedescriptionrequiredsaas system parameters
idstringthe id in sunmi databaseyes
seq_numstringproduct sequence numberno
bar_codestringproduct bar codeno
namestringproduct nameyes
aliasstringproduct aliasno
pricedoublecurrent product priceyes
promote_pricedoubleproduct promotion priceno
member_pricedoublemembership priceno
specstringspecs for the productno
unitstringunit for the productno
levelstringlevel of the productno
areastringarea of the productno
brandstringbrand of the productno
qr_codestringqr code url for the productno
expire_timeintproduct expire timeno

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 address:/product/create (just for reference)

parameters:

parameterrequiredtypedescription
shop_idyesstringthe identifier of the shop in open platform
product_listyesarray array of product

product parameter:

parameterrequiredtypedescription
idyesstringunique identifier of the product
seq_numnostringproduct sequence number
bar_codenostringproduct bar code
nameyesstringproduct name
aliasnostringproduct alias
pricenodouble(non-negative ,2digit precision)current selling price
promote_pricenodouble( non-negative ,2digit precision )promote price
member_pricenodouble( non-negative ,2digit precision )membership price
specnostringproduct specs
unitnostringproduct unit
levelnostringproduct level
areanostringproduct area
brandnostringproduct brand
qr_codenostringproduct qr code url
expire_timenointproduct expire time

Return value: 

{
    "code": 0,
    "msg": "succeed",
    "data": {
        "exist_list": [
            "1"
        ],
        "invalid_list": [
            "400"
        ],
    }
}

Error list

Error codedescription
5000database error
5041invalid saas provider
5015invalid product

3.2.3 Update New Product

API description : This API is used after a saas system had udpate a new product to inform the open platform system about the change.

Note that the update API will only update the existing product. If there are no such product, the product id will be returned in the not_exist_list.

Update API will only modify the existing properties of a product, if there are no such property in the system, then it will do nothing.

API address:/product/update(for reference only)

Parameter

parameterrequiredtypedescription
shop_idyesstringthe identifier of a shop
product_listyesarraythe list of product to be updated

product parameter

parameterrequiredtypedescription
idyesstringID of the product
seq_numnostringsequence number of the product
bar_codenostringbar code of the product
namenostringname of the product
aliasnostringalias of the product
pricenodouble( non-negative ,2digit precision )current price
promote_pricenodouble( non-negative ,2digit precision )promotion price
member_pricenodouble( non-negative ,2digit precision )membership price
specnostringspec of the product
unitnostringunit of the product
levelnostringlevel of the product
areanostringarea of the product
brandnostringbrand of the product
qr_codenostringQR code url of the product
expire_timenointexpiration time of the product

Return value:

{
    "code": 0,
    "msg": "succeed",
    "data": {
        "not_exist_list": [
            "5"
        ],
        "invalid_list": []
    }
}

Errors:

error codedescription
5000database error
5041invalid saas provider
5015invalid product

3.2.4 Delete Product

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.

API address:/product/delete(for reference only)

Parameters

parameterrequiredtypedescription
shop_idyesstringid of the shop
product_key_listyeslist list of product id to be deleted

Return value: 

{
    "code": 0,
    "msg": "succeed",
    "data": {
        "not_exist_list": [
            "100"
        ]
    }
}

Error:

Error codeDescription
5000database error
5041invalid saas provider
5015invalid product

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:

{
    "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.

API addresshttps://example.SaaS.com/api/getProductList(for reference only)

Parameters

parameterrequiredtypedescription
shop_idyesstringid of the shop
page_numyesintcurrent page number
page_sizeyesintnumber of items returned per request

Return value:

{
    "code": 0,
    "msg": "succeed",
    "data": {
        "total": 2,
        "product_list": [
            {
                "name": "example_product",
                "seq_num": "28929380903",
                "price": 10.00,
            }, ...
        ]
    }
}

6 Examples

This chapter offers some examples for creating the product mapping.

The API below requires the shop mapping done to work. For shop mappings please see shop API

The sample paramater we use (we have skipped the sign, random, etc. parameters for reader’s convenience):

app_idsecret_keyshop_id
APPID6917LTYtokenlty1237948

As shown below, after the initial shop mapping, there are not products in the list.

6.1 Example to create new product

6.1.1 Success example

After successfulling creating the shop binding, user will need to call product/create to create product on open platform

Parameters:

app_idAPPID6917LTY
shop_id7948
product_list[{“name”:”\u53ef\u53e3\u53ef\u4e50\/\u704c\u88c5″,”id”:”1″,”seq_num”:”cola58476″,”bar_code”:”6958644000259″,”unit”:”\u7f50″,”price”:”3.2″,”member_price”:”3″,”spec”:”250ml”,”level”:””,”brand”:”\u53ef\u4e50″}]

Return value:

{
    "code": 0,
    "msg": "succeed",
    "data": {
        "exist_list": [],
        "invalid_list": []
    }
}

After refreshing the page, we can see that we successfully created a product.

Click Details for the product detail.

6.1.2 Failed Example: product already existed

Resend the same request in 6.1.1, we can find the product_id in the exist list, telling us this product already existed

Parameters:

app_idAPPID6917LTY
shop_id7948
product_list[{“name”:”\u53ef\u53e3\u53ef\u4e50\/\u704c\u88c5″,”id”:”1″,”seq_num”:”cola58476″,”bar_code”:”6958644000259″,”unit”:”\u7f50″,”price”:”3.2″,”member_price”:”3″,”spec”:”250ml”,”level”:””,”brand”:”\u53ef\u4e50″}]

Return value:

{
    "data": {
        "exist_list": [
            "1"
        ],
        "invalid_list": []
    },
    "code": 0,
    "msg": "succeed"
}

6.1.3 Failed Example: invalid JSON

In this example we put an invalid JSON in the request body

Parameter:

app_idAPPID6917LTY
shop_id7948
product_list[{“name”:”\u53ef\u53e3\u53ef\u4e50\/\u704c\u88c5″,,,”id”:”1″,”seq_num”:”cola58476″,”bar_code”:”6958644000259″,”unit”:”\u7f50″,”price”:”3.2″,”member_price”:”3″,”spec”:”250ml”,”level”:””,”brand”:”\u53ef\u4e50″}]

Return value:

{
    "code": 1,
    "msg": "product_list: JSON.parse error"
}

6.1.4 Failed Example: missing required field

In this request, the request body is missing parameter id

Parameters:

app_idAPPID6917LTY
shop_id7948
product_list[{“name”:”\u53ef\u53e3\u53ef\u4e50\/\u704c\u88c5″,”id”:”1″,”seq_num”:”cola58476″,”bar_code”:”6958644000259″,”unit”:”\u7f50″,”price”:”3.2″,”member_price”:”3″,”spec”:”250ml”,”level”:””,”brand”:”\u53ef\u4e50″}]

Return value:

{
    "code": 1,
    "msg": "invalid saas product info"
}

6.2 Example to update an existing product

6.2.1 Success example – update the existing product

Requesting the product/update API to update the price of a product

Parameters:

app_idAPPID6917LTY
shop_id7948
product_list[{“id”:1, “price”:”3.5″}]

Return value:

{
    "data": {
        "not_exist_list": [],
        "invalid_list": []
    },
    "code": 0,
    "msg": "succeed"
}

In the sunmi store page, we can see that the price has already been changed and the update time is recorded.

before

after

6.2.2 Success example – create a new product

The update API can also be used to create a product that doesn’t exist.

Parameters:

app_idAPPID6917LTY
shop_id7948
product_list[{“id”:2, “name”:”Non-Exist Product”,”seq_num”:”nonexist1″,”price”:”58.2″}]

Return value:

{
    "data": {
        "not_exist_list": [
            "2"
        ],
        "invalid_list": []
    },
    "code": 0,
    "msg": "succeed"
}

The return value shows that the product with id “2” does not exist, so it created an item with product id 2.

before

after

6.2.3 Failed Example: invalid JSON

In this example we put an invalid JSON in the request body

Parameters:

app_idAPPID6917LTY
shop_id7948
product_list[{“name”:”\u53ef\u53e3\u53ef\u4e50\/\u704c\u88c5″,,,”id”:”1″,”seq_num”:”cola58476″,”bar_code”:”6958644000259″,”unit”:”\u7f50″,”price”:”3.2″,”member_price”:”3″,”spec”:”250ml”,”level”:””,”brand”:”\u53ef\u4e50″}]

Return value:

{
    "code": 1,
    "msg": "product_list: JSON.parse error"
}

6.2.4 Failed Example: missing required field

In this request, the request body is missing parameter id

Parameters:

app_idAPPID6917LTY
shop_id7948
product_list[{“name”:”\u53ef\u53e3\u53ef\u4e50\/\u704c\u88c5″,”id”:”1″,”seq_num”:”cola58476″,”bar_code”:”6958644000259″,”unit”:”\u7f50″,”price”:”3.2″,”member_price”:”3″,”spec”:”250ml”,”level”:””,”brand”:”\u53ef\u4e50″}]

Return value:

{
    "code": 1,
    "msg": "invalid saas product info"
}

6.3 Example to delete an existing product

6.3.1 Success example

Requesting product/delete API to delete an existing product.

Parameters:

app_idAPPID6917LTY
shop_id7948
product_key_list[2]

Return value:

{
    "data": {
        "not_exist_list": []
    },
    "code": 0,
    "msg": "succeed"
}

In the product list, we can see that the product has already been deleted.

before

after

6.3.2 Failed Example: invalid product

In this request we tried to delete a product that does not exist

Parameters:

app_idAPPID6917LTY
shop_id7948
product_key_list[3]

Return value:

{
    "data": {
        "not_exist_list": [
            "3"
        ]
    },
    "code": 0,
    "msg": "succeed"
}

Shop APIs

1.Background

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:

parameterrequiredtypedescription
shop_idyesstringthe 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.

This image has an empty alt attribute; its file name is image2019-10-19_16-42-16.png

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.

This image has an empty alt attribute; its file name is image2019-10-19_16-46-26.png

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.

API link: https://example.SaaS.com/api/verifyShop (for reference only)

API parameters:

parameter requiredtypedescription
shop_idyesstringthe identifier for a shop in saas platform
verify_codeyesstringthe verification code for that shop id

Return body: (passed)

{
  code:0
  msg: "succeed"
  data: {}
}

Return body: (error)

{
  code:0
  msg: "invalid verify code"
  data: {}
}

2.2 Requesting the open platform API

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.

This image has an empty alt attribute; its file name is image2019-10-19_16-54-11.png
This image has an empty alt attribute; its file name is image2019-10-19_16-56-3.png

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.

content-typeapplication/x-www-form-urlencoded
return data formatJSON
character encodingutf-8
signatureMD5
signing rulessee authentication

3.1.2 Signing rules

See Authentication

3.1.3 Common parameters

parameterrequiredtypedescription
app_idyesstringunique identifier provided by SUNMI store open platform
randomyesstring6-10 digits random string with numbers and alphabets.
timestampyesintcurrent 10 digit unix timestamp
sign yesstringsee 3.1.2

3.2 API list

API addressdescription
/shop/bindcreate a shop mapping
/shop/unbinddelete a shop mapping
/shop/updateupdate 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:

parameterrequiredtypedescription
shop_idyesstringthe ID of the shop provided by the saas provider
shop_nameyesstringthe name of a shop
sunmi_shop_noyesstringthe shop number provided by the open platform.
sunmi_shop_keyyesstringthe API key mentioned in chapter 2.2
company_idyes stringThe unique ID of the merchant
company_nameyesstringthe name of a merchant
contact_personyesstringthe name of the contact person
phoneyesstring the phone number of the contact person
industry_idnointthe industry number of a shop
industry_namenostringthe industry name of a shop
provincenostringthe province of the shop’s location
citynostringthe city of the shop’s location
districtnostringthe disctrict of the shop’s location
addressnostring the address of the shop’s location
mailnostringthe mail address of the shop
formatnointStore format: 0 – None; 1 – pay before having meal; 2 – pay after having meal. 0 by default.
statusnointStore status: 1 – enabled; 2 – disabled; 1 by default

Return value:

{
  code: 0
  msg: "succeed"
  data: {}
}

Error:

Error codedescription
5000database error
5032invalid shop_id
5041invalid saas provider
5042shop already mapped
5043API 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:

parameterrequiredtypedescription
shop_idyesstringthe shop_id of the shop to be unmapped

Return value:

{
  code: 0
  msg: "succeed"
  data: {}
}

Error:

Error codedescription
5032invalid shop_id
5041invalid saas provider
5000database 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:

parameterrequiredtypedescription
shop_idyesstringthe ID of the shop provided by the saas provider
shop_nameyesstringthe name of a shop
company_nameyesstringthe name of a merchant
industry_idnointthe industry number of a shop
industry_namenostringthe industry name of a shop
provincenostringthe province of the shop’s location
citynostringthe city of the shop’s location
districtnostringthe disctrict of the shop’s location
addressnostring the address of the shop’s location
mailnostringthe mail address of the shop
formatnointStore format: 0 – None; 1 – pay before having meal; 2 – pay after having meal. 0 by default.
statusnointStore status: 1 – enabled; 2 – disabled; 1 by default

Return value:

{
  code: 0
  msg: "succeed"
  data: {}
}

Error code:

error codedescription
5032invalid shop_id
5041invalid saas provider
5000database 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:

  1. 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.
  2. 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
  3. There must be a parameter named ‘app_id’
  4. Sort all parameter in the key’s alphabetic order. Create a string which concatenate all key-value pair in such order.
  5. Concatenate the user’s secret_key at the tail of the string. For details, please read the example
  6. use the MD5 signature of the string
  7. 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:

str1 = "app_id=2039dds&content=newproductmask&environment=test&product_id=389238&random=289192×tamp=1593029283&user_id=29389;
str2 = str1 + "&key=kdsofkdsnflke9382938k";
sign = MD5(str2).upper();

By the code above, our final request will contains the parameters below:

app_id:2039dds
product_id: 389238
user_id: 29389
content: newproductmask
environment: test
sign: IDKNFLK392038KDS932K
timestamp: 1593029283
random:289192

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:

{
    code:0
    msg: "success"
    data: {}
} 

4.2 Error Code

Error CodeReason
0success
5090invalid sign
5091timestamp outdated