techjoomla / com_api

API framework for Joomla
http://docs.techjoomla.com/joomla-rest-api/com-api-introduction
GNU General Public License v3.0
123 stars 97 forks source link

How To call Api Method #13

Closed kumarg311 closed 7 years ago

kumarg311 commented 9 years ago

Hi, I installed this component , but i confused that how to call api methods.

please show the calling url or url structure.

Thanks Gaurav

vishal22 commented 9 years ago

Hi,

I assume that, you are installed api plugin and published it. To call api method you can use ajax call or using curl ( in case of php call ) or jHTTP(joomla) method, place url as given below in api call code.

Url format is as given below -

For - Access public resource file

http//[root address]/index.php?option=com_api&app=[plugin name]&resource=[plugin resource file name]&format=raw

For - Access private resource file

key = user authentication key generated by com_api component.

http//[root address]/index.php?option=com_api&app=[plugin name]&resource=[plugin resource file name]&format=raw&key=key

gastondisacco commented 9 years ago

Hello @vishal22 @kumarg311, I am getting this as response for a test call: { "code": 400, "message": "Users API Plugin not found, Users is probably not installed" }

Any idea? Thanks!

coolbung commented 9 years ago

Can you confirm if the users plugin is installed and published as well.

gastondisacco commented 9 years ago

Thanks @coolbung, I can confirm it is installed and published. In case I disable the plugin a different message error is returned.

brunobasto commented 9 years ago

@coolbung Any news on this?

coolbung commented 9 years ago

Can you share the request URL that you are using ?

brunobasto commented 9 years ago

I figured it out by reading the code. Turns out I have to implement the plugin so that it can find it under plugins/api. Right?

coolbung commented 9 years ago

Thats right, the URL for any request should be

index.php?option=com_api&format=raw&app=&resource=

brunobasto commented 9 years ago

Can you explain what should I implement in these methods:

invoke negotiateContent fetchResource

?

I figured that ''fetchResource'' is the one who returns the JSON or XML, but what are the others for?

coolbung commented 9 years ago

You don't need any of that. Take a look at the user resource in the user plugin - https://github.com/techjoomla/com_api-plugins/blob/master/users/users/users.php

You only need the post() and get() methods in the resource. These get triggered based on if your URL is being called via HTTP GET or POST.

Content negotiation is done by the framework, so you don't need any of those methods in your plugin.

brunobasto commented 9 years ago

Ok, now I can't get pass this message:

{"code":404,"message":"Json Resource not found in this API"}

json is the name of my resource. I have a file called json.php

I followed the example just like the users.php example

brunobasto commented 9 years ago

Ok. Got it working. It looks like the class names for the ApiResources have to follow a certain convention. Thanks! You've been very helpful!

vcnwafor commented 8 years ago

i am yet to wrap my head around a simple way of making a method call....

i tried this url still getting error http://localhost/ptv/index.php?option=com_api&app=Com_K2&resource=&format=raw&key=key

coolbung commented 8 years ago

You need to create a API plugin and resources within the plugin. If your API plugin for K2 has the plugin name as plgAPIK2, and then the resource class is K2ApiResourceItems

http://localhost/ptv/index.php?option=com_api&app=k2&resource=items&format=raw&key=key

You can refer the users plugin for the plugin & resource structure https://github.com/techjoomla/com_api-plugins/tree/master/users

On Fri, Apr 29, 2016 at 5:26 AM, Victor Chigozie Nwafor < notifications@github.com> wrote:

i am yet to wrap my head around a simple way of making a method call....

i tried this url still getting error

http://localhost/ptv/index.php?option=com_api&app=Com_K2&resource=&format=raw&key=key

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/techjoomla/com_api/issues/13#issuecomment-215596751

Thanks! Ashwin Date techjoomla.com http://techjoomla.com/?utm_source=email_signature&utm_medium=email&utm_campaign=ashwin | appcarvers.com http://appcarvers.com/?utm_source=email_signature&utm_medium=email&utm_campaign=ashwin | tekdi.net http://tekdi.net/?utm_source=email_signature&utm_medium=email&utm_campaign=ashwin @coolbung | @techjoomla | @appcarvers | @tekdinet

If it isn't broken, don't fix it!