WebFaction
Community site: login faq

1) Does anyone have a working example that allows you to login to the WebFaction API using PHP with some XML-RPC library (Zend XmlRpc Client or ...)? The WebFaction API documentation only has Python scripts, and depend on a Pyton library (xmlrpclib).

2) Alternatively, is the XML-part of the XML-RPC request documented somewhere? (the raw XML used for the XML-RPC request, without the Python method call)?

Something along those lines: #

<?xml version="1.0"?>
<methodCall>
<methodName>examples.getStateName</methodName>
<params>
<param>
<value><i4>40</i4></value>
</param>
</params>
</methodCall>

asked 23 Dec '12, 11:36

klor
111
accept rate: 0%


Our API tutorials and examples use Python, but the WebFaction API reference is language-neutral.

If you want to use phpxmlrpc, you simply create a XML-RPC client instance and send messages to it. Here's a simple example that logs in, lists your domains, and creates a new app, dumping the results to the screen along the way:

<?php
include "xmlrpc.inc";

// your control panel credentials
$username = "someuser";
$password = "xxxxxxxx";

// initialize the xmlrpc client
$client = new xmlrpc_client("https://api.webfaction.com/");
$client->return_type = 'phpvals';

// login and get session id
$resp = $client->send(new xmlrpcmsg("login", 
  array(new xmlrpcval($username, "string"), 
  new xmlrpcval($password, "string"))));
$loginresp = $resp->value();
$session_id = $loginresp[0];
$account = $loginresp[1];
var_dump($session_id);
var_dump($account);

// list some domains
$resp = $client->send(new xmlrpcmsg("list_domains", 
  array(new xmlrpcval($session_id, "string"))));
$domains = $resp->value();
var_dump($domains);

// create an app
$resp = $client->send(new xmlrpcmsg("create_app",
  // session
  array(new xmlrpcval($session_id, "string"),
  // app name
  new xmlrpcval("my_new_app", "string"),
  // app type
  new xmlrpcval("static", "string"),
  // autostart
  new xmlrpcval(FALSE, "boolean"),
  // extra info
  new xmlrpcval("", "string"))));
$app = $resp->value();
var_dump($app);

There may be less-verbose ways to do the same thing with phpxmlrpc, but I don't have much experience with it. This should be enough to illustrate the core concepts.

Hope that helps!

permanent link

answered 24 Dec '12, 18:46

seanf
12.2k31736
accept rate: 37%

If you use Laravel, then I have a fresh package for reaching the API with php. https://github.com/subdesign/laravel-webfaction

permanent link

answered 13 Jul, 06:55

sub
114
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×261
×75
×24
×11

question asked: 23 Dec '12, 11:36

question was seen: 6,206 times

last updated: 13 Jul, 06:55

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2016 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM