Search

Hi Nick, first of all thanks for the great extension. Exactly what I need I think!

Problem is I've just moved over to using Nginx and although I have got Sympony up and running I'm still not sure how to convert the .htaccess rewrites. Any chance you could post the equivalent for Nginx?

Hi Nick, first of all thanks for the great extension. Exactly what I need I think!

Great to hear! I'm interested to know how you're using it and for what purpose.

Yikes, I'm as much in the dark as you! Your best bet would be to look at the syntax you're using for the Symphony rewrites and apply the same concept. It's just a single rewrite so it should be simple enough.

I'm looking to use it with an iOS project I'm working on... I'd been creating datasources and pages to get the data I wanted and events to update/add new data but I now need to be able to delete items so want to move over to using your extension.

I've re-written the rewrite as:

if ($request_filename ~ /symphony/api/) {
rewrite ^/symphony/api(/(.*/?))?$ extensions/rest_api/handler.php?url=$1&$query_string last;
}

It is working for the base level of each of the plugins (i.e. symphony/api/sections/) but when I try get data for say a section (i.e. symphony/api/entries/prices/) I get "Page Not Found" from Nginx (not Sympony).

I've played around with the re-write and the best I can get is section not found from the API. What is the url I'm actually trying to achive to get the prices?

I've tried the following amongst others: extensions/rest_api/handler.php?url=entries&prices

Mondays hate me, I can't seem to add a dynamic data source using REST v1.1.0 & Symphony 2.2.2.

Direct visit to the URLs are working as expected but once added to a dynamic data source it says no entries found on the page XML.

Source URL

http://holiday.local/symphony/api/entries/countries/?auth-token=e3a7d90e&filter[id]=25

Included Elements

/response/entry

I've tried every possible sequence I could think of, ?auth-token appending/prepending, different and direct included elements, e.g. //entry. Tried reseting caching period to one min and clearing browsers cache too.

Running out of ideas, saw it was mentioned earlier in this thread, does anyone else have this working on v2.2.2 please?

Sounds like a network/authentication thing to me. Try logging out of Symphony completely, and then loading the API URL. Does it work? If so, then good, token authentication is working.

Is your site in maintenance mode, perhaps?

Thanks for getting back to me Nick. Once again, kudos for a great extension.

I've double checked the login but no luck still. After I've visited the API URL I am signed as the 'API User' in the administration, as expected.

Uninstalled maintenance mode module too, though it wasn't active. Both sites are running on local environment on a ubuntu desktop, perhaps this would could cause a problem?

Wrong post

Just to be sure, do you have the latest code from Github? To check, in handler.php this line should be commented out as below:

//require_once(CORE . '/class.administration.php');

The next thing to do is check that d463892 is a valid auth token on the host site. Does this user have the "Allow login via URL" option ticked?

Yes I do, used Git for the download and handler.php has the correct line commented out.

d463892 should be d4638928

I hadn't noticed but I was using an incorrect auth-token in the last post although I've double checked again that this isn't the problem although I can access via curl now.

curl -d "auth-token=d4638928&filter[id]=25&filter[updated]=yes" http://holiday.local/symphony/api/entries/countries/

<response result="error">
            <message>Entry encountered errors when saving.</message>
            <name label="Name" type="missing" message="'Name' is a required field."/>
            <url label="URL" type="missing" message="'URL' is a required field."/>
            <code label="Code" type="missing" message="'Code' is a required field."/>
            <id label="ID" type="missing" message="'ID' is a required field."/>
            <post-values/>
        </response>

Thanks again for your input, any other ideas? I'll have some time to upload to a test environment this afternoon, will see if the problem is my environment.

this isn't the problem although I can access via curl now

Hmm sounds like that should have fixed it if it's working via a CURL request when it wasn't previously. Perhaps your dynamic XML data source is being cached and you're not seeing the true result this time.

It was always working via curl or browser - which is why I was more confused.

Uploading to a dev server fixed the issue, once I reset the cache again, which means it must be something on my local environment although its set-up identically.

Thanks for your help, if I can be more specific later, I will try to find out what went wrong.

Hi Nick, I was playing around with the rest_api extension and it seems, REST API: Entries Datasource and Event isn't working. (Just for the record, I'm using a fresh Symphony 2.2.5 install.) I get:

Fatal error: Class 'REST_Entries' not found in /Users/malcolm/www/test/extensions/rest_api/events/event.rest_api_entries.php on line 39

for the event, and:

Fatal error: Class 'REST_Entries' not found in /Users/malcolm/www/test/extensions/rest_api/data-sources/data.rest_api_entries.php on line 44

for the datasource.

Correct me if I'm wrong, but aren't datasource and event supposed to resolve frontpage-requests as restful calls?

Kind regards, Thomas

Correct me if I'm wrong, but aren't datasource and event supposed to resolve frontpage-requests as restful calls?

I'm not sure what you mean. You shouldn't be attaching the data source or event to your pages — they are internal data sources and events that the extension uses (that I couldn't figure out how to hide from the pages editor).

The extension README describes the URLs to access the API.

Ok, thank you for clarifying. I was a bit confuesd regarding the event and datasource.

Since the api is private, wouldn't it be nice to have some sort of basic public rest calls (post put delete) that could be accessed like a generic frontage request (but without the xslt overhead of course)?

As Nick has said to me before, Symphony is perfect for doing this yourself. It already is a kind-of-rest-service for public use, you just output what you want dependant on a URL call by a user.

Not sure if I get got this right. Ok, I can sort of implement post/put calls with custom events. But how would I prevent the page being rendered without writing a extension that hooks in to the page rendering process? Sure, I can convert XML to json using xslt, although this can be quite painful, and that's actually what I want to prevent. (by the way, like your new gravatar)

You'd want the page to be rendered though, so you can output the content you would want your REST API to display, we're talking standard Symphony workflow here, Nick's extension makes more REST services available that you would only want for admin users to perform tasks with

But how would I prevent the page being rendered without writing a extension that hooks in to the page rendering process?

You cannot, you would do this using an extension that hooks into the rendering process. You could subscribe to a delegate that fires just after all data sources and events have executed, but just before the page XSLT is rendered. You would have access to the XMLElements (objects) which would normally be serialised to an XML string and then transformed. You could instead iterate over these objects and serialise as JSON.

But if you're doing this for anything other than read operations then naturally you're leaving yourself open to abuse. The REST API extension is entirely private so that developers can choose to implement their own authentication on top of this if they want (using a custom wrapper that does authentication in their own site/mobile app which then masks the API request). The REST API extension makes all sections available via the API, so I had to make it private. I didn't want to build my own set of ACL controls on top (enabling various CRUD operations on a per-user per-section basis).

Sure, I can convert XML to json using xslt, although this can be quite painful, and that's actually what I want to prevent

It can be, but in the Symphony stack it's the most elegant solution architecturally because you can use all-native Symphony code without the need for any customisation. There are a few XSLT templates around which will transform any XML into JSON for you, so your pages would be very light (~5 lines of XSLT): import the XML-to-JSON template and perform a single apply-templates or call-template to instantiate the transformation.

Well, this is my current solution for getting things done as well.

I'm currently using a slightly modified version of Doeke Zanstras xml2json stylesheet, which does a great job (ok, it's not that lightweight), but given a node contains html, you have to take care of that too (speaking: convert to string or wrap in CDATA), since you don't want this to be converted into key/value pairs.

I just thought it'd be nice to have a more RESTlike public api that would e.g. handle POST payload data as well.

Security is surly a matter I'm concerned of, but you could sort of whitelist sections that allow public post/put access (e.g. user comments).

Security is surly a matter I'm concerned of, but you could sort of whitelist sections that allow public post/put access (e.g. user comments).

Yep, you could. And in fact earlier versions of the REST API extension did partially have this: a multiselect box to choose sections that were available through the API. It could be nice to have a table of checkboxes, like the Members extension, to configure access for each section. I remove it to keep the extension simple, but if you are so inclined please feel free to add the feature.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details