Webservice access: how to?

Discussion space for community admins

Moderators: hugo, alexandre, rmvanarkel

Post Reply
draconis
Posts: 4
Joined: Wed Nov 27, 2013 8:26 am

Webservice access: how to?

Post by draconis » Mon Dec 02, 2013 5:46 am

Hello,

Following your examples, I'm trying to access the webservices through PHP calls.
I read the instructions at this page: http://www.cyclos.org/cyclos4adminwebservices#phpclient

I downloaded and put the Cyclos folder with webservice classes in the root folder of my project.
Then I created a PHP page with the content written in your example.

I your example you say to use this url pattern:

http[s]://cyclos.url/[network/]web-rpc/<short-service-name>

so I used this url:

https://communities.cyclos.org/mycommun ... serService

If I insert this url directly in my browser, I receive an answer:

{"class":"org.cyclos.server.spring.webrpc.InvalidRequestException","errorCode":"INVALID_REQUEST"}

So the webservice is answering.

But if I try to call the url through your PHP example, I receive this error:

Caught exception: Error calling Cyclos service: userService.search: UNKNOWN

I used my admin username & password, I enabled webservices in System Configuration > Channels
I also enabled access to webservices in Account Configuration > Account types > User account (not needed here, actually)

So what could be the problem?

Thank you!

Maximilian

draconis
Posts: 4
Joined: Wed Nov 27, 2013 8:26 am

Re: Webservice access: how to?

Post by draconis » Mon Dec 02, 2013 6:15 am

Further investigating the PHP code, I found the "url" function in Configuration.php
It takes the BaseUrl and adds webService Path

like this: return Configuration::$rootUrl . "/web-rpc/" . $serviceUrlPart;

So the base url must be: http[s]://cyclos.url/[network]

(without trailing slash I suppose)

But the problem is still the same:

Caught exception: Error calling Cyclos service: userService.search: UNKNOWN

alexandre
Posts: 837
Joined: Wed Sep 06, 2006 9:06 am

Re: Webservice access: how to?

Post by alexandre » Fri Dec 13, 2013 1:05 pm

HI,

I tested the examples through my community and works fine.
I used this example:

<?php

function load($c) {
if (strpos($c, "Cyclos\\") >= 0) {
include str_replace("\\", "/", $c) . ".php";
}
}

spl_autoload_register('load');

Cyclos\Configuration::setRootUrl("https://communities.cyclos.org/mycommunity");
Cyclos\Configuration::setAuthentication("adminuser", "adminpass");

$userService = new Cyclos\UserService();
$query = new stdclass();
$query->keywords = "test";
$query->pageSize = 5;
$page = $userService->search($query);

echo("Found $page->totalCount users\n");

foreach ($page->pageItems as $user) {
echo("$user->name ($user->username)\n");
}
?>

The php example client needs:
* PHP 5.3 or newer (namespaces are used)
* PHP CURL extension (package php5-curl in Debian / Ubuntu)
* PHP JSON extension (package php5-json in Debian / Ubuntu)

If this not work for you please send your phps to info@cyclos.org so we can inspect.

regards
Alexandre Caurrinhos
Cyclos development team.

Post Reply