JavaScript Requires Chilkat v11.0.0+
JavaScript
PayPal: Find disputes awaiting a seller response
See more PayPal Examples
Scan cases updated in the past 30 days and page through the results. Show each case waiting on the seller and its response deadline when PayPal includes one in the summary.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat
v11.4.0 or greater.
var success = false;
// See Unlock Chilkat before making requests.
// For the merchant's internal backoffice application. Load the sandbox token
// from the merchant's credential store. Keep it out of publicly distributed apps.
// See Get a PayPal access token.
var http = new CkHttp();
http.AuthToken = "SANDBOX_ACCESS_TOKEN";
var resp = new CkHttpResponse();
var since = new CkDateTime();
since.SetFromCurrentSystemTime();
since.AddDays(-30);
var query = new CkJsonObject();
query.UpdateString("update_time_after",since.GetAsTimestamp(false));
query.UpdateInt("page_size",50);
var page = 1;
var more = true;
while ((more == true)) {
query.UpdateInt("page",page);
success = http.HttpParams("GET","https://api-m.sandbox.paypal.com/v1/customer/disputes",query,resp);
if (success !== true) {
console.log("No HTTP response: " + http.LastErrorText);
return;
}
if ((resp.StatusCode < 200) || (resp.StatusCode >= 300)) {
var errorInfo = new CkJsonObject();
errorInfo.Load(resp.BodyStr);
console.log("HTTP " + resp.StatusCode + " " + errorInfo.StringOf("name") + " " + errorInfo.StringOf("details[0].issue"));
console.log("PayPal debug ID: " + errorInfo.StringOf("debug_id"));
return;
}
var result = new CkJsonObject();
var parsedResult = result.Load(resp.BodyStr);
if (parsedResult !== true) {
console.log("Expected a JSON response; HTTP " + resp.StatusCode);
return;
}
var i = 0;
while ((i < result.SizeOfArray("items"))) {
result.I = i;
if (result.StringOfEquals("items[i].status","WAITING_FOR_SELLER_RESPONSE",true) == true) {
console.log(result.StringOf("items[i].dispute_id") + " " + result.StringOf("items[i].reason"));
if (result.HasMember("items[i].seller_response_due_date") == true) {
console.log("Respond by " + result.StringOf("items[i].seller_response_due_date"));
}
}
i = i+1;
}
var hasNext = false;
var linkIndex = 0;
while ((linkIndex < result.SizeOfArray("links"))) {
result.I = linkIndex;
if (result.StringOfEquals("links[i].rel","next",true) == true) {
hasNext = true;
}
linkIndex = linkIndex+1;
}
more = hasNext;
page = page+1;
}