Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to call an external API from Js policy ?

Not applicable

Hi, I'm a beginner in APIGEE. I need your suggestions to make an external API/webservice from a Js policy that I have created. Please help me on this.

I have created a conditional flow and retried its result in its attached JS Policy.From this JS I need to call another API call.Following is my code.

var responseData = JSON.parse(response);
if (responseData.Event.Resource.Id) {
    downloadDataId = responseData.Event.Resource.Id;
    context.setVariable('downloadDataId', downloadDataId);
    var authHeader = context.getVariable('shareFiles.auth_token');
    authHeader = 'Bearer ' + authHeader;
    var url = 'https://my-download-url/Items(' + downloadDataId + ')/Download';
    var headers = {
        'Content-Type': 'application/json',
        'Authorization': authHeader
    };
    var myRequest = new Request(url,"GET",headers);
    try {
        var exchange = httpClient.send(myRequest);
        context.session['exchange'] = exchange;
        var exchange = context.session['exchange'];
        exchange.waitForComplete(1000);
        print(JSON.parse(exchange));
    }
    catch(err) {
        print(err.message);
    }
} else {
    context.setVariable('downloadDataId', '');
}

Following is my response

7250-apigee.png

Please suggest me the right method for solving this issue.

0 5 2,071
5 REPLIES 5