我尝试在 Woocommerce 中使用其 API 在 javascript(客户端)中创建新产品?
端点:
https://localhost/wpShop/wc-api/v2/products?consumer_key=ck_1111111111122123&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1458225139&oauth_nonce=nVq4rX&consumer_secret=cs_232332322233232&oauth_signature=kzoVx+VYSWlLbRpi3f8222222=
GET
我从 Woocommerce 获得所有产品!完美的!
但是,为什么我不能创建一个新产品?
我的新产品:
var data = {
product: {
title: 'Premium Quality',
type: 'simple',
regular_price: '21.99',
description: 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
short_description: 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.',
categories: [
9,
14
],
images: [
{
src: 'http://www.adpic.de/data/picture/detail/Wasserflasche_74756.jpg',
position: 0
},
{
src: 'http://www.adpic.de/data/picture/detail/Wasserflasche_74756.jpg',
position: 1
}
]
}
};
我的ajaxPOST
请求:
$.ajax({
method: "POST",
url: woocommerceURLcreateProduct,
data: $.param(data)
})
.done(function( msg ) {
console.log( "Data Saved: " );
console.log( msg );
});
我得到错误:
{code: "woocommerce_api_missing_callback_param", message: "Missing Parameter data"}
资源:
http://woothemes.github.io/woocommerce-rest-api-docs/v2.html?javascript#create-a-product