2016-04-05 15 views
0

Magentoバージョン2.0用のRest APIを使用して製品を作成しようとしています。Rest APIを使用して製品を作成する:Magento V2.0

私はPostmanを使用して残りのAPIをテストしています。

URL:http://13.91/rest/V1/products

リクエストに次のヘッダーを追加しました。 許可:ベアラ********************** コンテンツタイプ:アプリケーション/ JSON

JSON本体

{ 
"sku":"10090-White-XL", 
"store_view_code":"", 
"attribute_set_code":"ColorSize", 
"product_type":"virtual", 
"categories":"Menswear/Tops", 
"product_websites":"base", 
"name":"10090-White-XL", 
"description":"<p>Precise Long-Sleeve Shirt in Black, Denim, or White.</p>", 
"short_description":"", 
"weight":"", 
"product_online":1, 
"tax_class_name":"Taxable Goods", 
"visibility":"Not Visible Individually", 
"price":119, 
"special_price":"", 
"special_price_from_date":"", 
"special_price_to_date":"", 
"url_key":"10090-white-xl", 
"meta_title":"Precise Long-Sleeve Shirt", 
"meta_keywords":"Precise Long-Sleeve Shirt", 
"meta_description":"Precise Long-Sleeve Shirt <p>Precise Long-Sleeve Shirt in Black, Denim, or White.</p>", 
"base_image":"", 
"base_image_label":"", 
"small_image":"", 
"small_image_label":"", 
"thumbnail_image":"", 
"thumbnail_image_label":"", 
"swatch_image":"", 
"swatch_image_label":"", 
"created_at":"3/23/16, 2:15 PM", 
"updated_at":"3/23/16, 2:15 PM", 
"new_from_date":"", 
"new_to_date":"", 
"display_product_options_in":"Block after Info Column", 
"map_price":"", 
"msrp_price":"", 
"map_enabled":"", 
"gift_message_available":"", 
"custom_design":"", 
"custom_design_from":"", 
"custom_design_to":"", 
"custom_layout_update":"", 
"page_layout":"", 
"product_options_container":"", 
"msrp_display_actual_price_type":"", 
"country_of_manufacture":"", 
"additional_attributes":"color=White,size=XL", 
"qty":null, 
"out_of_stock_qty":0, 
"use_config_min_qty":1, 
"is_qty_decimal":0, 
"allow_backorders":0, 
"use_config_backorders":1, 
"min_cart_qty":1, 
"use_config_min_sale_qty":1, 
"max_cart_qty":10000, 
"use_config_max_sale_qty":1, 
"is_in_stock":0, 
"notify_on_stock_below":1, 
"use_config_notify_stock_qty":1, 
"manage_stock":0, 
"use_config_manage_stock":0, 
"use_config_qty_increments":1, 
"qty_increments":0, 
"use_config_enable_qty_inc":0, 
"enable_qty_increments":0, 
"is_decimal_divided":0, 
"website_id":1, 
"related_skus":"", 
"crosssell_skus":"", 
"upsell_skus":"", 
"additional_images":"", 
"additional_image_labels":"", 
"hide_from_product_page":"", 
"bundle_price_type":"", 
"bundle_sku_type":"", 
"bundle_price_view":"", 
"bundle_weight_type":"", 
"bundle_values":"", 
"configurable_variations":"", 
"configurable_variation_labels":"", 
"associated_skus":"" 

}

私が得るエラーは{"message":"%fieldName is a required field.","parameters":{"fieldName":"product"}}

です。誰かが私にどのように製品を追加できるか教えていただけたら嬉しいです。私はすべての文書をチェックしましたが、答えを見つけることができませんでした。

答えて

2

私は私の質問に対する答えを見つけました。 JSON構造この形式である必要があります。

{ 
"product":{ 
    "id": 12345, 
    "sku": "10090-White-XL", 
    "name": "10090-White-XL", 
    "attribute_set_id": 9, 
    "price": 119, 
    "status": 1, 
    "visibility": 1, 
    "type_id": "virtual", 
    "created_at": "2016-04-05 23:04:09", 
    "updated_at": "2016-04-05 23:04:09", 
    "product_links": [], 
    "options": [], 
    "tier_prices": [], 
    "custom_attributes": [ 
    { 
     "attribute_code": "description", 
     "value": "<p>Precise Long-Sleeve Shirt in Black, Denim, or White.</p>" 
    }, 
    { 
     "attribute_code": "meta_title", 
     "value": "Precise Long-Sleeve Shirt" 
    }, 
    { 
     "attribute_code": "meta_keyword", 
     "value": "Precise Long-Sleeve Shirt" 
    }, 
    { 
     "attribute_code": "meta_description", 
     "value": "Precise Long-Sleeve Shirt <p>Precise Long-Sleeve Shirt in Black, Denim, or White.</p>" 
    }, 
    { 
     "attribute_code": "color", 
     "value": "11" 
    }, 
    { 
     "attribute_code": "options_container", 
     "value": "container2" 
    }, 
    { 
     "attribute_code": "required_options", 
     "value": "0" 
    }, 
    { 
     "attribute_code": "has_options", 
     "value": "0" 
    }, 
    { 
     "attribute_code": "url_key", 
     "value": "10090-white-xl" 
    }, 
    { 
     "attribute_code": "msrp_display_actual_price_type", 
     "value": "0" 
    }, 
    { 
     "attribute_code": "tax_class_id", 
     "value": "2" 
    }, 
    { 
     "attribute_code": "size", 
     "value": "8" 
    } 
    ] 

}、 「saveOptions」:真 }

注意すべき重要なことはidenityにjson.The闊歩ドキュメントヘルプの製品タグですそれ。ここにリンクがあります:http://devdocs.magento.com/swagger/#!/catalogProductRepositoryV1/catalogProductRepositoryV1SavePost

1

カスタム属性を持つシンプルな商品(例:備考)。

media_gallery_entriesに注意してください。有効なbase64_encoded_dataイメージのコンテンツとMIMEタイプを指定してください。

URL:http://domain/index.php/rest/V1/products

METHOD:POST

HEADER: アプリケーション/ JSON 認証:ベアラ

POST DATA/RAWペイロード:

{ 
 
    "product": { 
 
\t "sku": "TESTPRD002", 
 
\t "name": "Women's Running - Pure Boost X Shoes", 
 
\t "attribute_set_id": 4, 
 
\t "price": 84, 
 
\t "status": 1, 
 
\t "visibility": 4, 
 
\t "type_id": "simple", 
 
\t "created_at": "2016-12-16 15:20:55", 
 
\t "updated_at": "2016-12-16 15:20:23", 
 
\t "weight": 2.5, 
 
\t "extension_attributes": { 
 
\t \t "stock_item": { 
 
\t \t "item_id": 1, 
 
\t \t "stock_id": 1, 
 
\t \t "qty": 20, 
 
\t \t "is_in_stock": true, 
 
\t \t "is_qty_decimal": false 
 
\t \t } 
 
\t }, 
 
\t "product_links": [], 
 
\t "options": [], 
 
\t "media_gallery_entries": [ 
 
\t \t { 
 
\t \t "media_type": "image", 
 
\t \t "label": "Women's Running - Pure Boost X Shoes", 
 
\t \t "position": 1, 
 
\t \t "disabled": false, 
 
\t \t "types": [ 
 
\t \t \t "image", 
 
\t \t \t "small_image", 
 
\t \t \t "thumbnail" 
 
\t \t ], 
 
\t \t "content": { 
 
\t \t \t "base64_encoded_data": "<ENCODED IMAGE DATA>", 
 
\t \t \t "type": "image/jpeg", 
 
\t \t \t "name": "TESTPRD002-01.jpg" 
 
\t \t \t } 
 
\t \t } 
 
\t ], 
 
\t "tier_prices": [], 
 
\t "custom_attributes": [ 
 
\t \t { 
 
\t \t "attribute_code": "description", 
 
\t \t "value": "<p>Lightweight and sleek, these women's running shoes are fueled by boost™ energy. The low-profile runners blend an energy-returning boost™ midsole with a STRETCHWEB outsole for a cushioned ride with terrific ground-feel. They feature a breathable mesh upper with a sock-like fit that offers all-around support. With a full boost™ midsole that keeps every stride charged with light, fast energy, the shoe has an upper that hovers over a free-floating arch.</p>" 
 
\t \t }, 
 
\t \t { 
 
\t \t "attribute_code": "short_description", 
 
\t \t "value": "<p>PURE BOOST X SHOES</p><p>NATURAL RUNNING SHOES WITH ARCH SUPPORT.</p>" 
 
\t \t }, 
 
\t \t { 
 
\t \t "attribute_code": "meta_title", 
 
\t \t "value": "PURE BOOST X SHOES" 
 
\t \t }, 
 
\t \t { 
 
\t \t "attribute_code": "meta_keyword", 
 
\t \t "value": "boost X, running, shoes, adidas" 
 
\t \t }, 
 
\t \t { 
 
\t \t "attribute_code": "meta_description", 
 
\t \t "value": "NATURAL RUNNING SHOES WITH ARCH SUPPORT." 
 
\t \t }, 
 
\t \t { 
 
\t \t "attribute_code": "category_ids", 
 
\t \t "value": [ 
 
\t \t \t "2", "3" 
 
\t \t ] 
 
\t \t }, 
 
\t \t { 
 
\t \t "attribute_code": "url_key", 
 
\t \t "value": "womens-running-pure-boost-x-shoes" 
 
\t \t }, 
 
\t \t { 
 
\t \t "attribute_code": "tax_class_id", 
 
\t \t "value": "1" 
 
\t \t }, 
 
\t \t { 
 
\t \t "attribute_code": "remarks", 
 
\t \t "value": "Lorem ipsum.." 
 
\t \t } 
 
\t ] 
 
    }, 
 
    "saveOptions": true 
 
}

関連する問題