9

Does Craft CMS have an API that third-party webapps can access?

Maybe a REST API which you can log in to and send GET, PUT, POST, DELETE commands to, from a third-party app?

It seems like it should have an API, by the statement of the creator:

A key part of the architecture is our service layer. All of the business logic in Craft happens in service classes, which provide APIs that anything else in the system (including other services) can talk to. - http://www.thenerdary.net/post/48123188844/interview-with-brandon-kelly-creator-of-craft

But then again, some other people who have tried integrating towards Craft CMS says it doesn't:

I ran into some trouble with the API. Shit, Craft doesn’t freakin’ have one! I assumed it would, oops.. So I researched how to do it. I knew I could probably fake it and output json using template tags but no-one wants to do that. I looked at some API controllers but non of them worked very well. In the end I found a nice plugin called JSON Expand that converts entries from Twig into JSON. - http://abandon.ie/notebook/using-angularjs-with-craft-cms

I'm confused. If it has an API, what kind is it, and what protocol does it use? REST? SOAP? RPC? Something else?

And where is it documented? A simple 'hello world' or 'transmit som data into Craft CMS' example would be really helpful.

9

No, Craft doesn't have a REST API (edit: or any other web service) built-in. The "API" mentioned in the first quote (and elsewhere related) would be the more generic meaning of the term and refers to the service layer.

With a very consistent MVC based architecture based on Yii, Craft is well suited for REST implementation, though. See this G+ thread for P&T weighing in on the subject.

As a native REST API isn't part of the core, one would have to added to Craft via a plugin.

There's at least one plugin out there, though I haven't tried it (or any others) myself.

Edit

It should be mentioned that after I wrote the above answer, Pixel and Tonic has released the Element API plugin - making it easy to build a REST API with Craft. Element API is pretty basic (only GET requests), but can probably be extended with a custom plugin to support additional HTTP methods.

P&T has also stated that they want Craft 3 to have a full, built-in REST API at some point.

| improve this answer | |
  • So when he says "including other services" then he is not talking about third party services? – Magne Apr 22 '15 at 9:41
  • No, as in "other Craft services", would be my interpretation. Notice the "anything else in the system" part. – Mats Mikkel Rummelhoff Apr 22 '15 at 9:43
  • Ah, ok. That makes sense. – Magne Apr 22 '15 at 9:46
  • Do you know if it has any other kind of API for third-parties? SOAP? RPC? – Magne Apr 22 '15 at 9:49
  • 1
    No, there aren't any web services shipped with Craft. Might be worth a feature request. – Mats Mikkel Rummelhoff Apr 22 '15 at 9:58
6

If you only need to create a JSON API for fetching existing entries, etc., check out the Element API plugin.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.