楽天RMS API 商品追加

<?php
define("RMS_SERVICE_SECRET", "SP3xxxxxxxxxxx");
define("RMS_LICENSE_KEY", "SL3xxxxxxxxxxx");
    $authkey = base64_encode(RMS_SERVICE_SECRET . ':' . RMS_LICENSE_KEY);
    $header = array(
        "Authorization: ESA {$authkey}",
        'Content-Type: application/json'
    );
    $url = 'https://api.rms.rakuten.co.jp/es/2.0/items/manage-numbers/mng123';

    $upsert_data = '{
        "itemNumber": "2100011223431",
        "title": "日本語",
        "tagline": "キャッチコピー",
        "productDescription": {
            "pc": "PC用商品説明文",
            "sp": "スマートフォン用商品説明文"
        },
        "salesDescription": "PC販売説明文",
        "precautions": {
            "description": "医薬品説明文",
            "agreement": "医薬品注意事項"
        },
        "images": [
            {
                "type": "CABINET",
                "location": "/myfolder-1/tv01.jpg",
                "alt": "l2_17-Inventory-Test"
            }
        ],
        "whiteBgImage": {
            "type": "CABINET",
            "location": "https://image.books.rakuten.co.jp/harryporter.jpg"
        },
        "tags": [
            5000001,
            5000002
        ],
        "unlimitedInventoryFlag": false,
        "customizationOptions": {
            "displayName": "ギフト目的",
            "inputType": "SINGLE_SELECTION",
            "required": false,
            "selections": {
                "displayValue": "のし必要の方は必ずお選び下さい。"
            }
        },
        "releaseDate": "2021-07-14",
        "purchasablePeriod": {
            "start": "2021-07-11T15:00:00+09:00",
            "end": "2021-07-31T14:59:59+09:00"
        },
        "subscription": {
            "shippingDateFlag": true,
            "shippingIntervalFlag": false
        },
        "features": {
            "searchVisibility": "ALWAYS_VISIBLE",
            "displayNormalCartButton": false,
            "displaySubscriptionCartButton": false,
            "inventoryDisplay": "DISPLAY_ABSOLUTE_STOCK_COUNT",
            "lowStockThreshold": 5,
            "shopContact": false,
            "review": "SHOP_SETTING",
            "displayManufacturerContents": false
        },
        "payment": {
            "taxIncluded": false,
            "taxRate": 0.08,
            "cashOnDeliveryFeeIncluded": false
        },
        "pointCampaign": {
            "applicablePeriod": {
                "start": "2021-10-13T04:07:08+09:00",
                "end": "2021-11-13T04:07:08+09:00"
            },
            "benefits": {
                "pointRate": 6
            },
            "optimization": {
                "maxPointRate": 6
            }
        },
        "itemDisplaySequence": 999999999,
        "layout": {
            "itemLayoutId": 1,
            "navigationId": 0,
            "layoutSequenceId": 0,
            "smallDescriptionId": 0,
            "largeDescriptionId": 0,
            "showcaseId": 0
        },
        "variantSelectors": {
            "key": "size-key",
            "displayName": "サイズ",
            "values": [
                {
                    "displayValue": "L サイズ"
                }
            ]
        },
        "variants": {
            "pinot-noir": {
                "merchantDefinedSkuId": "112233",
                "selectorValues": {
                    "size-key": "Lサイズ"
                },
                "images": [
                    {
                        "type": "CABINET",
                        "location": "/myfolder-1/tv01.jpg",
                        "alt": "l2_17-Inventory-Test"
                    }
                ],
                "restockOnCancel": false,
                "backOrderFlag": false,
                "normalDeliveryDateId": 1,
                "backOrderDeliveryDateId": 2,
                "orderQuantityLimit": 100,
                "referencePrice": {
                    "displayType": "REFERENCE_PRICE ",
                    "type": 1,
                    "value": 1000
                },
                "features": {
                    "restockNotification": true,
                    "noshi": true
                },
                "hidden": false,
                "standardPrice": 1000,
                "articleNumberForSet": [
                    "45000000000",
                    "45000000001"
                ],
                "articleNumber": {
                    "value": "0689640032932",
                    "exemptionReason": "1"
                },
                "shipping": {
                    "fee": 1000,
                    "postageIncluded": false,
                    "shopAreaSoryoPatternId": 1,
                    "shippingMethodGroup": 2,
                    "postageSegment": {
                        "local": 1,
                        "overseas": 1
                    },
                    "overseasDeliveryId": 1,
                    "singleItemShipping": 1
                },
                "asurakuDeliveryId": 2,
                "specs": {
                    "label": "スペック情報ラベル",
                    "value": "スペック情報内容"
                },
                "attributes": {
                    "name": "attribute name",
                    "values": [
                        "赤色",
                        "100"
                    ]
                }
            }
        },
        "itemType": "CUSTOMIZABLE_SET",
        "genreId": "555555"
    }';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); // メソッド指定
    curl_setopt($ch, CURLOPT_TIMEOUT,        30);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //返り値を 文字列で返します
    curl_setopt($ch, CURLOPT_POSTFIELDS, $upsert_data); //返り値を 文字列で返します

    $response = curl_exec($ch);
    if(curl_error($ch)){
        $response = curl_error($ch);
    }

    $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    $response1 = json_decode( $response, true );

    curl_close($ch);
    var_dump("create result", $response1);
?>

いいなと思ったら応援しよう!