I have tried 2 types of ajax calls to post json data so that i can order an item using woocommerce API. I am using OAuth1.0a to authorize the user. Its getting the data but not able to post the data. But none of them worked for me. So please somebody say how to post json data using ajax call. Thanks in advance.
var oauth2 = OAuth({
consumer: {
public: 'key',
secret: 'secret'
},
signature_method: 'HMAC-SHA1'
});
var token = {
public: 'key',
secret: 'secret'
};
var dataToSend = {};
var request_data = {
url: 'http://www.example.com/wc-api/v3/orders',
method: 'POST',
data: dataToSend
};
return $.ajax({
url: request_data.url,
type: request_data.method,
data: oauth2.authorize(request_data, token)
});
return $.ajax({
url: request_data.url,
type: request_data.method,
'content-type': 'application/json',
body: request_data.data,
headers: oauth2.toHeader(oauth2.authorize(request_data, token))
});
key is genetrated using below link : https://docs.woothemes.com/document/woocommerce-rest-api/