Highlighted

Call JSON url and get data in AEM through INDS script [Extendscript]

annaduraim74336

30-10-2019

Hi All,

I need to call .json URL link through extend script to do some backend functionality in InDesign server. Is it possible to get JSON data through Javascript?

I tried some code. But this does not return any data.

var host = "http://localhost:4502/bin/querybuilder.json?p.limit=-1&type=dam%3aAsset";

var jsonData = getData(host);

function getData(host) {

    var aemConn = new Socket, body = "", response, firstRead = true;

aemConn.timeout = 60;

    if (!aemConn.open(host, "UTF-8")) {

        return;

    }

    while( response = aemConn.read() ){

        response = response.toString();

        if(!firstRead){

            body = body + response;

            continue;

        }

        var strings = response.split("\n");

        for(var x = 0; x < strings.length; x++){

            if( (x == 0) && (strings[x].indexOf("200") === -1)){

                return body;

            }

            if(x === (strings.length - 1)){

                body = body + strings[x];

            }

        }

        firstRead = false;

    }

    return body;

}

Please give me any helps!

Thanks.