javascriptxmlhttprequestwso2wso2-api-managermediator

How to send http request in "script mediator" javascript language in WSO2 APIM?


I tried "fetch", "XMLHttpRequest", "jquery" functions to send http request in script inline mediator wso2 publisher. but in logs wso2 says "XMLHttpRequest" not defined and for jquery "$ not defined" and for "fetch" syntax error" Is there any way to send http request in script mediator of wso2 apim? this is jquey error.

[2022-08-25 15:53:25,508] ERROR - ScriptMediator {api:run:v1} The script engine returned an 
error executing the inlined js script function mediate
com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.EcmaError: 
ReferenceError: "$" is not defined. (<Unknown Source>#5) in <Unknown Source> at line number 5

my mediator:

<script language="js" source="https://code.jquery.com/jquery-1.7.1.min.js">
<![CDATA[
print("before sent########################################");

$.get("http://run.mocky.io/v2/5185415ba171ea3a00704eed", function(data, status){
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");

print("Data: DDDDDDDDDDDDDDDDD" + data + "\nStatus: " + status);
});

print("sent########################################");
]]>
</script>

Solution

  • Please check the answer for the question : Cannot send request in mediation synapse in wso2 apim

    The same would help on here too.