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"
}