Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
#816218
Hi team

i need to call the external application REST API through the using token.
in my process marker application, i need to get it done through the java-script (by using button click). Because i want to show the return parameters form API on Dynaform fields.

please can some one help me . if you can attach the java-script code , that is good

i used following code but not working
Code: Select all
function getDetails() {
   var req = new XMLHttpRequest();
   var sUrl ="api http link with parameeters";
   var sTkn ="getTokenExtenalApp";  
  
   req.open("GET", sUrl , true);
   req.setRequestHeader("Authorization", "Bearer " + sTkn); 
   
   alert("Error status code: " + req.setRequestHeader);
  
   req.onreadystatechange = function() {
     alert ("working");
     if (req.readyState==4) {
        if (req.status==200) {        
           var aShowRetuen = JSON.parse(req.responseText);
           alert(aShowRetuen);       
        }
        else {
           alert("Error status code: " + req.status);
        }
  // }
   req.send(null);
  }
}
#816227
You need to uncomment your \\ } because otherwise you don't have matching curly braces.
Your req.send() needs to be outside the req.onreadystatechange event handler.
You need to set a valid URL and access token in your sUrl and sTkn variables.

Try it this way:
Code: Select all
function getDetails() {
   var req = new XMLHttpRequest();
   var sUrl ="api http link with parameeters";
   var sTkn ="getTokenExtenalApp";  
  
   req.open("GET", sUrl , true);
   req.setRequestHeader("Authorization", "Bearer " + sTkn); 
   
   alert("Error status code: " + req.setRequestHeader);
  
   req.onreadystatechange = function() {
     alert ("working");
     if (req.readyState==4) {
        if (req.status==200) {        
           var aShowRetuen = JSON.parse(req.responseText);
           alert(aShowRetuen);       
        }
        else {
           alert("Error status code: " + req.status);
        }
     }    
   }
   
   req.send(null);
}
#816262
Dear amosbatto and team

i tried to fix this issue number of time by changing java-script code and the REST API link and token.
but every time the req.status is give '0' to out

(please note : the relevant rest API's are executed without any errors through 'POSTMAN' correctly)

our REST api links are executed as HTTPS links. please let me know whether 'var req = new XMLHttpRequest();' is working for https links?

thx

A 1xbet clone script is a pre-designed software so[…]

4rabet clone script is enabling entrepreneurs to e[…]

Parimatch clone script is enabling entrepreneurs t[…]

In the world of cryptocurrency, a wallet is an app[…]