Jump to content

Api Issue


Martwana

Recommended Posts

So, im using the SDK api from github.

 

 

$response = $api->get("users", "get", array('user_id' => 1));

This returns the details for user number 1.

 

Great!

 

$response = $api->get("clientgroups", "getList", array(1));

This returns:

 

object(BlestaResponse)#2 (2) { ["raw":"BlestaResponse":private]=> string(52) "{"message":"The requested resource does not exist."}" ["response_code":"BlestaResponse":private]=> int(404) }

 

Only ever seems to be when the class name has multiple words in it. i have tried clientgroups, client_groups, client-groups, ClientGroups, Client-Groups etc. I'm lost. 

 

Any ideas?

 

Martin

 

p.s. Blesta Rocks!, but the api is confusing me haha.

 

 

Link to comment
Share on other sites

So, im using the SDK api from github.

 

 

$response = $api->get("users", "get", array('user_id' => 1));

This returns the details for user number 1.

 

Great!

 

$response = $api->get("clientgroups", "getList", array(1));

This returns:

 

object(BlestaResponse)#2 (2) { ["raw":"BlestaResponse":private]=> string(52) "{"message":"The requested resource does not exist."}" ["response_code":"BlestaResponse":private]=> int(404) }

 

Only ever seems to be when the class name has multiple words in it. i have tried clientgroups, client_groups, client-groups, ClientGroups, Client-Groups etc. I'm lost. 

 

Any ideas?

 

Martin

 

p.s. Blesta Rocks!, but the api is confusing me haha.

 

Try something like this:

$response = $api->get("ClientGroups", "getList", array($company_id = 1, $page = 1, $order_by = array('name'=>"ASC")));

or

$response = $api->get("client_groups", "getList", array($company_id = 1, $page = 1, $order_by = array('name'=>"ASC")));

 

I'm just guessing here, I haven't tested this.

Link to comment
Share on other sites

Need some higher up help, someone more familiar with the code. Alex and myself have been unsuccessful so far

Yeah, I spent quite a while working with Martwana on this. We've traced the request down the stack of the GitHub open source API such that I believe the issue is not there. The $url variable remains unmodified there, but I think the cURLed *.json request isn't being parsed properly on the receiving end when using multi-word models. I have no prior Blesta API experience so bare with me on that. Apache isn't returning a 404, the Blesta codebase itself is erroring out that the resource doesn't exist. We believe somewhere in the Blesta codebase it isn't properly handling multi-word model names from API requests, though. We tried to track it down but our lack of familiarity with the entire codebase made it feel a bit like chasing a needle in a haystack. We're not sure where the request is routed to or how it's handled once it is cURLed off as a *.json request. Regardless, I'm pretty confident that Martwana and I would have found the issue if it was in our actual implementation. Something is awry.

Link to comment
Share on other sites

$response = $api->get("clientgroups", "getList", array(1));

 

Two issues here:

  1. First parameter should separate words using underscore, i.e. "client_groups"
  2. Third parameter should be a valid set of key/value pairs for the specific action you're calling from the ClientGroups API

e.g.

$response = $api->get("client_groups", "getList", array('company_id' => 1));
Link to comment
Share on other sites

 

Two issues here:

  • First parameter should separate words using underscore, i.e. "client_groups"
  • Third parameter should be a valid set of key/value pairs for the specific action you're calling from the ClientGroups API
e.g.
$response = $api->get("client_groups", "getList", array('company_id' => 1));

Ah, that makes sense, but the documentation may be incorrect:

getList( integer $company_id, integer $page = 1, array $order_by = array('name'=>"ASC") )

may should read

getList( array ( 'company_id' => integer 1, 'page' => integer  1, 'order_by' => array ( 'name' => "ASC" ) ) )

or similar.

 

The docs appear to show the passing of 3 separate vars to this method, not passing a single array with 3 values.

 

A "bad parameters" error would have been helpful in that case, too.

 

Mart is gonna laugh. :lol:

Link to comment
Share on other sites

Ah, that makes sense, but the documentation may be incorrect:

getList( integer $company_id, integer $page = 1, array $order_by = array('name'=>"ASC") )

may should read

getList( array ( 'company_id' => integer 1, 'page' => integer  1, 'order_by' => array ( 'name' => "ASC" ) ) )

or similar.

 

The docs appear to show the passing of 3 separate vars to this method, not passing a single array with 3 values.

 

A "bad parameters" error would have been helpful in that case, too.

 

Mart is gonna laugh. :lol:

 

The documention is correct, as my link was to the source documentation, not the API SDK documentation which requires the use of key/value pairs in order to explicitly map them to the appropriate method call parameters.

Link to comment
Share on other sites

The documention is correct, as my link was to the source documentation, not the API SDK documentation which requires the use of key/value pairs in order to explicitly map them to the appropriate method call parameters.

 

Ah! Thanks for clearing that up. Sorry if I am asking dumb questions, I'm admittedly trying to help prior to using the API myself.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...