不幸的是,这是一个非常模糊的问题,所以如果有人能指出如何解决问题或帮助我找到它,我会很高兴。
第一个json请求到usertoken的目的,最后,当utoken到达时,用于主json提交并向API提交发布请求。但是,由于一些奇怪的原因,它拒绝发送。
此代码插入到感谢页面上,每个用户都直接在那里,一旦窗口加载就应该提交。但是,那些负责API的人士表示,即使提交了300多份订单,也没有提出任何要求。
JQUERY
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
var myDate = "30/01/2014"; //order date - dynamic element
var n=myDate.split("/"); //split the date into correct format
var fdate = (n[2]+"-"+n[1]+"-"+n[0] );
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://api.yotpo.com/oauth/token');
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
if (this.readyState == 4) {
if (typeof cb !== "undefined") {
cb(this);
}
else {
var response = JSON.parse(this.responseText)
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://api.yotpo.com/apps/ID/purchases');
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send("{\n \"utoken\": \"" + response.access_token + "\",\n \"email\": \"email@email.com\",\n \"customer_name\": \"Customer Name\",\n \"order_id\": \"112897\",\n \"platform\": \"general\",\n \"order_date\": \"" + fdate + "\",\n \"currency_iso\": \"GBP\",\n \"products\":{\n \"CODE\": {\n \"url\": \"URL\",\n \"name\": \"TechTalk Leicester\",\n \"image\": \"image.jpg\",\n \"description\": \"this is the description of a product\",\n \"price\": \"100\"\n } }\n}");
}
}
};
xhr.send("{\n \"client_id\": \"CLIENTID\",\n \"client_secret\": \"CLIENT SECRET\",\n \"grant_type\": \"client_credentials\"\n
});//]]>
</script>