Yotpo API POST
<mvt:comment> Yotpo </mvt:comment>
<!-- Yotpo -->
http://blog.merchant.local/?p=2995
<!– Yotpo –>
<script>
$(document).ready(function () {
var credUrl = 'https://api.yotpo.com/oauth/token',
creds = {
"client_id": "ej5GZPZcQfXvXaI3fHCxHl3k9NnIz0Lqh2Idf19k",
"client_secret": "M5ltFLv9j6FXiYsZqDXZV0qD5T9GZlcnDRfbrPYp",
"grant_type": "client_credentials"
},
accessToken = '';
console.log(accessToken);
$.ajax({
url: credUrl,
type: 'POST',
contentType:'application/json',
data: JSON.stringify(creds),
dataType:'json',
success: function(data){
}
}).done(function (data) {
accessToken = data.access_token;
console.log(accessToken);
d = new Date();
var data = {
"validate_data": false,
"platform": "general",
"utoken": accessToken,
"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>
"&mvt:item:code;": {
"url": "&mvt:seo_settings:urlprefix;p/&mvta:item:name;/&mvta:item:code;",
"name": "&mvt:item:name;",
"image": "&mvt:global:domain:base_url;&mvt:item:customfield_values:productimagecustomfields:default;",
"price": '&mvt:item:price;'
}
</mvt:foreach>
}
};
$.ajax({
url: 'https://api.yotpo.com/apps/ej5GZPZcQfXvXaI3fHCxHl3k9NnIz0Lqh2Idf19k/purchases',
type: 'POST',
contentType:'application/json',
data: JSON.stringify(data),
dataType:'json',
success: function(data){
}
});
});
});
</script>