VMware Cloud Community
zoomprofile
Enthusiast
Enthusiast

[vRO 8.6.2] How to use XMLHttpRequest

Hi,

I want to run following code inside of scriptable task in workflow

var xhr = new XMLHttpRequest();

var content = "{ \"id\": \"cd3b8ec5-adf6-45fb-8a57-bf4577350dc7\", \"name\": \"BpContent-engineering\", \"typeId\": \"com.vmw.blueprint\", \"config\": { \"sourceProjectId\": \"9b06bfde-83f2-4d79-8444-ee82bf067414\" } }";

var url = "https://vmware-automation.DOMAIN.com/catalog/api/admin/sources";

xhr.open("POST", url);

xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Authorization", "Bearer eyJ.........ixjwfQ");

xhr.onreadystatechange = function () {
   if (xhr.readyState === 4) {
      System.log(xhr.responseText);
   }};

xhr.send(content);

But I'm still getting error

"XMLHttpRequest" is not defined

 

But scriptable task autocomplete is offering this class for using, so why if it's cannot be used?

 

Thanks

Labels (3)
Reply
0 Kudos
2 Replies
xian_
Expert
Expert

Looks like they included NodeJS autocomplete into the code editor, while the internal JS engine is not updated. This causes confusion on usable language constructs.

Best you can do is to check the API Explorer on available objects and functions.

xian__0-1643402806283.png

 

Reply
0 Kudos
Ab20
Contributor
Contributor

Hi, I am also getting same error, Did you find any solution for this? please let me know

Reply
0 Kudos