是否可以在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=
javascript请求:
$.ajax({
method: "GET",
url: woocommerceURLProduct,
data: ""
})
.done(function( msg ) {
console.log( "products: " );
console.log( msg );
});
这很有效!但我无法将此用于创建新产品。
相同端点:
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=
我的新产品:
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
}
]
}
};
我的ajax请求:
$.ajax({
method: "POST",
url: woocommerceURLcreateProduct,
data: $.param(data)
})
.done(function( msg ) {
console.log( "Data Saved: " );
console.log( msg );
});
I get the error: {code: "woocommerce_api_missing_callback_param", message: "Missing Parameter data"}
资料来源:
http://woothemes.github.io/woocommerce-rest-api-docs/v2.html?javascript#create-a-product