Jump to content

Pages Web Service (ServicePages)


Recommended Posts

  • 3 months later...

Little tip - because this modules page is just a page (everything's a page), it can have children.

One thing that I don't think you can get back through it is a count of all the pages that would match a selector, to use for pagination, for example. But you can easily make a child page that returns $pages(selector)->count() and maybe other meta information (perhaps as a json object).

Link to comment
Share on other sites

  • 1 month later...

I've been trying to wrap my head around multilanguage, which was discussed in this thread previously. But I have no luck importing (the English one in this example) into my template(s). NOTE: The domain is just an example, the real domain is different.

I have two languages:

Norwegian: http://domain.no/service-pages/?template=subject

English: http://domain.no/en/service-pages/?template=subject

When I paste these links into the browser, I get the JSON in the correct language as I hope for from each of them. But when I try to import it somewhere (even on domain.no itself), I can only get the Norwegian one to work.

The code (with /en/) that wont work is this, simply remove /en/ and it works.


    // Get JSON string
    $json_output = file_get_contents("http://domain.no/en/service-pages/?template=subject");
    // Convert JSON string to Array
    $someArray = json_decode($json_output, true);

    echo "<pre>";
    echo "</pre>";


Any suggestions?

Link to comment
Share on other sites

  • 3 months later...
On 7/18/2014 at 2:10 AM, Christian said:

We are currently using Service Pages to pull data and serve it on our front end. We can also remove null values by iterating to each fields and prepare new set of data with the formatted data we need. All is fine as of now, but it seems that a performance issue could occured if all available fields must return before formatting it. Is there any option to remove null fields via settings?


@Christian Did you ever find a solution for this? Would like to get rid of the empty values too. 

Link to comment
Share on other sites

Second question. The ServicePages API seems to return images (or any file) like this.

reel_poster: {
    basename: "breakdown-2015-poster.jpg",
    description: "",
    tags: "",
    formatted: false,
    modified: 1468541707,
    created: 1468541707

How do I get the actual path / URL of the file referenced? I need to get the path in a JS app, so I can't use the PHP API. 

Link to comment
Share on other sites

On 8/7/2015 at 0:21 PM, sforsman said:


It is important to realize that the JSON-data returned by the module will be decoded into a "dummy" PHP object (an instance of stdClass), based purely on the raw information that can be seen in the JSON-representation. Such an object has nothing to do with ProcessWire's objects/classes. So the consuming service has absolutely no idea of any other properties other than those that are given to it by the module. You can basically compare it to an array. Hence you cannot use any properties related to a ProcessWire class, such as FieldtypeImage.

The simplest option is to build the URL manually, e.g.

<img src="http://xyz.de/site/assets/<?php echo ($post->id . '/' . $post->mf_termin_image->basename); ?>">

Although this is in PHP, and doesn't completely answer my question, I think this is the only possible solution. Posted a question and my own solution on StackOverflow here.

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Is there a way to get pages in another language yet?

My situation:
works on the serving sites instruction page & in FF browser direct call.
but does not work within the template or Chrome / Safari (Osx) directly.
without /en/ ... works flawless (same situation as Laban).

So I've tried various httpheader / useragent options (also via curl) , the content application/json, debug=1, ... solutions suggested in this thread.
Still "failed to open stream: HTTP request failed! HTTP/1.1 404 Page Not Found" from PW.

Once again, the "active" button at the settings > language page of the "pages web services" page. omg.
Does Superuser login ignore this setting?


Link to comment
Share on other sites

  • 2 months later...

Looks like an issue with the File Compiler - it is trying to compile the "include" from this: $this->input->get->include

Simple fix is to add namespace ProcessWire; to the top of that file and the module installs just fine. I also did a quick test and queries also seem to be working properly, but be sure to test thoroughly.

Link to comment
Share on other sites

Just now, awebcreature said:

Many thanks , Adrian! 

After adding that namespace and changed all wire("config") to $config , wire("fields") to $fields and wire("templates") to $template in instructions.php , all is OK!

Thanks, again!

Ah yes - I didn't mention all the errors in the instructions.php file because the functionality of the module seemed to be fine :) 

  • Like 1
Link to comment
Share on other sites

  • 3 months later...


Someone maybe found a way how to select a page (current year) withing two datetime fields (event_start/event_ende) while event_ende datetime-field might not be set (='')?
I'd like to limit traffic by using only one call.


seems not supported by PWS?

any way to "pipe / OR" selectors in PWS (event_ende>=timestamp OR event_ende='')?


Link to comment
Share on other sites

  • 2 years later...


I play with something similar to service-pages and need to transport a selector and optional a field filter (for example to only get id, name, title instead of all the page fields). I set the selector as query string,


but how to set the field filter or split selector string from the field filter in parameters?


Can't combine the query string with selector and fields filter because of multiple "=" signs... How should it be done a clean / easy way?



Optional I use predefined selectors (more secure way too) only selected by path / urlSegments instead of selector in query, but would be nice to know how to handle it most flexible...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...