Yotpo API for Orders
<script>
$(document).ready(function () {
var credUrl = 'https://api.yotpo.com/oauth/token',
creds = {
"client_id": "APP_KEY",
"client_secret": "APP_SECRET",
"grant_type": "client_credentials"
},
accessToken = '';
$.ajax({
url: credUrl,
type: 'POST',
contentType:'application/json',
data: JSON.stringify(creds),
dataType:'json',
success: function(data){
console.log('Success');
}
}).done(function (data) {
accessToken = data.access_token;
d = new Date();
var data = {
"platform": "general",
"validate_data": false,
"utoken": accessToken,
"orders": {
"email": "&mvt:order:bill_email;",
"customer_name": "&mvt:order:bill_fname;",
"order_id": "&mvt:item:order_id;",
"currency_iso": "USD",
"user_reference": "&mvt:order:cust_id;",
"order_date": d.getDate() + "-" + (d.getMonth()+1) + "-" + d.getFullYear()
},
"products": {
<mvt:assign name="pcounter" value="0" />
<mvt:foreach iterator="item" array="order:items">
<mvt:assign name="pcounter" value="g.pcounter + 1 "/>
<mvt:if expr="g.pcounter GT 1">
,
</mvt:if>
"product_sku": {
"name": "&mvt:item:name;",
"url": "http://www.outdoorsforless.com/p/&mvta:item:code;/&mvta:item:name;.html",
"image": "http://www.outdoorsforless.com/mm5/&mvte:item:imagetypes:main;",
"price": '&mvt:item:price;'
}
</mvt:foreach>
}
};
$.ajax({
url: 'https://api.yotpo.com/apps/n0H9hhMlJ3UHwHrPj7mxZqIHa4gq3kO6m6prKqAY/purchases/mass_create.json',
type: 'POST',
contentType:'application/json',
data: JSON.stringify(data),
dataType:'json',
success: function(data){
//On ajax success do this
console.log(data);
}
});
});
});
</script>