# Webhook Mechanism

# Introduction

Product details including addition, deletion & modification of variants.

# Setup Procedure

  • 1)Set up message monitoring and reference.webhook
  • 2)Set up client monitoring interface, example as below(Java).
  • 3)Test monitoring.

# Message

# Product Message

# Inbound message for Product

{
    "messageId": "ca72a4834cd14b9588e88ce206f614a0",
    "type": "PRODUCT",
    "params": {
        "categoryId": null,
        "categoryName": null,
        "pid": "1424608189734850560",
        "productDescription": "xxxxxx",
        "productImage": null,
        "productName": null,
        "productNameEn": null,
        "productProperty1": null,
        "productProperty2": null,
        "productProperty3": null,
        "productSellPrice": null,
        "productSku": null,
        "productStatus": null,
        "fields" : [
            "productDescription"
        ],
    }
}
Parameter Definition Type Required Length Note
messageId Message Id string Y 200 Message Id
type Message type string Y 200 PRODUCT,VARIANT
params object Y 5
categoryId category Id string Y 200
categoryName category Name string Y 200
pid product id string Y 200
productDescription product description string Y 2000
productImage product image string Y 200
productName product name string Y 200
productNameEn product name(english) string Y 200
productProperty1 product property string Y 200
productProperty2 product property string Y 200
productProperty3 product property string Y 200
productSellPrice product sell price double Y 20
productSku product sku string Y 200
productStatus product status int Y 5 status:3-online, 1-offline, 0-delete,4-all delete
fields fields list list Y 5

# Inbound message for Variant

{
    "messageId": "7cceede817dc47ed9748328b64353c5c",
    "type": "VARIANT",
    "params": {
        "vid": "1424608152007086080",
        "variantName": null,
        "variantWeight": null,
        "variantLength": null,
        "variantWidth": null,
        "variantHeight": null,
        "variantImage": null,
        "variantSku": null,
        "variantKey": null,
        "variantSellPrice": null,
        "variantStatus": null,
        "variantValue1": null,
        "variantValue2": null,
        "variantValue3": null,
        "fields" : [
            "variantLength"
        ],
    }
}
Parameter Definition Type Required Length Note
messageId Message id string Y 200 Message Id
type Message type string Y 200 PRODUCT,VARIANT
params object Y 5
vid variant Id string Y 200
variantName variant name string Y 200
variantWeight variant weight int Y 200
variantLength variant length int Y 2000
variantWidth variant width int Y 200
variantHeight variant height int Y 200
variantImage variant name(english) string Y 200
variantSku variant sku string Y 200
variantKey variant key string Y 200
variantSellPrice variant sell price double Y 200
variantStatus variant status int Y 5 status:1-online, 2-offline, 3-delete,4-all delete
variantValue1 variant value1 string Y 200
variantValue2 variant value2 string Y 200
variantValue3 variant value3 string Y 200
fields fields list list Y 5

# Stock Message

{
    "messageId": "ca72a4834cd14b9588e88ce206f614a0",
    "type": "STOCK",
    "params": {
        "1424608152007086080": [
            {
                "vid": "1424608152007086080",
                "areaId": "2",
                "areaEn": "US Warehouse",
                "countryCode": "US",
                "storageNum": 12
            }
        ],
        "AE7DB9BC-4290-4C85-B8A6-F8957F3DB053": [
            {
                "vid": "AE7DB9BC-4290-4C85-B8A6-F8957F3DB053",
                "areaId": "2",
                "areaEn": "US Warehouse",
                "countryCode": "US",
                "storageNum": 1
            }
        ]
    }
}

# Listening example

# Example

package com.linkus.cn.controller;

import com.alibaba.fastjson.JSON;
import com.linkus.cn.constant.callback.domain.CallbackParams;
import com.linkus.cn.util.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Linkus Webhook Listening Example
 *
 * @author : kay
 */
@RestController
@RequestMapping("/webhookListener")
@Slf4j
public class TestController {

    @PostMapping("/productMessage")
    public Result productMessage(@RequestBody @Validated CallbackParams query) {
        log.info("product message:{}", JSON.toJSONString(query));
        return Result.success(Boolean.TRUE);
    }
}
package com.linkus.cn.constant.callback.domain;

import lombok.Data;

/**
 * @author : kay
 */
@Data
public class CallbackParams {
    private String messageId;
    private String type;
    private Object params;
}
package com.linkus.cn.constant.callback.domain;

import lombok.Getter;
import org.springframework.util.StringUtils;

/**
 * @author : kay
 */
@Getter
public enum CallbackBusinessTypeEnum {
    PRODUCT,
    VARIANT,
    STOCK;

    public static CallbackBusinessTypeEnum create(String name) {
        if (!StringUtils.isEmpty(name)) {
            for (CallbackBusinessTypeEnum typeEnum: CallbackBusinessTypeEnum.values()) {
                if (typeEnum.name().equals(name.toUpperCase())) {
                    return typeEnum;
                }
            }
        }
        return null;
    }
}