REST Callout from Salesforce Flow

PHOTO EMBED

Fri Jul 30 2021 20:25:46 GMT+0000 (Coordinated Universal Time)

Saved by @redflashcode

 ({
     invoke : function(component, event, helper) {
         var cancelToken = event.getParam("arguments").cancelToken;
         return new Promise(function(resolve, reject) {
             var xhttp = new XMLHttpRequest();
             xhttp.onreadystatechange = $A.getCallback(function() {
                 if (this.readyState === 4) { // DONE
                     if (this.status >= 200 && this.status < 300) {
                         var response = JSON.parse(xhttp.responseText);
                         component.set("v.churnVal", response);
                         resolve();
                     } else {
                         var errorText = "";
                         if (this.status === 0) {
                             errorText = 'Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.';
                         } else {
                             errorText = this.statusText;
                         }
                         reject(errorText);
                     }
                 }
             });
             var customerId = component.get("v.customerId");
             xhttp.open("GET", "https://upp57qbj5b.execute-api.us-west-1.amazonaws.com/production/customer/"+customerId+"/churn", true);
             xhttp.send(null);
             cancelToken.promise.then(function(error) {
                 xhttp.abort();
                 reject(error);
             });
         });
     }
})
content_copyCOPY