-
Notifications
You must be signed in to change notification settings - Fork 0
/
jQuery_ServiceReviewAPIs_Basics.html
93 lines (71 loc) · 3.62 KB
/
jQuery_ServiceReviewAPIs_Basics.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<html>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script>
var bizUnitID = 'xxx'; //Your Business unit ID at Trustpilot
var apiKey = 'xxx'; // Your Trustpilot API Key Here
//var reqURL = "https://api.trustpilot.com/v1/business-units/"+bizUnitID;
var reqURL = "https://api.trustpilot.com/v1/business-units/"+bizUnitID+"/reviews";
//WE BEGIN WITH ABOVE THREE VARIABLES
//CASE-1: VALID BIZ UNIT WITH REVIEWS & TRUST SCORE AVAILABLE
$.ajax({url: reqURL+"?apikey="+apiKey+"&token="+token,
dataType: "json",
success: function(json) {
//console.log("CASE-1: Trust Score: " + json.trustScore);
//console.log("CASE-1: Number of Reviews: " + json.numberOfReviews.total);
//console.log("CASE-1: Overall Response Received: " + JSON.stringify(json));
$.each(json, function(key, value) {
console.log("SUCCESS");
console.log("CASE-0:: "+key +" : "+ value);
});
}, error : function(json) {
console.log("CASE-1 ERROR: ######### " + json.responseText);
$.each(json, function(key, value) {
console.log("FAILURE");
console.log("CASE-0:: "+key +" : "+ value);
});
}
});
//CASE-2: VALID BIZ UNIT WITH NO REVIEWS & TRUST SCORE AVAILABLE --> IT WILL RETURN TRUST SCORE of 7
bizUnitID = "xxx";
reqURL = "https://api.trustpilot.com/v1/business-units/"+bizUnitID;
$.ajax({url: reqURL+"?apikey="+apiKey,
dataType: "json",
success: function(json) {
console.log("CASE-2: Trust Score: " + json.trustScore);
console.log("CASE-2: Number of Reviews: " + json.numberOfReviews.total);
// If Trust Score 7 & Number of Reviews ZERO, you know now ;-)
//console.log("CASE-2: Overall Response Received: " + JSON.stringify(json));
$.each(json, function(key, value) {
//console.log(key +" : "+ value);
});
}, error : function(json) {
console.log("CASE-2 ERROR: ######### " + json.responseText);
$.each(json, function(key, value) {
//console.log("CASE-2:: "+key +" : "+ value);
});
}
});
//CASE-3: INVALID BIZ UNIT WITH OF COURSE NO REVIEWS & TRUST SCORE EXISTING, BUT VALID API KEY!
bizUnitID = "xxx";
reqURL = "https://api.trustpilot.com/v1/business-units/"+bizUnitID;
$.ajax({url: reqURL+"?apikey="+apiKey,
dataType: "json",
success: function(json) {
//console.log("Trust Score: " + json.trustScore);
//console.log("Number of Reviews: " + json.numberOfReviews);
// If Trust Score 7 & Number of Reviews ZERO, you know now ;-)
console.log("CASE-3: Overall Response Received: " + JSON.stringify(json));
$.each(json, function(key, value) {
console.log(key +" : "+ value);
});
}, error : function(json) {
console.log("CASE-3 ERROR: ######### " + JSON.parse(json.responseText).message);
$.each(json, function(key, value) {
//console.log("CASE-3:: "+key +" : "+ value);
});
}
});
</script>
</body>
</html>