VMware Cloud Community
ericr999
Enthusiast
Enthusiast
Jump to solution

Object URL, with a post

Hello,

I was wondering if anyone else ever tried to use the object URL ?

It seems pretty simple, but for some reason, the remote server always answer me as if my post was empty.

I tried it with a curl, and it works perfectly with my post.

So the issue must be with my code, but I also noticed that the object URL in the API Explorer, from the postContent method, it says that I should pass a string value.

But if I take the HTTP post workflow, its passing a string value, so I'm confused.

Also, i'm using vRO 7.0

Here's the code I've developped:

var urlObject = new URL(url + user + "&_secret=" + password);

if (os.toLowerCase() == 'sles'){

  var folder_os = "unix/linux/assemblage";

} else if (os.toLowerCase() == 'windows') {

  var folder_os = "windows/windows 2012/assemblage";

} else {

  throw ("OS non supporte");

}

var content = "{\"attributes\":{" +

               "\"ipaddress\":\"" + fqdn + "\"},\"hostname\":\"" + servername + "\"" +

               ",\"folder\":\"" + folder_os + "\"}";

System.log("URL: " + url + user + "&_secret=" + password);

System.log("PostContent :" + content);

result = urlObject.postContent(content);

System.log(result);

0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

You need to set the requestType ("POST") and contentType ("application/json") properties of your URL object before calling postContent() method.

View solution in original post

0 Kudos
4 Replies
tschoergez
Leadership
Leadership
Jump to solution

Hi,

I would recommend to rather use the HTTP REST Plugin instead of the URL object, it's newer and better maintained, and provides much more functionality.

You can use it to "render" your own HTTP calls, with headers and content.

Here are some examples:

VMware vCenter Orchestrator HTTP-REST Plug-In 1.0.3

https://purevirtual.eu/2012/11/11/exploring-vco-and-rest-apis/

Automating Veeam with vCO and the Restful API

Worst case: Call curl from vRO 🙂 Small, but useful command-line tools for vCO Workflows  (Escaping the call properly is a real pain though)

Regards,

Joerg

0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

You need to set the requestType ("POST") and contentType ("application/json") properties of your URL object before calling postContent() method.

0 Kudos
ericr999
Enthusiast
Enthusiast
Jump to solution

mmm, I'll have to investigate, but from what I see, I'm sending a JSON but the remote host, needs some parameters in my url.

I thought about hardcoding the parameters in the REST operation URL, but so far its not working.

What I'm trying to do is work with the web api from Check_MK.

https://mathias-kettner.de/checkmk_wato_webapi.html

But since its not really a rest interface, but its just expecting a request parameter with a json, that's why I'm not sure it can work. But I might be wrong, i'm still Learning vro/rest/json stuff. Smiley Happy

0 Kudos
ericr999
Enthusiast
Enthusiast
Jump to solution

Correct, I was missing the requestType initialization. But funny thing is in the HTTP workflow, there's no mention of setting the requestType before the postContent.

Also, from the last few weeks of experience with VRO, I feel like there's some missing documentation or explanation of some methods. Anyone have any suggestions of blogs, books, I should read that would go through all methods and actions and stuff I can find in VRO ? Or should I just continue digging ?

Thanks,

0 Kudos