Parse Remote API Output (GPL)????

3 posts / 0 new
Last post
#1 Fri, 02/27/2009 - 09:09
tpnsolutions
tpnsolutions's picture

Parse Remote API Output (GPL)????

Hey,

I'm hoping someone can shed some light on how to "consistently" parse the output of a remote api call.

*** I currently am working on a PHP frontend to webmin/virtualmin which includes a limited feature set and customized interface for my customers. ***

As I was reading the documentation on this, it appears that all output is in plain text.

However, there appears to be no easy way to actually parse content into a name => value pair or the like.

Example:

http://localhost:10000/virtual-server/remote.cgi?program=list-domains

This command responds with something like:

Domain Username Description

mydomain.com myuser my description

Exit status: 0

Now, if all I wanted to do was simply output the results directly to screen this wouldn't be an issue.

However, I would like to parse the content of this output into a nicely formatted HTML table for instance.

There appears to be no common delimiter when parsing the output which makes this from what I've tried thus far either very difficult or nearly impossible.

*** Honestly, if I had designed this API, I would have implemented some level of standard output such as XML, JSON, or a combination of the two so that parsing the output would be more simple, and consistent amongst the commands. ***

Forgive me if I'm missing something here, and no offense intended for either Jamie or Joe on this, just giving my thoughts on the topic.

Hope someone can shed some light on an easy way to deal with this.

-- Best Regards, Peter

Fri, 02/27/2009 - 09:15
Joe
Joe's picture

Hi Peter,

If you want a format that is more easily parsed, you need to use the <b>multiline</b> flag to list-domains, with a URL like :

http://localhost:10000/virtual-server/remote.cgi?program=list-domains&am...

All the list-* API functions accept this same flag. Also, if you just want to get the domain names, you can use the <b>name-only</b> flag instead.

XML or JSON output is not available yet, but is on my TODO list.

--

Check out the forum guidelines!

Fri, 02/27/2009 - 11:19 (Reply to #2)
tpnsolutions
tpnsolutions's picture

Thanks Jamie!

It's good to know that you do plan on this level of support in the future.

Admittingly I am still messing around with the API commands and this morning did notice the two mentioned commands.

I suppose in the meantime I will see what I can do with it and report back any findings.

My original post reflected my preferences which seems like common place in most API's these days.

Thanks again for taking a few moments to address my concern!

As always, your apps rock!

--
Best Regards,
Peter

Best Regards,
Peter Knowles | TPN Solutions
Email: pknowles@tpnsolutions.com | Skype: tpnassist
Topic locked