REST API knowledge exchange
Post Reply
pizzle85
Novice
Posts: 4
Liked: never
Joined: Feb 27, 2015 9:06 pm
Contact:

Get vmRestorePoint by vmDisplayName with periods

Post by pizzle85 »

Im attempting to perform a query to pull all vmRestorePoints based off the display name of the VM assoicated with the restore point. When the VM name contains periods the API throws an error about the period being an illegal character. Does anyone know if there is a way to get this to work or a better way to pull all restore points based off some VM information (ID, NAME, etc)?

restHost.createRequest("GET", "/query?type=vmrestorepoint&filter=vmdisplayname==" + vmName, null).execute();

Is there a way to match instead of equal?
veremin
Product Manager
Posts: 20389
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Get vmRestorePoint by vmDisplayName with periods

Post by veremin »

Might be a silly question, but is vmName parameter contains opening and ending quotes, something like "VMName.User1"?
pizzle85
Novice
Posts: 4
Liked: never
Joined: Feb 27, 2015 9:06 pm
Contact:

Re: Get vmRestorePoint by vmDisplayName with periods

Post by pizzle85 »

I attempted it using double and single quotes, it didn't make a difference. It always complains about the period.

Every VM in our VMware environment is named its FQDN.
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Get vmRestorePoint by vmDisplayName with periods

Post by tsightler » 2 people like this post

Did you try to escape the quote? I think I ran into this and I just used the escape function, something like:

Code: Select all

restHost.createRequest("GET", escape("/query?type=vmrestorepoint&filter=(vmdisplayname==\"" + vmName + "\")"), null).execute()
This string escapes the outer set of the double quotes so that it's part of the literal string, then concatenates the VM name, then encodes the special characters (like the quote marks themselves) in the resulting URL. I guess I'm supposed to be using encodeURI() instead of escape() these days, but I'm old school. I believe that this will work as it definitely works for FQDN hostnames, but I haven't specifically tried it with VM names.
pizzle85
Novice
Posts: 4
Liked: never
Joined: Feb 27, 2015 9:06 pm
Contact:

Re: Get vmRestorePoint by vmDisplayName with periods

Post by pizzle85 »

awesome, what you sent worked like a charm. I suppose it was just a lack of knowledge on my part. Thanks for the quick help!

This is what i ended up using:

Code: Select all

var uri = encodeURI("/query?type=vmrestorepoint&filter=vmdisplayname==\"" + vmName + "\"");
var restorePointsXML = restHost.createRequest("GET", uri, null).execute()
note that the quotes were required
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests