FW

Hi I found a way to use http requests in ARIS script, this solution uses JAVA methods but it works fine with our ARIS setup. The code below is a GET request.

function httpRequest(url){
    var obj = new java.net.URL(url);
    var con = obj.openConnection();
    
    con.setRequestMethod("GET");
    con.setRequestProperty("User-Agent", java.net.USER_AGENT);
    
    var responseCode = con.getResponseCode();
    var iN = new java.io.BufferedReader(new java.io.InputStreamReader(con.getInputStream()));
    var inputLine = new java.lang.String();
    var response = new java.lang.StringBuffer();
    while((inputLine = iN.readLine()) != null){
        response.append(inputLine);
    }
    iN.close();
    return new java.lang.String(response);
}

This method returns a String with the response body (html code). You can later parse the response and use in your own script.

You can also use authorization if you need by adding this lines to the method.

var encoding = new java.lang.String(org.apache.commons.codec.binary.Base64().encodeBase64(userpass.getBytes()));
con.setRequestProperty("Authorization", "Basic " + encoding);

Note: The user and password (userpass variable) needs to be in the format username:password for basic authorization.

If you tries to connect to a webserver that don't exists or gives no response you need to use try catch statement to prevent script errors.

try{
    // statments that can cause errors like
    // con.getResponseCode(), con.getInputStream()))...
}

catch(e){
    // handle error
}
by Frank Weyand
Posted on Wed, 08/12/2015 - 08:41

Hi Fredrik,

thank you very much for this posting. These examples are an important contribution to the ARIS community!

Bye,

Frank

0
by FLAVIO DE FARIA
Posted on Fri, 02/02/2018 - 15:32

Hi,

I am getting Http response code 401 in ADS Rest API using the code above . I supose to be authorization issue.

I really appreciate any help on this.

Thanks,

Flavio

 

0
by Runé Becker
Badge for 'Mastermind' achievement
Posted on Fri, 02/02/2018 - 22:17

In reply to by flavio.faria

Yes, ARIS RESTful API first needs a token provided by ARIS Server after a login:

http://localhost/apidocs/swagger-ui/index.html?url=/umc/apidocs/swagger.json#!/tokens/login

But the above article is about the ARIS Script API which is completely different from ARIS Document Storage API.

While the ARIS ADS (RESTful) API is an meant for EXTERNAL access/outside ARIS, the ARIS Script API is used by report scripts running INSIDE an ARIS Server.

Cheers

Rune

0
by Alokin Iksok
Posted on Wed, 04/11/2018 - 10:22

Hi,

When I'm using this method I get an error(Connection refused: connect) on the line: 

var responseCode = con.getResponseCode();

Do you know what might be?

Thank you!

0

Featured achievement

Rookie
Say hello to the ARIS Community! Personalize your community experience by following forums or tags, liking a post or uploading a profile picture.
Recent Unlocks

Leaderboard

|
icon-arrow-down icon-arrow-cerulean-left icon-arrow-cerulean-right icon-arrow-down icon-arrow-left icon-arrow-right icon-arrow icon-back icon-close icon-comments icon-correct-answer icon-tick icon-download icon-facebook icon-flag icon-google-plus icon-hamburger icon-in icon-info icon-instagram icon-login-true icon-login icon-mail-notification icon-mail icon-mortarboard icon-newsletter icon-notification icon-pinterest icon-plus icon-rss icon-search icon-share icon-shield icon-snapchat icon-star icon-tutorials icon-twitter icon-universities icon-videos icon-views icon-whatsapp icon-xing icon-youtube icon-jobs icon-heart icon-heart2 aris-express bpm-glossary help-intro help-design Process_Mining_Icon help-publishing help-administration help-dashboarding help-archive help-risk icon-knowledge icon-question icon-events icon-message icon-more icon-pencil forum-icon icon-lock